advanced/ci-cd/cicd-circleci.md
For the purpose of virtualization, we uses virtual machine technology. This technology actually reduces concentration risk when deploy in the right configurations. You can always achieve more failures using fewer x physical machines and hosting more than x virtual machines that are networked to watch each other and take over in the event of partner machines failure.
Another drawback of virtual machine is licensing cost. Virtual machine technology imposes a performance penalty from running an additional layer about the physical hardware. Also virtual machine technology hardware that both virtual machine hypervisor and the guest operating system support. To overcome all these problems Docker is the best solution.
Current CI/CD solutions follow multi-tiered environments approach - development, test, staging and production. Each of these environments are managed independently of each other.Hence, each of these environments may have different configurations different library versions or even different Operating Systems.
This leads to the popular problem known as “it works on my machine” syndrome where an application that works on one environment stops working on some other due to the above-mentioned problem.
Steps to follow:
Clone the Repository:
git clone https://github.com/sangam14/dockerapp1.git
Change directory to dockerapp1 as shown below:
cd dockerapp1
Bringing up app using Docker Compose:
docker-compose up
output:
As shown above, we can save key and value by clicking "Save" button.
Make sure you add circle-ci config file under .circleci/... as shown under the example https://github.com/sangam14/dockerapp1/tree/master/.circleci
.circleci/config.yml
version: 2
jobs:
build:
working_directory: /dockerapp1
docker:
- image: docker:17.05.0-ce-git
steps:
- checkout
- setup_remote_docker
- run:
name: Install dependencies
command: |
apk add --no-cache py-pip=9.0.0-r1
pip install docker-compose==1.15.0
- run:
name: Run tests
command: |
docker-compose up -d
docker-compose run dockerapp1 python test.py
- deploy:
name: Push application Docker image
command: |
docker login -e $DOCKER_HUB_EMAIL -u $DOCKER_HUB_USER_ID -p $DOCKER_HUB_PWD
docker tag dockerapp_dockerapp $DOCKER_HUB_USER_ID/dockerapp1:$CIRCLE_SHA1
docker tag dockerapp_dockerapp $DOCKER_HUB_USER_ID/dockerapp1:latest
docker push $DOCKER_HUB_USER_ID/dockerapp1:$CIRCLE_SHA1
docker push $DOCKER_HUB_USER_ID/dockerapp1:latest
As shown above, make sure to add environment variable like $DOCKER_HUB_EMAIL, $DOCKER_HUB_USER_ID,$DOCKER_HUB_PWD Once you get circleci job running successfully, it should automatically be deployed on DockerHub repository.
Login to the circle-ci account https://circleci.com using github. Select project which you want to deploy.
Go to the setting of the project in circleci dashboard and add the environment variable which declared in .circleci/config.yml file io. You can also provide Github SSH permission.
Next, Run the build and it will perform following steps one by one {if it encounter any error, you should see red-colored messages )
1.Spin up Environment
2.Checkout code
3.Setup a remote Docker engine
4.Install dependencies
5.Run tests
It should result in test.py. Refer https://github.com/sangam14/dockerapp1/blob/master/app/test.py
After it gets successfully completed, you should be able to find the below Docker Image under DockerHub.
https://hub.docker.com/r/sangam14/dockerapp
You should see it successfully deployed. Cheers !
Sangam biradar - [email protected] -www.codexplus.in