CI/CD pipeline and Docker

This is a memo when I learned the CI/CD pipeline using Docker.

What is CI/CD?

CI/CDのプロセス

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.

CI/CD and Git commands

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.

Create a feature branch

$ git checkout -b feature

Bring modified files to Git staging

$ git add .

Commit your changes

$ git commit -m '<commit message>'

push to feature branch

$ git push origin feature

The Travis CI build runs and the test code runs.

Create a pull request on GitHub ・ Merge

By being reflected in the Master branch in Git, Travis CI build will run and the application will be deployed.

Recommended Posts

CI/CD pipeline and Docker
Docker installation and initialization
Docker terms and commands
Building a CICD pipeline using Docker (personal memorandum)
Docker settings and this and that
Overview of Docker and containers
Docker Compose basics and commands
Latest docker installation (Ubuntu 20.04 and Ubuntu 20.10)
Installing and building Docker (memo)
Hello World with Docker and C
2. Create Docker image and register Registry
Microservices With Docker and Cloud Performance
Challenge to install WSL2 and docker
docker
About Docker, disguise server and container
Raspberry Pi Kubernetes and Docker downgraded story
Install docker and docker-compose on Alpine Linux
Building Rails 6 and PostgreSQL environment with Docker
Kind @ Mac in Docker and vctl container
[AWS ECR] Save and get Docker images
Docker Compact Manual (2: Mount and Data Persistence)
[Challenge Docker from 0] Overview and terms of Docker
Communicate Gitlab and Gitlab Runner launched with Docker
Introduction of Docker Hub and commands Self-learning ①
Note: [Docker] How to start and stop
Install Docker and create Java runtime environment