🇬🇧 🦊 GitLabCI: Easy Build and Deploy an Image With Kaniko
I read differents post about image build and deployment with GitLab CI and i would like want to share one tip : use Kaniko 😁.
To create an image you can use the usual docker command
docker build -t <your image name>
And to push this image, this one :
docker push <your image name>:latest
All built with the docker image, and the dind services :
image: docker:stable
services:
- docker:dind
And finally, in your gitlab-ci.yml, you will have this :
🐳 build_and_deploy_classic:
stage: build
image: docker:stable
services:
- docker:dind
script:
- docker login -u GitLabci -p "$CI_SECRET" registry.GitLab.com
- docker build -t <your image name> .
- docker push <your image name>:latest
This work correctly, of course you can use this.
But on my jobs, i prefer use Kaniko. Why ? Simply because in one line you can build and push on a repository.
Juste before this, you need to write in a file your username, password and auths.
That’s all 😎
🐳 build_and_deploy_kaniko:
stage: build
image:
name: gcr.io/kaniko-project/executor:debug
entrypoint: [""]
script:
- echo "{\"auths\":{\"$CI_REGISTRY\":{\"username\":\"$CI_REGISTRY_USER\",\"password\":\"$CI_REGISTRY_PASSWORD\"}}}" > /kaniko/.docker/config.json
- /kaniko/executor --context $CI_PROJECT_DIR --dockerfile $CI_PROJECT_DIR/Dockerfile --destination $CI_REGISTRY_IMAGE
In this example i deploy my image on the GitLab registry but you can deploy on others repositories.
Don’t hesitate to give me comments 😋