mirror of
https://ops.gitlab.net/gitlab-org/gitlab-build-images.git
synced 2025-12-09 10:02:56 +01:00
Welcome to the matrix
This refactors our custom image building to utilize GitLab parallel jobs with a matrix. This makes it easier to parse what kind of matrix we are going to build in our docker images. Furthermore instead of splitting the image name, we can simply pull the versions of the tools from the environment variables. The ultimative reason: Dogfooding
This commit is contained in:
parent
32d1908296
commit
a9cf88c469
11 changed files with 325 additions and 292 deletions
|
|
@ -1,9 +1,9 @@
|
|||
#!/bin/bash
|
||||
|
||||
set -e
|
||||
IFS=$'\n\t'
|
||||
|
||||
source scripts/build-helpers.sh
|
||||
SCRIPT_DIR="$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
|
||||
source "$SCRIPT_DIR/lib/custom-docker.sh"
|
||||
|
||||
function print_golang_args() {
|
||||
case "$1" in
|
||||
|
|
@ -245,23 +245,25 @@ function parse_arguments() {
|
|||
CUSTOM_IMAGE_NAME=debian
|
||||
CUSTOM_IMAGE_VERSION=buster
|
||||
|
||||
while read image; do
|
||||
read version
|
||||
case "$image" in
|
||||
ruby) print_ruby_args $version ;;
|
||||
golang) print_golang_args $version ;;
|
||||
chrome) print_chrome_args $version ;;
|
||||
docker) print_docker_args $version ;;
|
||||
git) print_git_args $version ;;
|
||||
lfs) print_lfs_args $version ;;
|
||||
node) print_node_args $version ;;
|
||||
yarn) print_yarn_args $version ;;
|
||||
postgresql) print_postgres_args $version ;;
|
||||
graphicsmagick) print_graphicsmagick_args $version ;;
|
||||
pgbouncer) print_pgbouncer_args $version ;;
|
||||
bazelisk) print_bazelisk_args $version ;;
|
||||
*) exit 1;;
|
||||
esac
|
||||
for tool in "${TOOLS[@]}"; do
|
||||
if [ -n "${!tool}" ]; then
|
||||
version="${!tool}"
|
||||
case "$tool" in
|
||||
RUBY) print_ruby_args $version ;;
|
||||
GOLANG) print_golang_args $version ;;
|
||||
CHROME) print_chrome_args $version ;;
|
||||
DOCKER) print_docker_args $version ;;
|
||||
GIT) print_git_args $version ;;
|
||||
LFS) print_lfs_args $version ;;
|
||||
NODE) print_node_args $version ;;
|
||||
YARN) print_yarn_args $version ;;
|
||||
POSTGRESQL) print_postgres_args $version ;;
|
||||
GRAPHICSMAGICK) print_graphicsmagick_args $version ;;
|
||||
PGBOUNCER) print_pgbouncer_args $version ;;
|
||||
BAZELISK) print_bazelisk_args $version ;;
|
||||
*) echo "unknown tool $tool"; exit 1;;
|
||||
esac
|
||||
fi
|
||||
done
|
||||
|
||||
printf -- "--build-arg CUSTOM_IMAGE_NAME=%s " "$CUSTOM_IMAGE_NAME"
|
||||
|
|
@ -269,10 +271,8 @@ function parse_arguments() {
|
|||
}
|
||||
|
||||
function generate_command() {
|
||||
build_image_name=$1; shift;
|
||||
|
||||
printf -- "docker build "
|
||||
echo $build_image_name | tr '-' '\n' | parse_arguments
|
||||
parse_arguments
|
||||
|
||||
for i in "$@"
|
||||
do
|
||||
|
|
@ -282,14 +282,17 @@ function generate_command() {
|
|||
}
|
||||
|
||||
function build_custom_if_needed() {
|
||||
build_image_name=$1
|
||||
build_image_name=$(get_image_name)
|
||||
echo "Building image $build_image_name"
|
||||
full_image_name="$CI_REGISTRY_IMAGE:$build_image_name"
|
||||
|
||||
# This re-uses and builds an existing image if needed
|
||||
docker pull --quiet "$full_image" || true
|
||||
docker_command=$(generate_command $@ --cache-from="$full_image_name" )
|
||||
echo "Building $build_image_name with $docker_command"
|
||||
echo "Docker command:"
|
||||
printf "\t%s" "$docker_command"
|
||||
eval $docker_command
|
||||
printf "\n\nSUCCESS - Successfully built:\n\t%s" "$build_image_name"
|
||||
}
|
||||
|
||||
build_custom_if_needed $@
|
||||
|
|
|
|||
18
scripts/custom-docker-push
Executable file
18
scripts/custom-docker-push
Executable file
|
|
@ -0,0 +1,18 @@
|
|||
#!/bin/bash
|
||||
set -e
|
||||
IFS=$'\n\t'
|
||||
|
||||
SCRIPT_DIR="$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
|
||||
source "$SCRIPT_DIR/lib/custom-docker.sh"
|
||||
|
||||
function custom_push() {
|
||||
build_image_name=$(get_image_name)
|
||||
echo "Pushing image $build_image_name"
|
||||
full_image_name="$CI_REGISTRY_IMAGE:$build_image_name"
|
||||
|
||||
docker push "$full_image_name"
|
||||
|
||||
printf "\n\nSUCCESS - Successfully pushed:\n\t%s" "$build_image_name"
|
||||
}
|
||||
|
||||
custom_push
|
||||
12
scripts/lib/custom-docker.sh
Normal file
12
scripts/lib/custom-docker.sh
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
TOOLS=(RUBY GOLANG GIT LFS CHROME NODE YARN POSTGRESQL GRAPHICSMAGICK PGBOUNCER BAZELISK)
|
||||
|
||||
function get_image_name(){
|
||||
local IMAGE_NAME
|
||||
IMAGE_NAME=""
|
||||
for tool in "${TOOLS[@]}"; do
|
||||
if [ -n "${!tool}" ]; then
|
||||
IMAGE_NAME="${IMAGE_NAME}-${tool,,}-${!tool}"
|
||||
fi
|
||||
done
|
||||
echo "${IMAGE_NAME:1}"
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue