The pipeline consists of several jobs executed in stages as defined in the .gitlab-ci.yml file. Here are the jobs ordered by the stages in which they run:
last_squid_version.txt and creates
version_changed file. It then commits and pushes these
updates to the Git repository.docker-hub-build: This job builds Docker images for Squid using the Docker dind (Docker in Docker) service.
docker-hub-build-arm: This job is similar to the
docker-hub-build job, but it creates Docker images for ARM
architecture.
docker-hub-test: Launches the Docker image built
in the docker-hub-build job and performs simple tests to
ensure its correct operation.
SquidParseConfig: Performs syntax checks on the Squid configuration file.
dive: Analyzes the layers of the Docker image
built in the docker-hub-build job using the Dive tool,
giving insights about the efficiency of the image layers.
docker-hub-test-arm: Similar to
docker-hub-test, but for the ARM image.
push-docker-hub: Tags and pushes the Docker images to the Docker Hub after tests pass.
push-docker-hub-arm: Does the same as
push-docker-hub but for the Squid image built for ARM
architecture.
update_dockerhub_readme: Updates Docker Hub description for the Docker image using the repository’s README.md file.
chatgpt_analysis: Uses AIML techniques for detailed testing and analysis pipeline for the new Squid version. These tests are then documented and stored as an artifact and also uploaded to an external website via SCP.
This job utilizes Hadolint, a Dockerfile linter that checks the Dockerfile’s syntax and best practices. This ensures the Dockerfile is written correctly before the beginning of the rest of the stages, which involve building and testing Docker images. If the Dockerfile doesn’t pass Hadolint’s checks, the pipeline fails at this point, avoiding further resource utilization.
The commands used in this job are:
cd $CI_PROJECT_DIR # navigates to the project directory.
hadolint --ignore DL3008 Dockerfile # runs the Hadolint linter on the Dockerfile ignoring a specific rule (DL3008).
This job fetches the latest Squid version from its GitHub releases page, and compares it with the previously stored latest version. If they differ, the job updates the README.md and variables.env files with the new version, commits them, and pushes to the repository.
The commands used in this job include but are not limited to:
apt update && apt install git curl ca-certificates -y --no-upgrade --no-install-recommends --no-install-suggests # updating packages and installing necessary ones.
export SQUID_VERSION=$(curl -LsXGET https://github.com/squid-cache/squid/releases/latest | grep -m 1 "Release" | cut -d " " -f4 |tr -d 'v') # fetching the latest Squid version and storing it.
echo "SQUID_VERSION=$SQUID_VERSION" > variables.env # updating the variables.env file with the new Squid version.
git config user.email "fredbcode" && git config user.name "fredbcode" # set the git user's name and email.
git add README.md ci/last_squid_version.txt variables.env && git commit -m "README Auto update and update last_squid_version [skip ci]" && git push https://$GITLAB_TOKEN@gitlab.com/fredbcode-images/squid.git HEAD:master # commit and push changes to the Git repository.
These jobs create Docker images for x64 and ARM architecture respectively. For each job, a Docker image is built using the Dockerfile in the project’s repository. The image is then tagged with a unique name and pushed to Docker Hub. The Docker images for both the architectures are necessary as they ensure the application runs seamlessly on different processor configurations.
The commands used in these jobs include:
docker login -u "$DOCKER_HUB_USER" -p "$DOCKER_HUB_TOKEN" $DOCKER_HUB_REGISTRY
source variables.env
docker build --build-arg SQUID_VERSION=$SQUID_VERSION --pull -t $CONTAINER_BUILD_NOPROD_NAME_AMD64 .
docker push $CONTAINER_BUILD_NOPROD_NAME_AMD64
These jobs test the Docker images built earlier. It does so by
installing curl and then trying to fetch google’s homepage
using Squid’s proxy server.
The commands used in these jobs include:
export https_proxy=http://$CONTAINER_TEST_NAME:3128 && curl -k https://www.google.fr
apt update && apt install -y curl --no-upgrade --no-install-recommends --no-install-suggests
It performs syntax check on the Squid configuration file. The checks
are performed by invoking
squid -k parse <config-file-name>. It ensures the
configuration file is syntactically correct before the image is deployed
in an environment.
The commands used in this job include:
/usr/sbin/squid -k parse /etc/squid/squid.conf
The Dive tool is used to explore a docker image’s layers, find
inefficient parts in it and the waste that can be avoided. This job uses
the wagoodman/dive:latest Docker image to perform analyses
on the Docker images built in the docker-hub-build and
docker-hub-build-arm jobs.
The commands used in these jobs include:
docker pull $CONTAINER_BUILD_NOPROD_NAME_AMD64
dive $CONTAINER_BUILD_NOPROD_NAME_AMD64
After all checks and tests are successfully done, these jobs tag the
Docker images with the new Squid version and latest tag,
and then push them to Docker Hub. These allow end users to use the
Docker images with the latest tag to always get the most
recent stable version, or with the version-specific tag to get a
particular version.
The commands used in these jobs include:
docker pull $CONTAINER_BUILD_NOPROD_NAME_AMD64
docker tag $CONTAINER_BUILD_NOPROD_NAME_AMD64 $HUB_REGISTRY_IMAGE:$SQUID_VERSION-amd64
docker push $HUB_REGISTRY_IMAGE:$SQUID_VERSION-amd64
docker tag $CONTAINER_BUILD_NOPROD_NAME_AMD64 $HUB_REGISTRY_IMAGE:latest-amd64
docker push $HUB_REGISTRY_IMAGE:latest-amd64
docker tag $CONTAINER_BUILD_NOPROD_NAME_AMD64 $HUB_REGISTRY_IMAGE:latest
docker push $HUB_REGISTRY_IMAGE:latest
At the top of the .gitlab-ci.yml file, variables are declared to be used throughout the pipeline. Some of these variables include:
GIT_CLONE_PATH: Path to clone the repository on the
GitLab CI/CD runner.CONTAINER_CLIENT_IMAGE: Image to use for the client
that communicate with main containers (debian: stable-slim).DOCKER_HUB_USER: Docker Hub username.DOCKER_HUB_TOKEN: Docker Hub token.DOCKER_HUB_REGISTRY: Docker registry to use.HUB_REGISTRY_IMAGE: Docker Hub image name.CONTAINER_TEST_NAME: The name of the test container
(squid).Environment variables are referred to in the pipeline using the
$VARIABLE_NAME syntax. These are defined directly in the
pipeline’s settings or in the .gitlab-ci.yml file.
File references are used to refer to files located in the pipeline’s
environment. For instance, *.yml is used to include all
YAML files in the respective directory in the pipeline.
Gitlab CI/CD as worded uses the $CI_ prefix for
predefined environment variables, some of them have been used above. For
example $CI_PROJECT_DIR, $CI_PROJECT_NAME,
$CI_COMMIT_BRANCH.
Several jobs in the pipeline depend on other jobs that must complete
before they can start. These dependencies are defined using the
needs keyword. For example, the
docker-hub-test job depends on the
docker-hub-build job as shown below:
needs: ["docker-hub-build"]
This dependency means the docker-hub-test job can’t
commence until the docker-hub-build job has completed
successfully.
The result of several jobs in the pipeline is the creation of an
artifact, a file stored and made available as part of a job’s completed
result. For example, in the getsquid_vars job, the
environment variables are stored in a variables.env file
and set as an artifact:
artifacts:
expire_in: 1 hour
paths:
- variables.env
This makes the variables.env file available to other
jobs (that depend on getsquid_vars) and allows them to
access the environment variables even after the
getsquid_vars job has finished executing.
Commit hash: f52d5cf
Title:
Merge branch 'fix/hadolint-user-healthcheck' into 'master'
Description: Fix Dockerfile Hadolint warnings
Impact on the pipeline: The commit introduces a change that resolves
a warning generated by the Hadolint linter. This change impacts the
hadolint job whose role is to perform linting checks on the
Dockerfile, and it helps to ensure the Dockerfile continues to follow
the best practices. It does not directly affect other jobs unless the
Hadolint linter check fails. This is a quality control update that
doesn’t affect the functionality of the app, but it may reduce possible
deployment issues and improve the Dockerfile’s readability.