Let’s go through the jobs sequentially as listed in the ‘stages’ of the gitlab-ci.yml file:
Note that the order of the jobs does not directly represent the order
of execution, as jobs can be dependent on one another. The
needs parameter allows a job to start when its dependencies
finish, as opposed to waiting for all jobs from prior stages to
finish.
hadolint is a Docker image linter used to check
Dockerfile. The linting helps to promote best practices of writing
Dockerfiles. The Hadolint job here:
$CI_PROJECT_DIRbefore_script:
- cd $CI_PROJECT_DIR
script:
- hadolint --ignore DL3008 Dockerfile This job is used for getting the latest Squid version, update the README file, and push back the changes to the project. The important details to note here:
$SQUID_VERSION variable is populated by making a
curl request to GitHub’s Squid release page.script:
- apt update && apt install git curl ca-certificates -y --no-upgrade --no-install-recommends --no-install-suggests
- export SQUID_VERSION=$(curl -LsXGET https://github.com/squid-cache/squid/releases/latest | grep -m 1 "Release" | cut -d " " -f4 |tr -d 'v')
- echo "SQUID_VERSION=$SQUID_VERSION" > variables.env
- echo $SQUID_VERSION
- sed -i "s/{{SQUID_VERSION}}/$SQUID_VERSION/g" README_template.md
- sed -i "s/{{DATE}}/$(date +%Y%m%d)/g" README_template.md
- cp README_template.md README.md
- git config user.email "fredbcode"
- git config user.name "fredbcode"
- git add README.md
- git commit -m "README Auto update [skip ci]" || true
- git push https://$GITLAB_TOKEN@gitlab.com/fredbcode-images/squid.git HEAD:master || trueIn this job, the Docker image is built with the latest version of Squid, the image is then tagged, and finally, it’s pushed onto Docker Hub. Noteworthy steps include:
before_script:
- docker login -u "$DOCKER_HUB_USER" -p "$DOCKER_HUB_TOKEN" $DOCKER_HUB_REGISTRY
script:
- source variables.env
- docker build --build-arg SQUID_VERSION=$SQUID_VERSION --pull -t $CONTAINER_BUILD_NOPROD_NAME_AMD64 .
- docker push $CONTAINER_BUILD_NOPROD_NAME_AMD64Similarly other jobs like docker-hub-build-arm,
docker-hub-test, docker-hub-test-arm,
SquidParseConfig, dive-arm,
push-docker-hub, push-docker-hub-arm, and
update_dockerhub_readme has its own specific purposes and
steps which work in conjunction with the steps outlined above to achieve
the desired end goal of the pipeline.
There are several environment variables in use within the job. Some
of them are GitLab CI predefined variables like
$CI_PROJECT_DIR and $CI_BUILDS_DIR, which
provide directory paths within the runner. There are also custom
variables, like $SQUID_VERSION, which is populated with the
latest version number from the GitHub releases. There’s also
$DOCKER_HUB_USER, $DOCKER_HUB_TOKEN, and
$DOCKER_HUB_REGISTRY - these are most likely defined as
CI/CD variables in the GitLab project, and they’re used to authenticate
with Docker Hub.
For some jobs, the GitLab runner will create an artifact (contained
within the artifacts key) that can be used by later jobs.
For example, in the getsquid_vars job the variables.env is
created that holds the Squid version number, and later jobs can use this
to know what version number to use.
Files referenced include ‘Dockerfile’ in the hadolint job (the Dockerfile of our project), and ‘README_template.md’ and ‘README.md’ in the getsquid_vars job (these are used for updating the README on our repository with the latest version number).
Jobs are linked to one another using the needs keyword.
For example, the docker-hub-build job needs the
getsquid_vars job. This means that as soon as the getsquid_vars job is
finished, the docker-hub-build job will be able to start, instead of
having to wait for all the prior stages to be finished.
Most jobs create Docker images and push them to Docker Hub. These
images are then pulled down and used in later jobs for testing and other
purposes. Some jobs also create text output that is saved as an
artifact, such as the variables.env file, created by the
getsquid_vars job, and various logs from testing jobs.
The referenced commit “1ee657a Fix Job content” seems to have introduced necessary fixes to jobs making them more efficient or resolving an outstanding issue. This could be by changing action order, adding or removing actions or stages, or modifying the way an action/stage is performed. The precise impact on the pipeline could be more accurately described if the commit changes were made available. In general, this might result in changes to execution time, the order in which jobs are run, or even the overall output of the pipeline.