Setup Gitlab CI
Introduction
Gitlab is a comprehensive platform designed for software development and version control using git. It provides a user-friendly web interface that enhances the speed of working with git, making it easier to manage Git repositories. Gitlab offers a range of features including:- Free public and private repositories: You can host your code securely and privately or share it with the world.
- Continuous Integration/Continuous Deployment (CI/CD): Automate the testing and deployment of your code.
- Free private docker image storage on Container Registry
Pushing a Docker Image to the Gitlab Container Registry
Logging into the Gitlab Container Registry
The results are as follows:
Setting up Gitlab CI
To set up steps that run whenever you push code to your Gitlab repository, add a `.gitlab-ci.yml` file to your project with the following content:
Explanation:
- image and services: Define the Docker environment to execute Docker commands.
- stages: Specify the stages that will execute when code is pushed. Here, there's only one stage: build.
- before_script: Runs before each stage. This step logs into the Container Registry.
- stage build: Builds the image with two tags: the SHA commit ID and "latest", then pushes all tags to the Container Registry.
Gitlab provides environment variables, which are information that can be used when stages are executed:
- CI_REGISTRY_USER: username
- CI_REGISTRY_PASSWORD: password
- CI_REGISTRY: Gitlab register
- CI_REGISTRY_IMAGE: image name
- CI_COMMIT_SHA: SHA commit id
After that, just push the code to the Gitlab repository to automatically trigger the CI process.
See you in the next articles!
Comments
Post a Comment