The gitlab-ci.yml file specifies instructions for GitLab
to build, test, and deploy Docker images through a series of jobs and
stages that form a CI/CD pipeline:
hadolint : This job uses the hadolint
Docker image to check the Dockerfile for best practices and potential
errors.getsquid_vars : This job retrieves the latest Squid
version, updates the README.md with version info, and writes the version
to a file variables.env which will be used by subsequent
jobs.docker-hub-build : This job builds the Docker image
with the retrieved squid squid version for the amd64 architecture.docker-hub-build-arm : This job builds the Docker image
with the retrieved squid version for the arm architecture.docker-hub-test : This job tests the Docker image that
has been built for the amd64 architectureto verify if squid proxy is
running as expected.docker-hub-test-arm : This job tests the Docker image
that has been built for the arm architecture to verify if squid proxy is
running as expected.dive : This job pulls the Docker image for the amd64
architecture and analyses it using dive which is a tool for
exploring a Docker image, layer contents, and discovering ways to shrink
the size of Docker/OCI image.dive-arm : This job pulls the Docker image for the arm
architecture and analyses it using dive.SquidParseConfig : This job checks if the squid.conf
configuration file can be parsed without errors.push-docker-hub : This job tags the built Docker image
for the amd64 architecture and pushes it to Docker Hub.push-docker-hub-arm : This job tags the built Docker
image for the arm architecture and pushes it to Docker Hub.chatgpt_analysis : This job generates and deploys
documentation of the pipeline to the website.update_dockerhub_readme : This job updates the ReadME
file on Docker Hub with the content of README.md from the
repository.Every job in the gitlab-ci.yml file plays a role in assuring the Docker images built are of high quality, secure, and perform the intended purpose.
hadolint job is used for Dockerfile linting which is
the process of running a program that will analyse code for potential
errors. Here we use a Docker image to run hadolint, which checks the
Dockerfile for best practices and potential errors. The commands used in
script are:
cd $CI_PROJECT_DIR
hadolint --ignore DL3008 DockerfileThe cd $CI_PROJECT_DIR navigates to the directory
containing the git repository and the
hadolint --ignore DL3008 Dockerfile command runs hadolint
against the Dockerfile in that repository. ‘DL3008’ is an ID of a
specific rule that hadolint checks. Adding this rule to the
--ignore flag will ignore this rule during the
linting.
getsquid_vars: This job fetches the latest release
version of Squid using curl and updates the README and
variables.env file.Both docker-hub-build and
docker-hub-build-arm jobs handles the docker build process
of the Dockerfile for amd64 and arm architectures respectively. Docker
build is handled using the docker build command which
creates Docker images from the Dockerfile and a ‘context’. ‘context’
refers to the set of files in the specified PATH or URL.
The docker-hub-test and docker-hub-test-arm
jobs checks whether the Docker image builds and Squid proxy is working
as expected with a simple curl command by routing the HTTP/HTTPS
requests through the proxy.
The docker-hub-test and docker-hub-test-arm
jobs will run only if docker-hub-build and
docker-hub-build-arm jobs succeed as they are defined as
dependencies.
The dive and dive-arm jobs are used to
explore each layer in the Docker image and provide a tree view of a
Docker image and layer contents. wagoodman/dive:latest
Docker image is used to do this which shows a summary of the image size
efficiency and user wasted space.
The SquidParseConfig reads the squid configuration file
/etc/squid/squid.conf with the Squid binary already present
in the Docker container $CONTAINER_BUILD_NOPROD_NAME_AMD64
to ensure the configuration can be parsed and doesn’t contain any
errors.
The push-docker-hub and push-docker-hub-arm
jobs tags the Docker images with the Squid version and architecture and
then pushes them to Docker Hub.
chatgpt_analysis provides a deep analysis of the GitLab
CI/CD jobs and pipelines, and provides the result in markdown format
(*.md) and HTML format (*.html). The generated
html file is then securely copied to a remote server.
update_dockerhub_readme updates Docker Hub’s ReadME for
the Docker repository with the contents of README.md from git
repository.
Environment Variables used by jobs:
$CI_BUILDS_DIR, $CI_PROJECT_NAME,
$CI_COMMIT_BRANCH are GitLab predefined environment
variables used to clone Git repository into the specified (tmpfs)
directory.
CONTAINER_CLIENT_IMAGE,
CONTAINER_BUILD_NOPROD_NAME_ARM,
CONTAINER_TEST_NAME, SQUID_VERSION,
$DOCKER_HUB_USER, $DOCKER_HUB_PASSWORD,
$DOCKER_HUB_TOKEN are custom environment
variables.
DOCKER_HUB_REGISTRY and DOCKER_HUB_USER
are used to login to Docker Hub.
Files used by jobs:
.gitlab-ci.yml - This is the main GitLab CI/CD
configuration file specifying all jobs and stages.README_template.md - The ‘getsquid_vars’ job updates
this template file with Squid version information and renames it to
README.md.variables.env - This file is used to share the fetched
Squid version info between different jobs.Jobs are linked through needs, which means each job can only run if the jobs it ‘needs’ are passed successfully.
docker-hub-test and docker-hub-test-arm
needs getsquid_vars and docker-hub-build.push-docker-hub needs
docker-hub-test.chatgpt_analysis needs getsquid_vars,
docker-hub-test, docker-hub-test-arm.push-docker-hub-arm needs getsquid_vars
and docker-hub-test-arm.update_dockerhub_readme needs
getsquid_vars.Artifacts are files which are created when a job finishes. The artifacts keyword is used to specify a list of files and directories which should be attached to the job when it is finished. Most jobs here produces artifacts which are used by subsequent jobs:
getsquid_vars job writes the squid version to
variables.env and updates the README.md with the version
info.docker-hub-build, docker-hub-build-arm
jobs build the Docker image and pushes it to Docker Hub.docker-hub-test, docker-hub-test-arm jobs
tests if squid proxy is functioning as expected.push-docker-hub, push-docker-hub-arm jobs
tag the Docker images with the Squid version and architecture and then
pushes them to Docker Hub.chatgpt_analysis job generates an HTML file
chatgpt_analysis*.html and markdown file
chatgpt_analysis*.md containing the deep analysis of the
GitLab CI/CD jobs and pipelines.update_dockerhub_readme job updates Docker Hub’s ReadME
for the Docker repository with the content of README.md.The latest commit ‘9790c65 README Auto update [skip ci]’ was about updating README.md with the latest version of Squid. The ‘[skip ci]’ keyword in the commit message tells GitLab to skip the CI/CD pipeline for this commit.