Deploy Code to Containers from Git Automatically

| April 20, 2017

There is a number of options to deploy your source code from a Git repo to containers including redeploy of the whole container, instant redeploy via volumes or “git clone” approach. However, when it comes to automation of this process and moving to continuous deployment, many developers can face the complexity, as they need to know how to properly combine all the application components with the required interconnection points.

Specifically, in the containers world you have to manage builds of your stack images dealing with extra complexity of CI/CD pipeline. And the whole containers redeploy may not be the best approach if you do often commits without configuration changes in operating system, application server stack or its dependencies.

github ci cd

To ease deployment automation, Jelastic prepared a special dedicated Git-Push-Deploy package for code delivery into the preliminary built container images. This package implements a number of configurations to set up automatic deployment of committed changes within your Git application source repository to the cloud, making them available for further testing with minimal delays.

Git-Push-Deploy Specifics

The Git-Push-Deploy package can be integrated with GitHub and GitLab repositories. It is developed for automatic delivery of updates within your Java, PHP, Ruby, Node.js, and Python application sources and can be applied to the following certified stack templates:

  • Java - Tomcat 6/7/8/9, TomEE, GlassFish 3/4, Jetty 6/8/9, WildFly 8/9/10, JBoss AS 7, Spring Boot 1.x
  • PHP - Apache 2.4, NGINX 1.10
  • Ruby - Apache 2.4, NGINX 1.10
  • Node.js - NodeJS 0.x-6.x
  • Python - Apache 2.4

The workflow depends on the programming language used in your project:

  • for Java-based projects, the package initiates the creation of a separate environment with a Maven build node, which will be responsible for interaction with remote Git repository, triggering your application builds and their deployment to the application server
  • for PHP/Ruby/Node.js/Python applications, the package sets up a pipeline for project deployment directly to the ROOT context on a web server (here, consider that Ruby app servers are supplied with a deployment mode instead of a context within the dashboard, though the actual project location is the same)

This deployment automation package is compatible with Jelastic PaaS of 4.9.5 version and higher. To review and compare available hosting platforms with a particular Jelastic version, refer to the Jelastic Cloud Union Catalog.

Repository Pre-Configurations

For a proper add-on installation, you’ll need to provide a Personal API Token for your Git account. This enables package to setup a webhook for the corresponding repository, which will initiate application redeployment each time any change is contributed to its code.

So let’s generate one, follow the instruction below according to the used Git VCS, i.e. either GitHub or GitLab.

Generating Access Token on GitHub

To get your personal access token for GitHub account, navigate to the Settings > Personal access tokens and click the Generate new token button.

node js app deployment automation

In the opened page, specify the Token description and select the repo and admin:repo_hook scopes. Click Generate token at the bottom of the page.

github auto deploy

Once redirected, copy and save the shown access token anywhere else (as it can’t be viewed again after you leave this page).

ruby continuous deployment

After this is accomplished, proceed to the Install Git-Push-Deploy Package section right down this article.

Generating Access Token on GitLab

To generate a personal access token on GitLab, enter your account Settings and switch to the Access Tokens tab.

Here, specify optional token Name, its Expiry date (can be left blank) and tick the api permission scope.

python app deployment automation

Click the Create Personal Access Token button.

In the opened page, copy and temporary store your access token value anywhere else (as you won’t be able to see it again after leaving this page).

github ci cd php

Now, you are ready for package installation.

Extra Pre-Configurations for Java Projects

If running a Java-based project, you need to preliminary ensure its proper interaction with Maven build node by adding a special Project Object Model (POM) file to its structure.

So, create a pom.xml file in your project repository root, with the following content as an obligatory basis:


where optional values are:

  • groupId - group of a project (e.g. company name)
  • artifactId - name of a project
  • version - your application version

All the rest of parameters should be left unchanged.

Install Git-Push-Deploy Package

Git-Push-Deploy package is an add-on, so it can be installed only on top of environment. We have prepared two separate environments with Tomcat and Apache-PHP application servers to show the workflow for different programming languages.

