Patterns for Continuous Integration with Docker using Travis CI 2 - Prod. Repo
The “Docker repo” pattern: create two separate Git repositories: one for Docker release and another for software development. This keeps the Docker-specific code isolated from the actual software. Developers can continue working on the source software as usual, while the production Docker image is developed separately
This repository is an example of the Git repository for Docker release.
Specifically, we create a separate Git repository specifically for the release Dockerfile. This keeps the Docker-specific code, which could be considered a deployment detail, isolated from the actual software. Developers can continue working on the source software as usual, while the production Docker image is developed separately.
When a new development release (e.g. 0.3.9.dev0) is ready and tested for production (see Patterns for Continuous Integration with Docker using Travis CI 2 - Dev. Repo for more details), someone updates consequently the requirements.txt file and commits on master. In this way: - Travis CI builds, tests and packages the software, - Travis CI does two new docker development images, e.g. 0.3.9.dev0 (the image of the development release tagged for production, for archiving purpouse) and latest (the production image of the project), on the Docker Registry, e.g. Docker Hub.
requirements.txt
python-dev-docker-project==0.3.9.dev0
Dockerfile
FROM python:3.6-slim
COPY requirements.txt /requirements.txt
RUN pip install --no-cache -r requirements.txt
ENTRYPOINT ["hello"]
CMD ["World"]
.travis.yml
sudo: required
services:
- docker
env:
global:
- IMAGE_NAME=gtesei/hello_docker_2
- REGISTRY_USER=gtesei
# REGISTRY_PASS=...
- secure: H8o2BrmikY0e9Gzj1t/Ca1H+hblEv9GC6Qd9MQoN/zxXx0MtiZw3eyCuBO4rpYvX80oeS/e9QM1b4v8OUCsRqGd1nwz4QhRQIRyzh03+n+Sp84qnTqAZvDNbPl0WYDSJyRYFij7SpVP37encJX8ioPaE+YarNn1AGUAVthFOvWhEEeuDGV0lDOXw0j+LsXr1hf821dqvlFLBXPE0dVB6LZD2QEde4BaCQaM+FgBRrcz/bkLMBByviUxdCevJsHSOnhc4rZCbBZ5k5oByJsXVMX/S+SFwP5N4ljkF9rjtIA8fMOlGjk8Z8kXSk3BeLctXGSrZBZBsXG2e89AfBeXFrK91tYdLJROXWdd6MN+U9r+FSIblHqB51zE2zFUpXK9pijUeJLNC2eacdNMRTvxA+tudEIuGkIKkgA4aGw8knoroWXI8ByLtVJA2mXQvlMqiN+pVQt36rwx1Tz0mlw2QOsI713f/JhSoJQNX7flRJrcs2FroCCmDrnpXiE+FN+svjLKz7b07lzw8H78PGfj11YPV8LGDHMRqf0/fu55157QaDgoDKekBLuwXYGT+q5pOu91r+9ywIUo5V8WXel7VM1iUqu3Kjq8DLpwiTErENwEEoq8x5uATXAHsnoXEpBFSj6RsU1BdambMkoz7bbOgviVwTDTGB4jgX7iYdlEYdzA=
before_script:
- version="$(sed -nE 's/^blog-travis-docker==(\S+).*/\1/p' requirements.txt)"
- docker pull "$IMAGE_NAME" || true
script:
- docker build --pull --cache-from "$IMAGE_NAME" --tag "$IMAGE_NAME" .
- docker run "$IMAGE_NAME"
after_script:
- docker images
before_deploy:
- docker login -u "$REGISTRY_USER" -p "$REGISTRY_PASS"
- docker tag "$IMAGE_NAME" "${IMAGE_NAME}:latest"
- docker tag "$IMAGE_NAME" "${IMAGE_NAME}:${version}"
deploy:
provider: script
script: docker push "${IMAGE_NAME}:latest" && docker push "${IMAGE_NAME}:${version}"
on:
branch: master
How to encrypt password of Docker Hub on .travis.yml
Travis CI
Docker Registry [Docker Hub]
Useful links
To install Travis
gem install travis
Credits
Defining encrypted variables in .travis.yml
Google Cloud | Continuous Delivery with Travis CI