Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Continuous Deployment Using Travis CI and Docker

What is the best way to automate the deployment of a Docker image in a CI environment?

After building a simple web project using Travis CI and using a Dockerfile to build the corresponding Docker image, is there a way to automatically cause that image to be deployed to a cloud provider?

Right now, the Dockerfile pulls down the base image to the Travis build machine and builds the image based on the instructions in the Dockerfile. At this point if the build is successful I can push it to the Docker Hub, though I have no need save this image to the Docker hub, what I envision is deploying the successfully built Docker image to a cloud provider (IE. DigitalOcean, Linode, or AWS) and starting/running the image.

like image 412
DanCat Avatar asked Oct 14 '15 18:10

DanCat


People also ask

Does Travis CI use Docker?

Travis CI builds can run and build Docker images, and can also push images to Docker repositories or other remote storage.

Is Docker used for continuous deployment?

Docker has become an early adopter in Continuous Integration and Continuous Deployment. By leveraging the right integration with source code control mechanism such as GIT, Jenkins can initiate a build process each time a developer commits his code.

How do you build a pipeline in Travis CI?

Steps in a Build Pipeline Compiling code: in our case, that means compiling Java source code into class files. Executing tests: like running unit tests and possibly integration tests. Deploying artifacts: packaging complied code into artifacts, say into jar files, and deploying them.

What is Travis CI used for?

Travis CI is an open-source hosted distributed continuous integration service used to build and test projects hosted at GitHub. Travis CI is configured by adding a file named .


2 Answers

While pushing directly to a host might seem ideal, I think it ignores the fact that hosts can fail, or may need to be replicated.

If you push directly to a prod host, and that host goes down, you don't have any way to start another one without re-running the entire CI pipeline.

If you push to an intermediary (the hub or a docker registry), you can create as many hosts as you want without having to re-run the build. You can also recover on a new host very easily (the initialize script can just pull the image and start).

If you wanted to, you could run your own registry on the cloud provider (instead of using the hub).

like image 197
dnephin Avatar answered Oct 20 '22 09:10

dnephin


For a static website, you might want to look at Surge.

Otherwise, you might want to look at the AWS Elastic Beanstalk Command Line Interface (AWS EB CLI) in combination with using docker with AWS EB.

For using docker with AWS EB, read this AWS Blog post

For AWS EB CLI, here is an excerpt from the AWS EB dashboard sidebar

If you want to use a command line to create, manage, and scale your Elastic Beanstalk applications, please use the Elastic Beanstalk Command Line Interface (EB CLI). Get Started

$ mkdir HelloWorld
$ cd HelloWorld
$ eb init -p PHP
$ echo "Hello World" > index.html
$ eb create dev-env
$ eb open

To deploy updates to your applications, use ‘eb deploy’.

Further reading

  • Installing the AWS EB CLI
  • EB CLI Command Reference
like image 25
Shadi Avatar answered Oct 20 '22 09:10

Shadi