In the pipeline defined in the gitlab-ci.yml file, the
following jobs are included:
hadolint: This job is implemented for maintaining
the quality of the Dockerfile. It uses the
hadolint/hadolint image to lint and validate Dockerfile
syntax.
chatgpt_analysis: This job generates a Markdown file
that provides an in-depth analysis of all the GitLab CI/CD
jobs.
getsquid_vars: This job fetches the latest version
of Squid to be used in other pipeline jobs. It also updates the
README.md file with the latest Squid version and date.
docker-hub-build and
docker-hub-build-arm: These jobs build a Docker image for
Squid using the Squid version fetched in the getsquid_vars
job. The Docker image is tagged and pushed to the Docker Hub registry.
The Docker image is built for both amd64 and arm architecture.
docker-hub-test and
docker-hub-test-arm: These jobs test the Docker image built
in the docker-hub-build job. They set up Squid proxy and
run a curl request to google.com via the Squid proxy. They test the
Docker image for both amd64 and arm architecture.
push-docker-hub and
push-docker-hub-arm: These jobs push the tested Docker
image to Docker Hub registry with appropriate tags. They push to Docker
Hub for both amd64 and arm architecture.
update_dockerhub_readme: This job updates the README
file in the project’s Docker Hub repository, using the README.md file
updated in the getsquid_vars job.
SquidParseConfig and Dive: These jobs
ensure the configuration of the Squid is correct and checks the
efficiency of the layers used in the Dockerfile.
Now let’s look at the specific purpose and objective of each job in the pipeline.
hadolint JobThe hadolint job uses hadolint, a
Dockerfile linter tool, to check if the Dockerfile adheres to best
practices. The job is defined as follows:
hadolint:
image: hadolint/hadolint:latest-debian
stage: Quality
before_script:
- cd $CI_PROJECT_DIR
script:
- hadolint --ignore DL3008 DockerfileThe before_script and script sections of
the job use standard Linux commands to navigate to the project directory
and run hadolint on Dockerfile.
chatgpt_analysis JobThe chatgpt_analysis job uses OpenAI’s chatbot, GPT3, to
generate a Markdown file that provides an in-depth analysis of all the
GitLab CI/CD jobs. The created Markdown file is named
chatgpt_analysis_$(date +%Y%m%d).md, where
$(date +%Y%m%d) represents the current date.
getsquid_vars JobThe getsquid_vars job is vitally important because it
fetches the latest available version of Squid, which is later used in
other pipeline jobs. Besides, it updates the README file with the
current Squid version and date, commits and pushes this file to the Git
repository. If an error occurs during the commit, the script goes on
(this is what || true means), since the README file may not
change.
docker-hub-build
and docker-hub-build-arm JobsThese jobs are responsible for building Squid Docker images for both
amd64 and arm architectures according to the Dockerfile. The images are
then tagged with the build-noprod-amd64 and
build-noprod-arm tags, respectively, and pushed to the
Docker Hub registry.
docker-hub-test
and docker-hub-test-arm JobsThe docker-hub-test and docker-hub-test-arm
jobs test the built Docker images for amd64 and arm architectures
respectively. Squid proxy is set up, and a curl request is made to
Google’s website via this proxy. If the request is successful, then the
Docker image is working as expected.
push-docker-hub
and push-docker-hub-arm JobsAfter the Docker images have been tested and verified, the
push-docker-hub and push-docker-hub-arm jobs
push these images to Docker Hub. The images are tagged with the Squid
version and amd64 or arm, and then they are
pushed to Docker Hub. If the branch is master, they are
also tagged as latest-amd64, latest-arm, and
latest.
update_dockerhub_readme
JobAfter all of the previous jobs have been run, the
update_dockerhub_readme job updates the README.md file for
the Docker image on Docker Hub. This is done by pushing the README.md
file that was updated during the getsquid_vars job.
SquidParseConfig JobThis job checks the syntax of the Squid configuration file which comes with the Docker image and verifies it doesn’t have any errors.
Dive JobThis job analyzes the efficiency and wastefulness of the Dockerfile. It does not provide any functionality to the GitLab Pipeline but it is purely informative. It will generate a report about the Dockerfile composition and will flag inefficient parts. This could be helpful to reduce the image size or lower the build time.
Several parameters, environment variables, and files are used in the pipeline.
Environment variables are used as parameters in the pipeline. Some of the environment variables used are:
$DOCKER_HUB_USER: The username for Docker Hub.$DOCKER_HUB_PASSWORD: The password for Docker Hub.$HUB_REGISTRY_IMAGE: The Docker Hub registry and image
name for the Docker images.$SQUID_VERSION: The latest version of Squid.$CHATGPT_API_KEY: The API key for ChatGPT.$SSH_NOSTROMO_KEY: The SSH key utilised to securely
copy files.$CI_PROJECT_DIR: This is a predefined GitLab CI/CD
variable and refers to the absolute path where the repository is cloned
in the runner job.$CI_BUILDS_DIR: This is a predefined GitLab CI/CD
variable and refers to the directory where builds are held, used in
order to define GIT_CLONE_PATH variable.$CI_PROJECT_NAME and $CI_COMMIT_BRANCH:
These predefined GitLab CI/CD variables are used to define a unique path
for each pipeline, preventing concurrency issues.$CONTAINER_CLIENT_IMAGE: This is the base image used to
run commands in jobs like chatgpt_analysis and
getsquid_vars, in this case, it’s
debian:stable-slim.$CONTAINER_BUILD_NOPROD_NAME_ARM and
$CONTAINER_BUILD_NOPROD_NAME_AMD64: These are Docker Hub
images names for arm and amd64 architectures respectively.The pipeline references several files:
variables.env: This file is produced by the
getsquid_vars job and contains the Squid version.Dockerfile: This file specifies the steps to build the
Squid Docker image and is used in the docker-hub-build and
docker-hub-build-arm jobs.README.md and README_template.md: These
files are used in the getsquid_vars and
update_dockerhub_readme jobs. The README.md file from the
Git repository is updated and then sent to Docker Hub.The “needs” keyword is used in GitLab CI/CD pipeline to create
dependencies between jobs. For example, the
docker-hub-build job depends on the
getsquid_vars job because it uses the Squid version
specified by getsquid_vars. This dependency is defined with
the “needs” keyword as follows:
docker-hub-build:
...
needs:
- getsquid_vars
...The “needs” dependency specifies that docker-hub-build
job should only run after the getsquid_vars job has
successfully completed.
The test jobs like docker-hub-test are dependent on
their corresponding build jobs docker-hub-build. Similarly,
the push jobs like push-docker-hub depend on their
corresponding test jobs and on getsquid_vars.
CharGPT analysis job needs the result from
docker-hub-test and docker-hub-test-arm jobs
to include them in the analysis report. jobs like
update_dockerhub_readme need getsquid_vars job
to execute.
The Docker images on Docker Hub are interdependent:
latest and latest-amd64 depend on the amd64
image, while latest-arm and the image tagged with Squid
version depend on both amd64 and arm images.
The pipeline defined in the gitlab-ci.yml file produces
several outcomes:
The getsquid_vars job produces the
variables.env file, which includes the latest Squid
version. This file is used as an artifact in subsequent jobs.
The chatgpt_analysis job generates a Markdown file,
saved as an artifact after the job is completed.
The docker-hub-build and
docker-hub-build-arm jobs produce Docker images for Squid
for amd64 and arm architectures respectively, and these images are
pushed to Docker Hub.
The docker-hub-test and
docker-hub-test-arm jobs test the Docker images and produce
logs that show the test results.
The push-docker-hub and
push-docker-hub-arm jobs push the Docker images to Docker
Hub using the appropriate tags, producing Docker images on Docker Hub as
the outcome.
The update_dockerhub_readme job updates the
README.md file of the Docker Hub repository.
The latest commit message is “README Auto update [skip ci]”. This
commit message is generated by the getsquid_vars job, which
updates the README.md file with the current Squid version and date, and
then commits this change to the Git repository.
The “[skip ci]” tag in the commit message is used to prevent CI/CD pipelines from being triggered for this commit. This is useful because the README.md update does not affect the application code or Docker images, and therefore, does not require a pipeline run.
The getsquid_vars job also pushes the updated README.md
file to the Git repository. As a result, the README.md file in the Git
repository always has the latest information about the Squid
version.
The latest commit does not directly impact on the CI/CD pipeline run. Its purpose is to provide relevant and up-to-date information to the users of the Git repository and the Docker images, by keeping the README.md file updated.
Project:Project Pipeline:Pipeline Docker images:Docker images