The GitLab pipeline is composed of several stages involving building, testing and pushing Docker images both for AMD64 and ARM architectures, running quality tests and eventually generating a ChatGPT Analysis. The jobs in the order defined in the ‘stages’ section:
hadolint - This job checks Dockerfile according to
hadolint rules.docker-hub-build - Job to build AMD64 Docker image with
Squid.docker-hub-test - Testing the built Docker image based
on a curl request against google home page.SquidParseConfig - Checks the syntax of the
squid.conf configuration.dive - This job runs wagoodman/dive to
analyze the AMD64 Docker image.push-docker-hub - Job to push AMD64 Docker image to
DockerHub repository.docker-hub-build-arm - Same as
docker-hub-build but for ARM Docker image.docker-hub-test-arm - Same as
docker-hub-test but for ARM Docker image.dive-arm - Same as dive but for ARM Docker
image.push-docker-hub-arm - Pushes ARM Docker image to
DockerHub repository.chatgpt_analysis - This job generates a text file
through a ChatGPT API that provides a detailed explanation of the
pipeline.hadolint:
image: hadolint/hadolint:latest-debian
stage: quality
before_script:
- cd $CI_PROJECT_DIR
script:
- hadolint --ignore DL3008 Dockerfile Jobs help ensure that the code adheres to the quality standards and
conventions defined by the team. In this case, the hadolint
job runs a linter tool on the Dockerfile to ensure it meets the Docker
best practices.
This job is used to build an AMD64 Docker image with the latest version of Squid.
docker-hub-build:
stage: Docker-hub-build
image: docker:dind
artifacts:
expire_in: 2 hours
paths:
- $CI_PROJECT_DIR
timeout: 3 hours
before_script:
- docker login -u "$DOCKER_HUB_USER" -p "$DOCKER_HUB_TOKEN" $DOCKER_HUB_REGISTRY
script:
- cd $CI_PROJECT_DIR
- apk add --no-cache curl
- export SQUID_VERSION=$(curl -s http://www.squid-cache.org/Versions/v6/ | egrep -m 1 -oh squid-.*.tar.gz | cut -d '"' -f1)
- docker build --build-arg SQUID_VERSION=$SQUID_VERSION --pull -t $CONTAINER_BUILD_NOPROD_NAME_AMD64 .
- docker push $CONTAINER_BUILD_NOPROD_NAME_AMD64The docker login command is used to log in to the Docker
registry. The export SQUID_VERSION is used to fetch the
latest version of Squid to be built into the Docker image. The
docker build command builds the Docker image, passing the
Squid version as a build argument. Lastly, the built Docker image is
pushed to Docker Hub using the docker push command.
After the Docker image has been created, it’s a good practice to test
whether it works as expected. In this case, the
docker-hub-test job is implemented for this specific
purpose.
docker-hub-test:
stage: Docker-hub-test
extends: .services-amd64
script:
- apt update && apt install -y curl --no-upgrade --no-install-recommends --no-install-suggests
- export https_proxy=http://$CONTAINER_TEST_NAME:3128 && curl -k https://www.google.fr
variables:
HOSTNAME: squidpipeline
needs: ["docker-hub-build"]This job runs a curl command against the google home page using the built Docker image as a proxy server. If the response from the curl command is successful, it means the Docker image is working as expected.
This job is utilized to check if the Squid configuration file
squid.conf in the Docker image is valid.
This job is responsible for analyzing the Docker image layers using
wagoodman/dive.
The push-docker-hub job is crucial because it’s
responsible for pushing the Docker image to Docker Hub. This step takes
place once the image has been successfully built and tested.
push-docker-hub:
stage: Docker-hub-pushtag
image: docker:dind
before_script:
- docker login -u "$DOCKER_HUB_USER" -p "$DOCKER_HUB_TOKEN" $DOCKER_HUB_REGISTRY
script:
- 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:latestThese jobs are similar to docker-hub-build,
docker-hub-test, dive, and
push-docker-hub, except they are building, testing,
analyzing, and pushing an ARM based Docker image.
This job generates a text file through a ChatGPT API that provides a
detailed explanation of the pipeline. It uses OpenAI’s function call
openai.ChatCompletion.create to get a response from a chat
model (gpt-3.5-turbo).
The pipeline script makes use of several parameters, environment
variables, and file references. In the variables section,
several environment variables are defined such as: -
GIT_CLONE_PATH: The path to clone the repository. It is
used to set a specific path for the cloned Git repository. -
CONTAINER_CLIENT_IMAGE - CI_JOB_NAME,
CI_COMMIT_REF_SLUG, CI_PROJECT_DIR,
CI_COMMIT_BRANCH, etc. These are pre-defined environment
variables provided by Gitlab CI/CD, allowing you to access specific
CI/CD information. - $DOCKER_HUB_USER and
$DOCKER_HUB_TOKEN are used to authenticate with Docker Hub.
- SQUID_VERSION is fetched from the newest version on the
official Squid versions page.
In the before_script sections you will notice a
reference to Dockerfile which is a Dockerfile located in
the repository root. Other files referenced by the pipeline include
.gitlab-ci.yml and the files in the gitlabci
directory, which are critical to the operation of the CI job.
There are dependencies set between jobs using the needs
keyword. For example, in the docker-hub-test job, the
needs: ["docker-hub-build"] keyword is a signal that the
docker-hub-build job needs to run successfully before
docker-hub-test can execute.
Jobs in the pipeline often produce artifacts, such as logs, test
reports, or build outputs that are used by other jobs or for debugging
purposes. In the hadolint and docker-hub-build
jobs, an artifact containing the Dockerfile and CD Project Directory is
created. These artifacts are saved and can be downloaded for 2 hours
after the pipeline finishes.
In the chatgpt_analysis job, a markdown file and an HTML
file is created and then copied over to a remote server. These files
give a detailed explanation of the pipeline.
This commit updated the content of the chatgpt_analysis
job. The RGB values fetched from the satellite image are now included in
the textual chat log. The generated text is also saved both in markdown
(.md) and HTML format. This addition provides more context to the
ChatGPT explanations and makes the GitLab pipeline more informative.