If you are going to use previously created environment, note that the package will overwrite the application deployed to ROOT context. So to keep your already deployed application, move it to the custom context. We recommend creating a new environment and then proceeding to the installation:

1. Click the Import button at the top pane of the dashboard and insert manifest.jps link for Git-Push-Deploy project within the opened URL tab:

ruby application deployment automation

Click Import to continue.

2. In the opened frame, specify the following details about your repository and target environment:

  • Git Repo Url -  HTTPS link to your application repo (either .git or of a common view). You can fork our sample Hello World application to test the flow
  • Branch - a project branch to be used
  • User - enter your Git account login
  • Token - specify the access token you’ve previously created for webhook generation
  • Environment name - choose an environment your application will be deployed to
  • Nodes - application server name (is fetched automatically upon selecting the environment)

java continuous deployment

Click Install to continue.

3. Wait a minute for Jelastic to fetch your application sources from GitHub and configure webhook for continuous deployment.
php github auto deploy

Close the notification frame when installation is finished.

4. Depending on a project type, the result will be the following:

  • for Java-based infrastructure, you’ll see a new environment appeared at your dashboard with a Maven build node inside; it will build and deploy your application to the ROOT context on a web server each time the source code is updated
    application ci/cd automation

Pay attention that it might take some time for Maven to compile a project (though the package installation itself has already finished), so you need to wait a few minutes before launching it. The current progress of this operation can be tracked in real time via vcs_update log file on Maven:
jps automation git push

  • for PHP-based infrastructure (and the rest of supported languages), your application will be deployed directly to the chosen server ROOT

PHP-based infrastructure git push

Herewith, consider that the similar Projects section for Ruby application servers provides information on used deployment mode (development by default) instead of a context, whilst actual app location refers to server root as well.

To start your application, click on Open in browser next to your web server.

node js continuous deployment

That’s it! Now a new version of your application is automatically delivered to the application server upon each commit to a repository.

Redeployment Policies for Different Stacks

The table below lists behavior of different application servers after receiving the updated code.

Stack NamePolicy
Tomcat 6Restart
Tomcat 7Restart
Tomcat 8Restart
Tomcat 9Restart
GlassFish 3Hot Redeploy via Server API
GlassFish 4Hot Redeploy via Server API
GlassFish 5Hot Redeploy via Server API
Jetty 6Restart
Jetty 8Restart
Jetty 9Restart
JBoss 7Restart
Wildfly 8Restart
Wildfly 9Restart
Wildfly 10Restart
Apache-PHPAdvanced ZDT
Nginx-PHPAdvanced ZDT
Apache-RubyGraceful Reload
Nginx-RubyGraceful Reload


To eliminate possible application downtime for a server with Restart update policy, scale it out to be run over multiple containers. In this case, the required updates will be applied to the instances sequentially, with a 30-second delay by default.

Test Automated Deploy from Git

And now let’s check how this process actually works. Make some minor adjustment to the code in a repo and ensure everything is automated:

1. Click Edit this file for some item within your project repository and Commit changes to it - for example, we’ll modify the text at our HelloWorld start page.
github continuous deployment
2. As a result, the appropriate webhook will be triggered to deploy the made changes into your hosting environment -  refer to the repository Settings > Webhooks section for the details.

python continuous deployment

Upon clicking on this string you’ll see the list of Recent Deliveries, initiated by the webhook, and result of their execution.

3. As the last checkpoint, return back to your application page and refresh it (whilst remembering that it may take an extra minute for Maven to build and deploy your Java-based project).
java app deployment automation

That’s it! As you can see, the modifications were successfully applied, so the solution works as intended.

Simply update your code, make commits as you usually do, and all the changes will be pushed to your Jelastic environment automatically. No need to switch between processes or make manual updates eliminates human errors and accelerates time to market for your application. Try out how it works with your project by registering at one of Jelastic providers.

Need some details or assistance? Feel free to ask for help within the comments below or get in touch with our technical experts at Stackoverflow.