Complex applications with highly customized logic and user interfaces take time to develop and require more formal practices to ensure that they work as intended and meet users' needs. My project might not be so large, but I can still benefit from using development and test environments, where I can develop and test my code without affecting end users. Building my own applications requires a thorough understanding of the issues that can take place during the app lifecycle, from development to the production stage.
Application lifecycle management becomes a lot easier thanks to the automation of routine operations (creating environments, building and deploying projects, binding and swapping domains, etc). One of the best practices is to make my test environment look like my production environment and to periodically synchronize the test database with the data from production, and both of environments will look at one database. Also we'll show how to use separate building environments to build all my projects with the embedded Maven tool.
To realize the schema above we'll come through the next steps:
- Create the production environment
- Create the build environment
- Build and deploy the project
- Create the test environment
Also here is a video version of the same procedure:
Let's get started!
How do I Create the Production Environment
Log into the CloudJiffy Manager.
Step 1 : Ask CloudJiffy to create a new environment.
Step 2 : Select the application server which I want to use (for example GlassFish), set the cloudlets limit and type the name of my first environment, for example, prodenv. Then click Create.
Step3 : Wait just a minute for my environment to be created.
How should I Create the Build Environment
I can build applications in the CloudJiffy cloud instead of building my projects locally and uploading WAR archives. It is faster and takes less time and bandwidth, I'll get the efficiency of the cloud and can continue to use my computer without extra loads. CloudJiffy can take application source code directly from my version control repositories (via Git or SVN protocol).
The next step is to create a building environment.
Ask CloudJiffy to create a new environment, pick Maven as my building tool, set the cloudlets limit and type the environment name, for example: buildenv. I can create environment without a compute node. No need to have separate building tools for each of my environments.
In just a couple of minutes my environment will be created.
How should I Build and Deploy the Project
Now we can easily build our first project and deploy it to the production environment.
Step 1 : Add my project to Maven.
Step 2 : In the dialog, navigate to the Git tab (or SVN) if I want to use Git as my revision control system. Specify my project name, Path to my project, Branch, Login and Password of my repository, name of my Environment, Context in which I will deploy my project, and click Add.
Step 3 : Click Buid and deploy button for my project.
How to Create Data Environment
Let's create one more environment with the database without a compute node. This allows me to store all my applications' data there.
Click on Create environment and pick the database (for example MySQL) that I want to use.
When my environment is successfully created, click the Open in browser button for MySQL. CloudJiffy sent me an email with credentials to the database. Create an account and the database with the application using these credentials.
How do I Configure the Database
Click the button Config next to the application server of my production environment.
In the opened tab create a mydb.cfg file in the /opt/glassfish3/temp directory and add there all necessary configurations:
host=jdbc:mysql://mysql{node_id}-{my_env_name}.{hoster_domain}/{db_name}
username={get in the email from Robot@CloudJiffy}
password={get in the email from Robot@CloudJiffy}
driver=com.mysql.jdbc.Drive
Note: I can mention all connection settings in my code (application). In the given example, we put all the settings in the file, which is read by our application.
Upload MySQL connector to the /opt/glassfish3/glassfish/domains/domain1/lib directory of GlassFish.
Restart GlassFish and open my app in a web browser.
With CloudJiffy I have the ability to set my own domain name for my URL instead of using my hoster domain name. So, buy a domain name for my production environment. In this case, we recommend to set my own custom domain by adding a CNAME record. Click the Settings button (the wrench icon) for my environment and bind the domain. In our case the URL is production.com.
Please note: in this example we use DNS names (production.com, test.com) that were previously added to local DNS-server (file hosts).
How do I Create the Test Environment
It's time to create our test environment now. For this purposes I can easily clone my production environment. That lets me work with multiple versions of the same environment and branch of my environments as needed. The cloned environment is identical to the original environment and includes all data in its databases, deployed *.WAR and *.JAR packages.
Clone my production environment to get the exact copy of it for adding some new features and testing them.
Let's call it testenv.
I can open it in a browser just to ensure that everything is ok.
That's All!