This blog is second in the Cloud Native Buildpack(CNB) series, If you are new to CNB, refer to previous blog which is more about Introduction to Cloud Native Buildpacks with Kubernetes.
Just to give a quick recap about CNB, Buildpacks enable us to create a OCI compatible Docker image from application source code, which we can consume very easily using pack cli.
Buildpacks are now part of open source CNCF Buildpacks project.
We can use pack cli to create our Docker images, without even writing a Dockerfile.
For testing purposes we can do it manually, but when it comes to actual production release and deployment, we need some kind of Continuous integration pipeline in place for the job.
In this blog we will be creating a CI pipeline using Gitlab, which will use Cloud Native Buildpack and final image will be pushed to Docker hub.
- Gitlab account under free plan, create one using the Gitlab Register link.
- Docker hub account, create one using Docker Hub signup page.
Creating CI pipeline in Gitlab
Once we are into CI/CI settings, we can see Variables section to
We will be adding 2 variables here
DOCKER_HUB_PASSWORD, which are your Docker hub credentials, and enable masking, so no credentials are visible during Job execution, click on Save variables.
In repository there is a file .
gitlab-ci.yml.sample which is similar to actual ci file, once we change the name to
.gitlab-ci.yml, it will automatically create a pipeline for us
Click on .
gitlab-ci.yml.sample file in git repository, click on Edit button in blue, and in edit mode change the file name to
.gitlab-ci.yml, click on Commit changes!
Now are pipeline is in place, let’s check our pipeline in CI/CD panel on Gitlab
In pipelines dashboard, we should be able to see our pipeline run status, which was triggered as soon as we committed the gitlab-ci file in our repository.
To check the pipeline run , click either on status or pipeline number, here it is
Our pipeline will show the stages and Jobs, lets click on job which
build_and_push_image, which will take us to the actual run
Once our Job is finished, we can see newly pushed docker image in our Docker hub account.
Voila!! We have Continuous integration pipeline with Gitlab source repo and Cloud native buildpacks!!
Deep Dive on Gitlab CI configuration file
image: docker:stable variables: DOCKER_DRIVER: overlay2 REALM: shared DOCKER_HOST: tcp://docker:2375/ services: - name: docker:dind entrypoint: ["env", "-u", "DOCKER_HOST"] command: ["dockerd-entrypoint.sh"] stages: - build build_and_push_image: stage: build before_script: - wget https://github.com/buildpacks/pack/releases/download/v0.6.0/pack-v0.6.0-linux.tgz - tar xvf pack-v0.6.0-linux.tgz - rm pack-v0.6.0-linux.tgz script: - echo "$DOCKER_HUB_PASSWORD" | docker login --username "$DOCKER_HUB_USER" --password-stdin - ./pack build "$DOCKER_HUB_USER"/cnb-goapp --builder cloudfoundry/cnb:tiny --publish
We have used
docker:stable as runtime image, so that we can use docker cli to login to Docker hub
docker:dind is docker in docker service which is used during runtime.