Docker ,MakeFile and Jenkins pipeline

How to create a re-usable MakeFile for build, push and deploy docker containers? and automate build using Jenkins pipeline.?

Typing a long docker commands is always a pain.We can create a script to help us out. Bash can be used here, but using a Makefile for more convenient than script, as the syntax is easy to get started with.

Clone below repo [MakeFile_repo] and go to the directory. 
  git clone git@github.com:Prashanth-Pullaikodi/Makefile_Docker_Build.git
Repo contains below files and folders.
1. MakeFile: Contains make configuration to build, push and deploy containers. Inorder to run the make command you needs to have docker installed and docker hub account . 2. Nginx: Contains Dockerfile to build NGINX . 3. Jenkinsfile: Contains CD pipile line defintion of automating this build ,push deploy task. Inorder have to use this file you needs to have Jenkins installed and configured with pipeline ,Git plugins.
You can use Makefile without Jenkins as well .

Makefile targets

make build
make push
make deploy
make cleanup
make rmi
make stop_single_container
make rm_single_container
make rmi_docker_hub

Modify the pre-defined values according to your setup and push to your git account.

RELEASE_VERSION := 3.0-patch                  #Modify if you would like to have release version for your imahe.
DOCKER_HUB_REPO := ""                         #DockerHub RepoName.
USER_NAME = ""                                #Username for you dockerHUB registry [https://cloud.docker.com]
PASSWORD = ""                                 # Password for you dockerHUB registry

How to use it.

Note: Make sure you have DockerHUb account and you loged to repo using 'docker login' command.
You can use this in two ways,
  • With Jenkins :
    • Pipeline Job and use SCM check out plugin to checkout this repo and run the JOB ,which will build,push and deoply docker container for you.
  • Manual :
    • Clone the repo and run make command to build ,push and deploy container.

make build 


Comments

Post a Comment

Popular posts from this blog

SAN and NAS Interview questions

Infrastructure As Code - Terraform and AWS.