mirror of
https://ops.gitlab.net/gitlab-org/gitlab-build-images.git
synced 2025-12-10 02:22:57 +01:00
Support using OS other than Debian as base for custom images
Signed-off-by: Balasankar "Balu" C <balasankar@gitlab.com>
This commit is contained in:
parent
703c30315e
commit
0dea43ac3b
14 changed files with 345 additions and 226 deletions
|
|
@ -5,6 +5,14 @@ IFS=$'\n\t'
|
|||
SCRIPT_DIR="$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
|
||||
source "$SCRIPT_DIR/custom-docker.sh"
|
||||
|
||||
function get_base_image_reference() {
|
||||
if [[ $1 =~ ^debian ]]; then
|
||||
echo "$CUSTOM_DOCKER_ARCH/$1"
|
||||
elif [[ $1 =~ ^ubi:8 ]]; then
|
||||
echo "registry.access.redhat.com/ubi8/$1"
|
||||
fi
|
||||
}
|
||||
|
||||
function print_golang_args() {
|
||||
declare -A GOLANG_DOWNLOAD_SHA256
|
||||
|
||||
|
|
@ -321,15 +329,12 @@ function parse_arguments() {
|
|||
*) echo "unknown architecture $(arch)"; exit 1;;
|
||||
esac
|
||||
|
||||
CUSTOM_IMAGE_NAME=debian
|
||||
CUSTOM_IMAGE_VERSION=buster
|
||||
|
||||
for tool in "${PATH_TOOLS[@]}" "${TAG_TOOLS[@]}"; do
|
||||
if [ -n "${!tool}" ]; then
|
||||
version="${!tool}"
|
||||
case "$tool" in
|
||||
ARCH) CUSTOM_DOCKER_ARCH=$version ;;
|
||||
DEBIAN) CUSTOM_IMAGE_VERSION=$version ;;
|
||||
OS) CUSTOM_BASE_IMAGE=get_base_image_reference $version ;;
|
||||
RUBY) print_ruby_args $version ;;
|
||||
BUNDLER) print_bundler_args $version ;;
|
||||
RUBYGEMS) print_rubygems_args $version ;;
|
||||
|
|
@ -353,10 +358,11 @@ function parse_arguments() {
|
|||
fi
|
||||
done
|
||||
|
||||
CUSTOM_IMAGE_NAME=$CUSTOM_DOCKER_ARCH/$CUSTOM_IMAGE_NAME # ex. https://hub.docker.com/r/amd64/debian/
|
||||
if [ -z "$CUSTOM_BASE_IMAGE" ]; then
|
||||
CUSTOM_BASE_IMAGE="$CUSTOM_DOCKER_ARCH/debian:buster"
|
||||
fi
|
||||
|
||||
printf -- "--build-arg CUSTOM_IMAGE_NAME=%s " "$CUSTOM_IMAGE_NAME"
|
||||
printf -- "--build-arg CUSTOM_IMAGE_VERSION=%s " "$CUSTOM_IMAGE_VERSION"
|
||||
printf -- "--build-arg CUSTOM_BASE_IMAGE=%s " "$CUSTOM_BASE_IMAGE"
|
||||
}
|
||||
|
||||
function generate_command() {
|
||||
|
|
|
|||
|
|
@ -1,12 +1,35 @@
|
|||
PATH_TOOLS=(DEBIAN RUBY GOLANG NODE POSTGRESQL)
|
||||
# Note: Check out https://wiki.bash-hackers.org/syntax/pe for documentation on
|
||||
# various variable operations used in this script.
|
||||
|
||||
PATH_TOOLS=(OS RUBY GOLANG NODE POSTGRESQL)
|
||||
TAG_TOOLS=(BUNDLER RUBYGEMS GIT LFS CHROME YARN GRAPHICSMAGICK PGBOUNCER BAZELISK DOCKER BUILDX GCLOUD KUBECTL HELM)
|
||||
|
||||
# Generate the docker image path using the components that were specified via
|
||||
# variables.
|
||||
# For example, consider a CI job which specifies the following variables:
|
||||
# OS: debian:bullseye
|
||||
# RUBY: 2.7
|
||||
# GOLANG: 1.16
|
||||
# GIT: 2.33
|
||||
# PGBOUNCER: 1.14
|
||||
# POSTGRESQL: 11
|
||||
# With the above variables, this function will return
|
||||
# `debian-bullseye-ruby-2.7-golang-1.16-postgresql-11`
|
||||
function get_image_path() {
|
||||
local path
|
||||
path=""
|
||||
for tool in "${PATH_TOOLS[@]}"; do
|
||||
if [[ -n "${!tool}" ]]; then
|
||||
path="${path}-${tool,,}-${!tool}"
|
||||
if [[ "${tool}" == "OS" ]]; then
|
||||
# The OS variable's value is following <distro>:<version>
|
||||
# format. We split that string into individual components.
|
||||
distro=${!tool%:*}
|
||||
version=${!tool#*:}
|
||||
path="${path}-${distro}-${version}"
|
||||
else
|
||||
# Convert the tool name into lowercase using `,,` operator
|
||||
path="${path}-${tool,,}-${!tool}"
|
||||
fi
|
||||
fi
|
||||
done
|
||||
|
||||
|
|
@ -17,15 +40,26 @@ function get_image_path() {
|
|||
fi
|
||||
}
|
||||
|
||||
# Generate the image tag using the components that were specified via variables.
|
||||
# For example, consider a CI job which specifies the following variables:
|
||||
# OS: debian:bullseye
|
||||
# RUBY: 2.7
|
||||
# GOLANG: 1.16
|
||||
# GIT: 2.33
|
||||
# PGBOUNCER: 1.14
|
||||
# POSTGRESQL: 11
|
||||
# For that job, this function will return
|
||||
# `git-2.33-pgbouncer-1.14`
|
||||
function get_image_tag() {
|
||||
local tag
|
||||
tag=""
|
||||
for tool in "${TAG_TOOLS[@]}"; do
|
||||
if [[ -n "${!tool}" ]]; then
|
||||
# Convert the tool name into lowercase using `,,` operator
|
||||
tag="${tag}-${tool,,}-${!tool}"
|
||||
fi
|
||||
done
|
||||
|
||||
|
||||
if [[ -n "$tag" ]]; then
|
||||
echo "${tag:1}"
|
||||
else
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue