getsquid_vars - We define this job to get the latest SQUID_VERSION from Squid’s GitHub repository, update README with this version, and commit the changes. It runs during the ‘Get-version’ stage and uses a simple Debian image to perform the tasks.
hadolint - It is a part of the ‘Quality’ stage which is responsible for ensuring the Dockerfile adheres to the best practices. It uses hadolint for this purpose.
docker-hub-build and docker-hub-build-arm - These jobs collectively build the Docker images for AMD64 and ARM architecture types sequentially, using the latest Squid version obtained in ‘getsquid_vars’ job.
docker-hub-test and docker-hub-test-arm - These jobs then test these built Docker images to ensure they are working as expected.
docker-hub-pushtag and docker-hub-pushtag-arm - They then push these verified Docker images to DockerHub.
chatgpt_analysis - It provides an understanding of how this particular GitLab CI/CD pipeline works using the GPT3 AI model.
pushreadme.yml - This job updates the full description of the Docker repository by pushing the latest README file. It runs during the ‘Docs’ stage.
Let’s understand each job one by one with a step-by-step breakdown:
script:
- apt update && apt install git curl ca-certificates -y --no-upgrade --no-install-recommends --no-install-suggests
- 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
- sed -i "s/{{SQUID_VERSION}}/$SQUID_VERSION/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 || truescript:
- hadolint --ignore DL3008 Dockerfile It uses Hadolint, a Dockerfile linter to check the Dockerfile and ignores the DL3008 rule.
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_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 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-amd64chatgpt_analysis - Analyzes this GitLab CI/CD pipeline using the OpenAI’s GPT3 model and creates an in-depth explanation saved as an artifact.
pushreadme.yml - This job updates the full description of the Docker repository by pushing the latest README file.
script:
- README_CONTENT=$(cat README.md)
- PAYLOAD=$(jq -n --arg desc "$README_CONTENT" '{"full_description":$desc}')
- echo "Payload JSON:$PAYLOAD"
- TOKEN=$(curl -v -s -X POST -H "Content-Type:application/json" -d '{"username":"'"$DOCKER_HUB_USER"'","password":"'"$DOCKER_HUB_PASSWORD"'"}' https://hub.docker.com/v2/users/login/ | jq -r .token)
- curl -X PATCH -H "Authorization:JWT $TOKEN" -H "Content-Type:application/json" -d "$PAYLOAD" https://hub.docker.com/v2/repositories/$HUB_REGISTRY_IMAGEThis job % Reads the content from README.md, prepares a JSON payload for Docker Hub API’s PATCH request, fetches the Docker Hub API token, and uses it to update the Docker repository’s full description on Docker Hub.
The variables used here include:
Some jobs depend on others, running after them because the subsequent jobs require the result or artifact of the previous one. For example:
Artifacts created in this pipeline includes:
This commit was generated by the ‘getsquid_vars’ job. The job updated the README with the latest Squid version and date, committed the changes using the commit message “README Auto update [skip ci]”. The “[skip ci]” phrase tells GitLab CI/CD to ignore this commit and not run the pipeline for this particular push. Since this is an automated update to the README and doesn’t contain any code changes, it doesn’t require the whole CI/CD pipeline to be rerun. This commit mainly helps us keep our README up-to-date with the latest Squid version without unnecessarily triggering the pipeline.