Merge branch 'allow-to-use-path-for-custom' into 'master'

Allow to prefix deployed images into nested

See merge request gitlab-org/gitlab-build-images!527
This commit is contained in:
Rémy Coutable 2022-05-02 14:10:07 +00:00
commit 65292a9a9c
3 changed files with 35 additions and 16 deletions

View file

@ -260,7 +260,7 @@ function parse_arguments() {
CUSTOM_IMAGE_NAME=debian CUSTOM_IMAGE_NAME=debian
CUSTOM_IMAGE_VERSION=buster CUSTOM_IMAGE_VERSION=buster
for tool in "${TOOLS[@]}"; do for tool in "${PATH_TOOLS[@]}" "${TAG_TOOLS[@]}"; do
if [ -n "${!tool}" ]; then if [ -n "${!tool}" ]; then
version="${!tool}" version="${!tool}"
case "$tool" in case "$tool" in
@ -302,15 +302,16 @@ function generate_command() {
} }
function build_custom_if_needed() { function build_custom_if_needed() {
build_image_name=$(get_image_name) build_image_path=$(get_image_path)
echo "Building image $build_image_name" build_image_tag=$(get_image_tag)
full_image_name="$CI_REGISTRY_IMAGE:$build_image_name" echo "Building image $build_image_tag"
full_image_name="$build_image_path:$build_image_tag"
docker_command=$(generate_command $@ --build-arg BUILDKIT_INLINE_CACHE=1 --cache-from="$full_image_name" -t "$full_image_name") docker_command=$(generate_command $@ --build-arg BUILDKIT_INLINE_CACHE=1 --cache-from="$full_image_name" -t "$full_image_name")
echo "Docker command:" echo "Docker command:"
printf "\t%s" "$docker_command" printf "\t%s" "$docker_command"
eval $docker_command eval $docker_command
printf "\n\nSUCCESS - Successfully built:\n\t%s" "$build_image_name" printf "\n\nSUCCESS - Successfully built:\n\t%s" "$build_image_tag"
} }
build_custom_if_needed $@ build_custom_if_needed $@

View file

@ -6,9 +6,10 @@ SCRIPT_DIR="$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
source "$SCRIPT_DIR/lib/custom-docker.sh" source "$SCRIPT_DIR/lib/custom-docker.sh"
function custom_push() { function custom_push() {
build_image_name=$(get_image_name) build_image_path=$(get_image_path)
echo "Pushing image $build_image_name" build_image_tag=$(get_image_tag)
full_image_name="$CI_REGISTRY_IMAGE:$build_image_name" echo "Pushing image $build_image_path:$build_image_tag"
full_image_name="$build_image_path:$build_image_tag"
docker push "$full_image_name" docker push "$full_image_name"

View file

@ -1,12 +1,29 @@
TOOLS=(DEBIAN RUBY BUNDLER GOLANG GIT LFS CHROME NODE YARN POSTGRESQL GRAPHICSMAGICK PGBOUNCER BAZELISK DOCKER GCLOUD KUBECTL) PATH_TOOLS=()
TAG_TOOLS=(DEBIAN RUBY BUNDLER GOLANG GIT LFS CHROME NODE YARN POSTGRESQL GRAPHICSMAGICK PGBOUNCER BAZELISK DOCKER GCLOUD KUBECTL)
function get_image_name(){ function get_image_path() {
local IMAGE_NAME local path
IMAGE_NAME="" path=""
for tool in "${TOOLS[@]}"; do for tool in "${PATH_TOOLS[@]}"; do
if [ -n "${!tool}" ]; then if [[ -n "${!tool}" ]]; then
IMAGE_NAME="${IMAGE_NAME}-${tool,,}-${!tool}" path="${path}-${tool,,}-${!tool}"
fi fi
done done
echo "${IMAGE_NAME:1}"
if [[ -n "$path" ]]; then
echo "$CI_REGISTRY_IMAGE/${path:1}"
else
echo "$CI_REGISTRY_IMAGE"
fi
}
function get_image_tag() {
local tag
tag=""
for tool in "${TAG_TOOLS[@]}"; do
if [[ -n "${!tool}" ]]; then
tag="${tag}-${tool,,}-${!tool}"
fi
done
echo "${tag:1}"
} }