Setting Up the Foundation: Docker Images and Registry
Docker Registry
After building the Docker images, we need to push them to a Docker registry. Without this step, we won't be able to deploy our containers to the Kubernetes cluster. We are going to use the GitLab Container Registry for this purpose.
Before pushing the images, we need to log in to the GitLab Container Registry. Start by exporting your GitLab username and the GitLab instance:
You can get your username using the following command:
GITLAB_USERNAME=$(glab api /user | jq -r .username)
Then run:
cat <>~/.bashrc && source ~/.bashrc
export GITLAB_USERNAME=$GITLAB_USERNAME
EOF
Log in to the GitLab Container Registry:
docker login registry.gitlab.com \
-u $GITLAB_USERNAME \
--password-stdin <<< $GITLAB_API_TOKEN
Export the GitLab Container Registry URL as an environment variable. Note that the URL is composed of the GitLab Container Registry URL and the group and project names and should normally look like this: registry.gitlab.com/$GITLAB_GROUP/$GITLAB_PROJECT. However, since the GitLab Container Registry does not support uppercase characters, we need to ensure that the URL is in lowercase. The following command will export the lowercase URL of the GitLab Container Registry to the .bashrc file:
cat <>~/.bashrc && source ~/.bashrc
export GITLAB_REGISTRY_URL="registry.gitlab.com/${GITLAB_GROUP,,}/${GITLAB_PROJECT,,}"
EOF
Tag the Docker images with the GitLab Container Registry URL:
DevSecOps in Practice
A Hands-On Guide to Operationalizing DevSecOps at ScaleEnroll now to unlock current content and receive all future updates for free. Your purchase supports the author and fuels the creation of more exciting content. Act fast, as the price will rise as the course nears completion!
