Skip to content
Snippets Groups Projects
Commit 624d0cdc authored by Fabrice Gangler's avatar Fabrice Gangler :art:
Browse files

ci: improve process to build and push all images to Gitlab container registry

parent f741f51b
No related branches found
No related tags found
No related merge requests found
Pipeline #87111 failed
Showing
with 312 additions and 8 deletions
#!/usr/bin/env bash
##############################################################################################
set -o errexit # enable exit if one of command fails
set -o pipefail # enable exit if one of pipe command fails
set -o nounset # enable exit if any of variables is not set
# set -o xtrace # all executed commands are printed to the terminal
##############################################################################################
source config_all-images.sh
source config_gitlab-repository.sh
source lib/docker-all-images.lib.sh
source lib/docker-image.lib.sh
##############################################################################################
trap handle_error ERR # Set the error handler function
trap handle_exit EXIT # Set the exit handler function
##############################################################################################
(check_all_images_configuration) # executed in a subshell
(remove_all_images) # executed in a subshell
(build_all_images) # executed in a subshell
(resume_build) # executed in a subshell
##############################################################################################
exit 0
#!/usr/bin/env bash
##############################################################################################
set -o errexit # enable exit if one of command fails
set -o pipefail # enable exit if one of pipe command fails
set -o nounset # enable exit if any of variables is not set
# set -o xtrace # all executed commands are printed to the terminal
##############################################################################################
source config_all-images.sh
source config_gitlab-repository.sh
source lib/docker-all-images.lib.sh
source lib/docker-image.lib.sh
##############################################################################################
trap handle_error ERR # Set the error handler function
trap handle_exit EXIT # Set the exit handler function
##############################################################################################
(check_all_images_configuration) # executed in a subshell
(remove_all_images) # executed in a subshell
(build_all_images) # executed in a subshell
(resume_build) # executed in a subshell
(push_all_imagess) # executed in a subshell
(resume_build) # executed in a subshell
##############################################################################################
exit 0
#!/usr/bin/env bash
##############################################################################################
set -o errexit # enable exit if one of command fails
set -o pipefail # enable exit if one of pipe command fails
set -o nounset # enable exit if any of variables is not set
# set -o xtrace # all executed commands are printed to the terminal
##############################################################################################
source config_all-images.sh
source config_gitlab-repository.sh
source lib/docker-all-images.lib.sh
source lib/docker-image.lib.sh
##############################################################################################
trap handle_error ERR # Set the error handler function
trap handle_exit EXIT # Set the exit handler function
##############################################################################################
(push_all_imagess) # executed in a subshell
(resume_build) # executed in a subshell
##############################################################################################
exit 0
# CI ~ Docker images of prerequisites
# CI - Docker images of prerequisites
## Docker images
Docker images of prerequisites usign by **Gitlab CI**:
- [PHP 8.1, Composer and Phive](./php.8.1_composer_phive/)
- [PHP 8.2, Composer and Phive](./php.8.2_composer_phive/)
- [PHP 8.3, Composer and Phive](./php.8.3_composer_phive/)
- [Ubuntu 22.04, PHP 8.1 (Ubuntu packages), Composer, Symfony-CLI, Xdebug and Make](./php.8.1_composer/)
- [Ubuntu 22.04, PHP 8.2 (ppa:ondrej/php), Composer, Symfony-CLI, Xdebug and Make](./php.8.2_composer/)
- [Ubuntu 24.04, PHP 8.3 (Ubuntu packages), Composer, Symfony-CLI, Xdebug and Make](./php.8.3_composer/)
- [Ubuntu 24.04, PHP 8.4 (ppa:ondrej/php), Composer, Symfony-CLI, Xdebug and Make](./php.8.4_composer/)
- [Ubuntu 22.04, PHP 8.1 (Ubuntu packages), Composer, Symfony-CLI, Xdebug and Make](php-8.1_composer/)
- [Ubuntu 22.04, PHP 8.2 (ppa:ondrej/php), Composer, Symfony-CLI, Xdebug and Make](php-8.2_composer/)
- [Ubuntu 24.04, PHP 8.3 (Ubuntu packages), Composer, Symfony-CLI, Xdebug and Make](php-8.3_composer/)
- [Ubuntu 24.04, PHP 8.4 (ppa:ondrej/php), Composer, Symfony-CLI, Xdebug and Make](php-8.4_composer/)
## How to build and push all images to Gitlab container registry?
### Configuration
see:
- [`config_all-images.sh`](config_all-images.sh)
- [`config_gitlab-repository.sh`](config_gitlab-repository.sh)
### Build all images
```bash
cd .gitlab/ci/Dockerfiles
./10_build_all-images.sh
```
### Push all images to Gitlab container registry
```bash
cd .gitlab/ci/Dockerfiles
./30_push_all-images.sh
```
#!/usr/bin/env bash
# shellcheck disable=SC2034 # Don't warn about unused variables in this file
##############################################################################################
DOCKERFILE_DIRECTORIES=(
'php-8.1_composer'
'php-8.2_composer'
'php-8.3_composer'
'php-8.4_composer'
)
##############################################################################################
#!/usr/bin/env bash
# shellcheck disable=SC2034 # Don't warn about unused variables in this file
##############################################################################################
GITLAB_URI="gitlab.adullact.net:4567"
GITLAB_REPOSITORY="comptoir/comptoir-du-libre"
##############################################################################################
#!/usr/bin/env bash
##############################################################################################
# shellcheck disable=SC2317 # Don't warn about unreachable commands in this file
##############################################################################################
# Check all images configuration
check_all_images_configuration () {
echo ""
echo "-------------- CHECK CONFIGURATION -------------------------"
for DOCKERFILE_DIRECTORY in "${DOCKERFILE_DIRECTORIES[@]}"
do
( # executed in a subshell
echo "---> Check [ ${DOCKERFILE_DIRECTORY} ] configuration"
cd "${DOCKERFILE_DIRECTORY}" || exit 255
source "config_docker-image.sh"
if [ "${DOCKERFILE_DIRECTORY}" != "${DOCKER_IMAGE_NAME}" ]; then
echo "EROOR :"
echo "[ ${DOCKERFILE_DIRECTORY} ] directory and [ ${DOCKER_IMAGE_NAME} ] image are not identicatl."
false
fi
)
done
}
# Remove all images
remove_all_images () {
echo ""
echo "-------------- REMOVE ALL IMAGES -------------------------"
for DOCKERFILE_DIRECTORY in "${DOCKERFILE_DIRECTORIES[@]}"
do
echo "---> Remove [ ${DOCKERFILE_DIRECTORY} ] image"
cd "${DOCKERFILE_DIRECTORY}" || exit 255
source "config_docker-image.sh"
remove_docker-image && cd .. || exit 255
done
}
# Build all images
build_all_images () {
echo ""
echo "-------------- BUILD ALL IMAGES -------------------------"
for DOCKERFILE_DIRECTORY in "${DOCKERFILE_DIRECTORIES[@]}"
do
echo ""
echo "-------------> Build [ ${DOCKERFILE_DIRECTORY} ] image"
cd "${DOCKERFILE_DIRECTORY}" || exit 255
source "config_docker-image.sh"
build_docker-image_without-cache && cd .. || exit 255
done
}
# Push all images
push_all_imagess () {
echo ""
echo "-------------- PUSH ALL IMAGES -------------------------"
for DOCKERFILE_DIRECTORY in "${DOCKERFILE_DIRECTORIES[@]}"
do
echo ""
echo "-------------> Push [ ${DOCKERFILE_DIRECTORY} ] image"
cd "${DOCKERFILE_DIRECTORY}" || exit 255
source "config_docker-image.sh"
push_docker-image && cd .. || exit 255
done
}
resume_build () {
echo ""
echo "-------------- RESUME BUILD -------------------------"
for DOCKERFILE_DIRECTORY in "${DOCKERFILE_DIRECTORIES[@]}"
do
docker images | grep "${DOCKERFILE_DIRECTORY}" || (
echo "ERROR: Image [ ${DOCKERFILE_DIRECTORY} ] does not exist" && false
)
done
}
#!/usr/bin/env bash
##############################################################################################
# shellcheck disable=SC2317 # Don't warn about unreachable commands in this file
##############################################################################################
# Function to handle errors
handle_error() {
echo "----------------------------------------------------------"
echo "----> FAIL : an ERROR occurred"
exit 1
}
# Function to handle script exit
handle_exit() {
echo "----------------------------------------------------------"
echo "----> EXIT : script interrupted"
echo ""
exit 255
}
# Buil Docker image with cache (useful for debugging)
build_docker-image_with-cache () {
# docker images | grep "${DOCKER_IMAGE_NAME}"
docker build --progress plain -t "${GITLAB_URI}/${GITLAB_REPOSITORY}/${DOCKER_IMAGE_NAME}:${DOCKER_IMAGE_VERSION}" .
docker images | grep "${DOCKER_IMAGE_NAME}"
}
# Build Docker image without cache (must be used to push a new Docker image or update Docker image)
build_docker-image_without-cache () {
docker pull "${DOCKER_IMAGE_FROM}"
docker image remove "${GITLAB_URI}/${GITLAB_REPOSITORY}/${DOCKER_IMAGE_NAME}:${DOCKER_IMAGE_VERSION}" || true
docker build --no-cache --progress plain -t "${GITLAB_URI}/${GITLAB_REPOSITORY}/${DOCKER_IMAGE_NAME}:${DOCKER_IMAGE_VERSION}" .
docker images | grep "${DOCKER_IMAGE_NAME}"
}
# Remvoe Docker image
remove_docker-image () {
docker image remove "${GITLAB_URI}/${GITLAB_REPOSITORY}/${DOCKER_IMAGE_NAME}:${DOCKER_IMAGE_VERSION}" || true
}
# Login to Gitlab and push image to Gitlab container registry
push_docker-image () {
docker login "${GITLAB_URI}"
docker push "${GITLAB_URI}/${GITLAB_REPOSITORY}/${DOCKER_IMAGE_NAME}:${DOCKER_IMAGE_VERSION}"
}
\ No newline at end of file
#!/usr/bin/env bash
##############################################################################################
set -o errexit # enable exit if one of command fails
set -o pipefail # enable exit if one of pipe command fails
set -o nounset # enable exit if any of variables is not set
# set -o xtrace # all executed commands are printed to the terminal
##############################################################################################
source ../lib/docker-image.lib.sh
source ../config_gitlab-repository.sh
source config_docker-image.sh
##############################################################################################
trap handle_error ERR # Set the error handler function
trap handle_exit EXIT # Set the exit handler function
##############################################################################################
build_docker-image_with-cache
##############################################################################################
#!/usr/bin/env bash
##############################################################################################
set -o errexit # enable exit if one of command fails
set -o pipefail # enable exit if one of pipe command fails
set -o nounset # enable exit if any of variables is not set
# set -o xtrace # all executed commands are printed to the terminal
##############################################################################################
source ../lib/docker-image.lib.sh
source ../config_gitlab-repository.sh
source config_docker-image.sh
##############################################################################################
trap handle_error ERR # Set the error handler function
trap handle_exit EXIT # Set the exit handler function
##############################################################################################
build_docker-image_without-cache
##############################################################################################
\ No newline at end of file
#!/usr/bin/env bash
##############################################################################################
set -o errexit # enable exit if one of command fails
set -o pipefail # enable exit if one of pipe command fails
set -o nounset # enable exit if any of variables is not set
# set -o xtrace # all executed commands are printed to the terminal
##############################################################################################
source ../lib/docker-image.lib.sh
source ../config_gitlab-repository.sh
source config_docker-image.sh
##############################################################################################
trap handle_error ERR # Set the error handler function
trap handle_exit EXIT # Set the exit handler function
##############################################################################################
push_docker-image
##############################################################################################
#!/usr/bin/env bash
##############################################################################################
set -o errexit # enable exit if one of command fails
set -o pipefail # enable exit if one of pipe command fails
set -o nounset # enable exit if any of variables is not set
# set -o xtrace # all executed commands are printed to the terminal
##############################################################################################
source ../lib/docker-image.lib.sh
source ../config_gitlab-repository.sh
source config_docker-image.sh
##############################################################################################
trap handle_error ERR # Set the error handler function
trap handle_exit EXIT # Set the exit handler function
##############################################################################################
build_docker-image_without-cache
push_docker-image
##############################################################################################
../lib/symlink_source/50_build_image_with-cache.sh
\ No newline at end of file
../lib/symlink_source/60_build_image_without-cache.sh
\ No newline at end of file
../lib/symlink_source/70_push_image.sh
\ No newline at end of file
../lib/symlink_source/80_builld_and_push_image.sh
\ No newline at end of file
#!/usr/bin/env bash
# shellcheck disable=SC2034 # Don't warn about unused variables in this file
##############################################################################################
DOCKER_IMAGE_FROM="ubuntu:22.04"
DOCKER_IMAGE_NAME="php-8.1_composer"
DOCKER_IMAGE_VERSION="1.0.0" # must be identical to LABEL.version in Dockerfile
##############################################################################################
../lib/symlink_source/50_build_image_with-cache.sh
\ No newline at end of file
../lib/symlink_source/60_build_image_without-cache.sh
\ No newline at end of file
../lib/symlink_source/70_push_image.sh
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment