Continuous Deployment with Docker and Virgo

Docker logo 011 Continuous Deployment with Docker and VirgoThe post “Automated installation of Virgo with Docker” described how to build and run a Docker container with Virgo inside.

Today I’ll describe an easy way of continuously deploying applications into such a Virgo running inside an isolated Docker container.

In a regular Virgo installation we would simply drop our application bundle into the pickup folder of the targeted Virgo instance. We could allow the Docker container to reach out into the filesystem of the host, but to keep the isolation on a high level we want to use a file upload. The idea is to provide an upload servlet that hands over the payload to the Virgo deployer via JMX.

The implementation of this file upload controller is pretty straightforward:

@Controller
public class FileUploadController {
…
  @RequestMapping(value = "/upload", method = RequestMethod.POST)
  public @ResponseBody
  String handleFileUpload(@RequestParam("name") String name, @RequestParam("file") MultipartFile file) {
    LOG.info("Handling file upload {}...", name);
    URI uri = acceptMultipartFile(file);
    Object invoke = this.mBeanServer.invoke(objectName, "deploy", new Object[] { uri.toString() },
                                                new String[] { String.class.getName() });
    LOG.info("Deployment of {} finished.", name);
  }}

Just before the default command of the Docker container, we assure that the point of acceptance is available:

# install “point of acceptance”
ADD com.eclipsesource.docker.farm-1.0.0.jar /home/virgo/pickup/
 
# default command
CMD su - virgo /home/virgo/bin/startup.sh

Not much left to do. Create the Docker image:

$ sudo docker build -t eclipsesource/tabris-jetty-farm .

Fire up a Docker container…

$ sudo docker run -i -h localhost -p 28081:8080 -t eclipsesource/tabris-jetty-farm

That’s it! You are ready to trigger continuous deployment as final step of your CI job:

$ curl -F "name=/tmp/app.jar" -F "file=@${PROJ_ROOT}/target/com.eclipsesource.tabris.demos_1.2.0.20131018-1406.jar" http://localhost:28081/farm/upload/

What’s next? I an future post I will explore the possibilities to programmatically build Docker images as well as create, start and stop Docker containers with the Docker Remote API[1] and docker-java[2].

[ Using Virgo in an industrial setting? Our technology subscription secures your investment for years to come. ]

[1] Docker Remote API – http://docs.docker.io/en/latest/api/docker_remote_api/
[2] docker-java – https://github.com/kpelykh/docker-java

Comments are closed.

No responses yet

Written by . Published in Categories: Editors choice, Planet Eclipse, Planet OSGi

Author:
Published:
Oct 25th, 2013