This is a memo when I learned the CI/CD pipeline using Docker.
Image quote: ThikIT "DevOps, containers are a big success in CI/CD pipelines!"
Systematize the process for continuous integration and continuous delivery (deployment). The following are typical CI tools.
An example using Travis CI + Docker + Heroku + Rails. Only Travis CI flow and Git command are described.
Store the following YAML file in the work directory.
sudo: required
services: docker
before_install:
- docker-compose up --build -d
- docker login -u "$HEROKU_USERNAME" -p "$HEROKU_API_KEY" registry.heroku.com
script:
- docker-compose exec --env 'RAILS_ENV=test' web rails db:create
- docker-compose exec --env 'RAILS_ENV=test' web rails db:migrate
- docker-compose exec --env 'RAILS_ENV=test' web rails test
deploy:
provider: script
script:
docker build -t registry.heroku.com/$HEROKU_APP_NAME/web -f Dockerfile.prod .;
docker push registry.heroku.com/$HEROKU_APP_NAME/web;
heroku run --app $HEROKU_APP_NAME rails db:migrate;
on:
branch: master
Permission setting, using Docker, container startup, DB preparation, test execution, deployment execution (only when the git branch is master) are described in order.
$ git checkout -b feature
$ git add .
$ git commit -m '<commit message>'
$ git push origin feature
The Travis CI build runs and the test code runs.
By being reflected in the Master branch in Git, Travis CI build will run and the application will be deployed.
Recommended Posts