Docker build own Image using Bitrise CI/CD tool

admin/ April 24, 2017/ Docker, Linux/ 0 comments

Docker build own Image using Bitrise CI/CD tool

You need three account to automate the Docker image build process.

1. Github (https://github.com) or Bitbucket (https://bitbucket.org)
2. Dockerhub (https://hub.docker.com)
3. Bitrise (https://www.bitrise.io)

1. Github/Bitbucket

SignUp or Login in the Github/Bitbucket. Create an repository.

Configure the Github/Bitbucket on you local system.

Step 1:
Create a directory and configure as below.

mkdir FirstRepo
cd FirstRepo
echo "# FirstRepo" >> README.md
git init
git add README.md
git commit -m "first commit"
git remote add origin [email protected]:username/FirstRepo.git
git push -u origin master

Create a file named as “Dockerfile”. Write you docker command statement inside the file which you want to build.
For Example-:

touch Dockerfile

Open your Dockerfile and paste the below line of statement.
To open Dockerfile on Linux

vi Dockerfile

Paste the below lines in the Dockerfile

FROM ubuntu:latest
MAINTAINER Arvind Rawat <[email protected]>

#Package install 
RUN apt update 
RUN apt install -y nginx

#Expose port to be used
EXPOSE 80

#Run nginx
CMD ["nginx", "-g", "daemon off;"]

To Save file, use below command for vi editor.

:wq

Step 2:

Commit the Dockerfile and push on the Github/Bitbucket.

$ git add .
$ git commit -a -m "commit message"
$ git push origin master

2. Dockerhub (https://hub.docker.com)

Login the https://hub.docker.com goto dockerhub dashboard.

Step 1:

Go To setting to link the Github Account/Bitbucket Account.

Click on the Setting.

Click on the Link Accounts & Services

Select the access for the repository.

Finally Your Github Account is linked.

Step 2-:

Automate the Docker build.

Click on “Create Automated Build”

Select your Repository Connector

Create your Automated Build.

 

3. Bitrise (https://www.bitrise.io)

Bitrise Setup for Automated build the Docker Image.

Step 1:

Login the Bitrise account.
Add you First App

Select Github/Bitbucket to use your repository.

Authenticate your Repository.

Type your branch name if you used except the Master branch.

Validation the Repository

Select the Other/Manual

Use the Stack Selector as “Android $ Docker Ubuntu 16.04”

Register The Webhook.

Click on the Finsh Button on the Right hand on the top button.

Step 2:

Click on the App then open the “Workflow”

Open the Bitrise.yml

Paste the below lines in the bitrise,yml file.

 ---
format_version: 1.3.1
default_step_lib_source: https://github.com/bitrise-io/bitrise-steplib.git
app:
 envs:
 - DOCKERHUB_IMG_ID: "$DOCKERHUB_IMG_ID"
 opts:
 is_expand: true
 - DOCKER_LOGIN_USER: "$DOCKER_LOGIN_USER"
 opts:
 is_expand: true
 - DOCKER_LOGIN_PASS: "$DOCKER_LOGIN_PASSWORD"
 opts:
 is_expand: true
trigger_map:
- push_branch: "*"
 workflow: primary
- pull_request_source_branch: "*"
 workflow: primary
workflows:
 primary:
 steps:
 - [email protected]:
 run_if: '{{getenv "SSH_RSA_PRIVATE_KEY" | ne ""}}'
 - [email protected]: {}
 - [email protected]:
 title: Do anything with Script step
 inputs:
 - content: |-
 #!/bin/bash
 # fail if any commands fails
 set -e
 # debug log
 set -x
 # Docker login
 docker login -u "${DOCKER_LOGIN_USER}" -p "${DOCKER_LOGIN_PASS}"

 #Docker build the Dockerfile in Current Repository
 docker build -t $DOCKERHUB_IMG_ID .

 #Docker pushing the image on Dockerhub logged in account.
 docker push $DOCKERHUB_IMG_ID

 #Docker image removed from bitrise
 docker rmi $DOCKERHUB_IMG_ID

Step 3:

Secret Environment Variables

Fill the docker username in right textbox

Enter the Dockerhub Password.

Enter the Docker image as “Username/RepoName” as in the dockerhub account.

For Example -;
arvindr226/php-5.6-alpine

Finally your Bitrise automated Build Docker Image setup has been done.

Click on the Start build after build succeed check the tags in your the Dockerhub.

On the Success of the build Complete.

 

Check the final image in the Dockerhub tags.

 

Leave a Reply