Continuous integration & deployment(CI/CD) is one of the well-known standard practice in modern-day software development. In a fiercely competitive world, businesses are relying on much more frequent feature releases to target customers. Recently, I came to know about CircleCI which is one of the excellent tools for achieving CI/CD efficiently. In my experience, the following CircleCI tagline is entirely apt:
Automate your development process quickly, safely, and at scale.
In this post, I will be sharing how to build and deploy Docker images using CircleCI quickly.
First, enable CircleCI webhook for your public GitHub repository. CirclecCi expects config.yml
in the .circleci
sub-folder of the project root directory. The config file should follow the rule specified here. CircleCI config file consists of three basic definitions as follows:
- version - configuration file version. Commonly used versions are 2 or 2.0
- workflow - defines the complete workflow of continuous integration and deployment. Workflow can have multiple jobs.
- jobs - contains the list of steps to be run.
- Define simple workflow using
workflows
tag for building and deployment of docker image. In workflow definition,filters
can be used for specifyingbranches
that are used for running a job. For example:
workflows:
version: 2
build-and-deploy:
jobs:
- build:
filters:
branches:
only:
- master
- develop
jobs
can be a single step or multiple steps. Steps execute sequentially, for example, build a Docker image and deploy to the docker registry. Below are few basic configurations required for baking docker imagesetup_remote_docker
, define docker environment for building docker image.working directory
, the folder where a code copied for running build commands.- Environment variables, for saving credentials and other build parameters securely. Refer below the code snippet for the job definition
jobs:
build:
working_directory: ~/docker-superset
docker:
- image: docker:17.05.0-ce-git
steps:
- checkout
- setup_remote_docker:
version: 17.05.0-ce
- run:
name: list files
command: ls -lsrt ~/docker-superset
- run:
name: Build Docker image
command: docker build -t abhioncbr/docker-superset:$SUPERSET_VERSION --build-arg SUPERSET_VERSION=$SUPERSET_VERSION -f ~/docker-superset/docker-files/Dockerfile .
- run:
name: Push to DockerHub
command: |
docker login -u $DOCKERHUB_LOGIN -p $DOCKERHUB_PASSWORD
docker push abhioncbr/docker-superset:$SUPERSET_VERSION
View complete config file here