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:
Balasankar "Balu" C 2022-06-15 09:51:03 +05:30
parent 703c30315e
commit 0dea43ac3b
No known key found for this signature in database
GPG key ID: B77D2E2E23735427
14 changed files with 345 additions and 226 deletions

View file

@ -9,11 +9,11 @@ docker:
- .docker
- .build_and_push
variables:
DEBIAN: bullseye
OS: "debian:bullseye"
docker-slim:
extends:
- .docker
- .build_and_push
variables:
DEBIAN: bullseye-slim
OS: "debian:bullseye-slim"

View file

@ -5,7 +5,7 @@ e2e:
extends:
- .build_and_push
variables:
DEBIAN: bullseye
OS: "debian:bullseye"
BUNDLER: '2.3'
parallel:
matrix:

View file

@ -6,7 +6,7 @@ gitaly:
stage: gitaly
parallel:
matrix:
- DEBIAN: ['bullseye']
- OS: ['debian:bullseye']
RUBY: ['2.7', '3.0']
GOLANG: ['1.16', '1.17']
GIT: ['2.33']

View file

@ -10,7 +10,7 @@ gitlab:
GRAPHICSMAGICK: '1.3.36'
parallel:
matrix:
- DEBIAN: ['bullseye']
- OS: ['debian:bullseye']
RUBY: ['2.7.patched', '3.0.patched']
GIT: ['2.36']
POSTGRESQL: ['11', '12', '13']
@ -30,7 +30,7 @@ gitlab-assets:
GRAPHICSMAGICK: '1.3.36'
parallel:
matrix:
- DEBIAN: ['bullseye']
- OS: ['debian:bullseye']
RUBY: ['2.7', '3.0']
GIT: ['2.33']
NODE: ['16.14']

View file

@ -3,13 +3,17 @@
# /scripts/custom-docker-build
#
ARG CUSTOM_IMAGE_NAME
ARG CUSTOM_IMAGE_VERSION
FROM ${CUSTOM_IMAGE_NAME}:${CUSTOM_IMAGE_VERSION}
ARG CUSTOM_BASE_IMAGE
FROM ${CUSTOM_BASE_IMAGE}
# We are setting this ARG again because it is required in install-essentials
# script. ARG defined before FROM can't be used afterwards.
# Check https://docs.docker.com/engine/reference/builder/#understand-how-arg-and-from-interact
ARG CUSTOM_BASE_IMAGE
ADD / /
RUN /scripts/install-essentials
RUN /scripts/install-essentials ${CUSTOM_BASE_IMAGE}
ENV PATH $PATH:/usr/local/go/bin
@ -128,5 +132,4 @@ ENV RUBY_VERSION=${RUBY_VERSION} \
BAZELISK_VERSION=${BAZELISK_VERSION} \
GCLOUD_VERSION=${GCLOUD_VERSION} \
KUBECTL_VERSION=${KUBECTL_VERSION} \
CUSTOM_IMAGE_NAME=${CUSTOM_IMAGE_NAME} \
CUSTOM_IMAGE_VERSION=${CUSTOM_IMAGE_VERSION}
CUSTOM_BASE_IMAGE=${CUSTOM_BASE_IMAGE}

View file

@ -3,27 +3,28 @@
set -xeuo pipefail
IFS=$'\n\t'
if [[ $(dpkg --print-architecture) == arm64 ]]; then
echo "The arm64 does not have prebuilt chrome. Using chromium instead."
function build_debian() {
if [[ $(dpkg --print-architecture) == arm64 ]]; then
echo "The arm64 does not have prebuilt chrome. Using chromium instead."
apt-get update -q -y
apt-get install -y chromium chromium-driver
apt-get autoremove -yq
apt-get clean -yqq
rm -rf /var/lib/apt/lists/*
exit 0
fi
CHROME_VERSION=${1:-99.0.4844.74-1}
CHROME_DRIVER_VERSION=${2:-99.0.4844.51}
# We hard code the URL rather than using $CI_API_V4_URL $CI_PROJECT_ID,
# because we would need to forward those variables
CHROME_DOWNLOAD_URL_BASE="https://gitlab.com/api/v4/projects/1075790/packages/generic/google-chrome-stable"
export DEBIAN_FRONTEND=noninteractive
curl -sS -L https://dl.google.com/linux/linux_signing_key.pub | apt-key add -
echo "deb http://dl.google.com/linux/chrome/deb/ stable main" > /etc/apt/sources.list.d/google.list
apt-get update -q -y
apt-get install -y chromium chromium-driver
apt-get autoremove -yq
apt-get clean -yqq
rm -rf /var/lib/apt/lists/*
exit 0
fi
CHROME_VERSION=${1:-99.0.4844.74-1}
CHROME_DRIVER_VERSION=${2:-99.0.4844.51}
# We hard code the URL rather than using $CI_API_V4_URL $CI_PROJECT_ID,
# because we would need to forward those variables
CHROME_DOWNLOAD_URL_BASE="https://gitlab.com/api/v4/projects/1075790/packages/generic/google-chrome-stable"
export DEBIAN_FRONTEND=noninteractive
curl -sS -L https://dl.google.com/linux/linux_signing_key.pub | apt-key add -
echo "deb http://dl.google.com/linux/chrome/deb/ stable main" > /etc/apt/sources.list.d/google.list
apt-get update -q -y
# Download from our package registry if we can't find the package in the apt repository
echo "Searching for $CHROME_VERSION in apt repository"
@ -55,3 +56,12 @@ apt-get autoremove -yq
apt-get clean -yqq
rm -rf /var/lib/apt/lists/*
rm -rf /etc/apt/sources.list.d/google*.list
}
BUILD_OS=${BUILD_OS:-debian}
if [[ $BUILD_OS =~ debian ]]; then
build_debian "$@"
elif [[ $BUILD_OS =~ ubi ]]; then
build_ubi "$@"
fi

View file

@ -3,10 +3,6 @@
set -xeuo pipefail
IFS=$'\n\t'
export DEBIAN_FRONTEND=noninteractive
apt-get update
# We install `git-core` as some tooling expect `/usr/bin/git`
# other tools that rely on PATH ordering will pick a one in `/usr/local`
# if present
@ -47,30 +43,48 @@ function install_debian_bullseye_deps() {
libre2-dev libevent-dev gettext rsync git-core lsb-release
}
VERSION=`cat /etc/issue | cut -d ' ' -f 3`
function prepare_debian_environment() {
export DEBIAN_FRONTEND=noninteractive
case "$VERSION" in
9)
install_debian_stretch_deps
;;
10)
install_debian_buster_deps
;;
11)
install_debian_bullseye_deps
;;
esac
apt-get update
# Set UTF-8
# http://stackoverflow.com/a/3182519/2137281
LOC=$'LC_ALL=C.UTF-8\nLANG=C.UTF-8'
echo "$LOC" > /etc/environment
cat /etc/environment
echo "C.UTF-8 UTF-8" > /etc/locale.gen
locale-gen
dpkg-reconfigure locales -f noninteractive -p critical
locale -a
VERSION=`cat /etc/issue | cut -d ' ' -f 3`
apt-get autoremove -yq
apt-get clean -yqq
rm -rf /var/lib/apt/lists/*
case "$VERSION" in
9)
install_debian_stretch_deps
;;
10)
install_debian_buster_deps
;;
11)
install_debian_bullseye_deps
;;
esac
# Set UTF-8
# http://stackoverflow.com/a/3182519/2137281
LOC=$'LC_ALL=C.UTF-8\nLANG=C.UTF-8'
echo "$LOC" > /etc/environment
cat /etc/environment
echo "C.UTF-8 UTF-8" > /etc/locale.gen
locale-gen
dpkg-reconfigure locales -f noninteractive -p critical
locale -a
apt-get autoremove -yq
apt-get clean -yqq
rm -rf /var/lib/apt/lists/*
}
function prepare_ubi_environment() {
echo "UBI preparation scripts"
}
if [[ $1 =~ debian ]]; then
export BUILD_OS=debian
prepare_debian_environment "$@"
elif [[ $1 =~ ubi ]]; then
export BUILD_OS=ubi
prepare_ubi_environment "$@"
fi

View file

@ -2,24 +2,33 @@
set -xeuo pipefail
export DEBIAN_FRONTEND=noninteractive
GCLOUD_VERSION=${1}
apt-get update
apt-get -y install \
apt-transport-https \
python3 \
gnupg
function build_debian() {
export DEBIAN_FRONTEND=noninteractive
apt-get update
apt-get -y install \
apt-transport-https \
python3 \
gnupg
curl -fsSL https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key add -
echo "deb https://packages.cloud.google.com/apt cloud-sdk main" | tee -a /etc/apt/sources.list.d/google-cloud-sdk.list
curl -fsSL https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key add -
echo "deb https://packages.cloud.google.com/apt cloud-sdk main" | tee -a /etc/apt/sources.list.d/google-cloud-sdk.list
apt-get update
apt-get update
PACKAGE_VERSION=$(apt-cache policy google-cloud-cli | awk -v dv=${GCLOUD_VERSION} '$1 ~ dv {print $1}')
PACKAGE_VERSION=$(apt-cache policy google-cloud-cli | awk -v dv=${GCLOUD_VERSION} '$1 ~ dv {print $1}')
apt-get install -y google-cloud-cli=${PACKAGE_VERSION}
apt-get -yq autoremove
apt-get clean -yqq
rm -rf /var/lib/apt/lists/*
apt-get install -y google-cloud-cli=${PACKAGE_VERSION}
apt-get -yq autoremove
apt-get clean -yqq
rm -rf /var/lib/apt/lists/*
}
BUILD_OS=${BUILD_OS:-debian}
if [[ $BUILD_OS =~ debian ]]; then
build_debian "$@"
elif [[ $BUILD_OS =~ ubi ]]; then
build_ubi "$@"
fi

View file

@ -1,42 +1,52 @@
#!/bin/bash
# This script installs noto color emoji
apt-get update
apt-get install unzip
function build_debian() {
apt-get update
apt-get install unzip
cat > ~/.fonts.conf << EOM
<?xml version='1.0'?>
<!DOCTYPE fontconfig SYSTEM 'fonts.dtd'>
<fontconfig>
<match target="scan">
<test name="family">
<string>Noto Color Emoji</string>
</test>
<edit name="scalable" mode="assign"><bool>true</bool></edit>
</match>
<match target="pattern">
<test name="prgname">
<string>chrome</string>
</test>
<edit name="family" mode="prepend_first">
<string>Noto Color Emoji</string>
</edit>
</match>
</fontconfig>
cat > ~/.fonts.conf << EOM
<?xml version='1.0'?>
<!DOCTYPE fontconfig SYSTEM 'fonts.dtd'>
<fontconfig>
<match target="scan">
<test name="family">
<string>Noto Color Emoji</string>
</test>
<edit name="scalable" mode="assign"><bool>true</bool></edit>
</match>
<match target="pattern">
<test name="prgname">
<string>chrome</string>
</test>
<edit name="family" mode="prepend_first">
<string>Noto Color Emoji</string>
</edit>
</match>
</fontconfig>
EOM
mkdir setup_fonts
cd setup_fonts
curl https://noto-website-2.storage.googleapis.com/pkgs/NotoColorEmoji-unhinted.zip -LO
unzip NotoColorEmoji-unhinted.zip
mkdir setup_fonts
cd setup_fonts
curl https://noto-website-2.storage.googleapis.com/pkgs/NotoColorEmoji-unhinted.zip -LO
unzip NotoColorEmoji-unhinted.zip
mkdir -p /usr/local/share/fonts
cp NotoColorEmoji.ttf /usr/local/share/fonts/
ls -la /usr/local/share/fonts/
chmod 644 /usr/local/share/fonts/NotoColorEmoji.ttf
mkdir -p /usr/local/share/fonts
cp NotoColorEmoji.ttf /usr/local/share/fonts/
ls -la /usr/local/share/fonts/
chmod 644 /usr/local/share/fonts/NotoColorEmoji.ttf
fc-cache -fv
fc-cache -fv
cd ..
rm -r setup_fonts
apt-get clean -yqq && rm -rf /var/lib/apt/lists/*
cd ..
rm -r setup_fonts
apt-get clean -yqq && rm -rf /var/lib/apt/lists/*
}
BUILD_OS=${BUILD_OS:-debian}
if [[ $BUILD_OS =~ debian ]]; then
build_debian "$@"
elif [[ $BUILD_OS =~ ubi ]]; then
build_ubi "$@"
fi

View file

@ -3,19 +3,30 @@ set -xeuo pipefail
IFS=$'\n\t'
POSTGRES_VERSION=${1:-12}
DEBIAN_VERSION=$(lsb_release -c -s)
export DEBIAN_FRONTEND=noninteractive
function build_debian() {
DEBIAN_VERSION=$(lsb_release -c -s)
# Uninstall the system client so that we don't have multiple versions
apt purge -y postgresql-client postgresql-client-common
export DEBIAN_FRONTEND=noninteractive
curl -sS -L https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add -
echo "deb http://apt.postgresql.org/pub/repos/apt/ ${DEBIAN_VERSION}-pgdg main" | tee /etc/apt/sources.list.d/postgresql.list
# Uninstall the system client so that we don't have multiple versions
apt purge -y postgresql-client postgresql-client-common
apt-get update
apt-get install -y postgresql-client-${POSTGRES_VERSION}
curl -sS -L https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add -
echo "deb http://apt.postgresql.org/pub/repos/apt/ ${DEBIAN_VERSION}-pgdg main" | tee /etc/apt/sources.list.d/postgresql.list
apt-get autoremove -yq
apt-get clean -yqq
rm -rf /var/lib/apt/lists/*
apt-get update
apt-get install -y postgresql-client-${POSTGRES_VERSION}
apt-get autoremove -yq
apt-get clean -yqq
rm -rf /var/lib/apt/lists/*
}
BUILD_OS=${BUILD_OS:-debian}
if [[ $BUILD_OS =~ debian ]]; then
build_debian "$@"
elif [[ $BUILD_OS =~ ubi ]]; then
build_ubi "$@"
fi

View file

@ -16,69 +16,80 @@ JEMALLOC_DOWNLOAD_URL="https://github.com/jemalloc/jemalloc/releases/download/${
BUNDLER_VERSION=${3:-""}
RUBYGEMS_VERSION=${4:-""}
# Install needed packages
apt-get update
apt-get install -y --no-install-recommends bison dpkg-dev libgdbm-dev autoconf
# Download jemalloc
mkdir -p /usr/src/jemalloc
cd /usr/src/jemalloc
curl --retry 6 -L -so jemalloc.tar.bz2 ${JEMALLOC_DOWNLOAD_URL}
echo "${JEMALLOC_DOWNLOAD_SHA256} jemalloc.tar.bz2" | sha256sum -c -
function build_debian() {
# Install needed packages
apt-get update
apt-get install -y --no-install-recommends bison dpkg-dev libgdbm-dev autoconf
# Install jemalloc
tar -xjf jemalloc.tar.bz2
rm jemalloc.tar.bz2
cd jemalloc-${JEMALLOC_VERSION}
./autogen.sh --prefix=/usr --enable-prof
make -j "$(nproc)" install
cd /tmp
# Download jemalloc
mkdir -p /usr/src/jemalloc
cd /usr/src/jemalloc
curl --retry 6 -L -so jemalloc.tar.bz2 ${JEMALLOC_DOWNLOAD_URL}
echo "${JEMALLOC_DOWNLOAD_SHA256} jemalloc.tar.bz2" | sha256sum -c -
# Download Ruby
curl -fsSL "$RUBY_DOWNLOAD_URL" -o ruby.tar.gz
echo "${RUBY_DOWNLOAD_SHA256} ruby.tar.gz" | sha256sum -c -
# Install jemalloc
tar -xjf jemalloc.tar.bz2
rm jemalloc.tar.bz2
cd jemalloc-${JEMALLOC_VERSION}
./autogen.sh --prefix=/usr --enable-prof
make -j "$(nproc)" install
cd /tmp
# Skip installing Gem docs
mkdir -p /usr/local/etc
echo 'install: --no-document' >> /usr/local/etc/gemrc
echo 'update: --no-document' >> /usr/local/etc/gemrc
# Download Ruby
curl -fsSL "$RUBY_DOWNLOAD_URL" -o ruby.tar.gz
echo "${RUBY_DOWNLOAD_SHA256} ruby.tar.gz" | sha256sum -c -
# Unpack Ruby
mkdir -p /usr/src/ruby
tar -xzf ruby.tar.gz -C /usr/src/ruby --strip-components=1
rm ruby.tar.gz
cd /usr/src/ruby
# Skip installing Gem docs
mkdir -p /usr/local/etc
echo 'install: --no-document' >> /usr/local/etc/gemrc
echo 'update: --no-document' >> /usr/local/etc/gemrc
# Apply patches
if [[ -d "/patches/ruby/$RUBY_VERSION" ]]; then
for i in "/patches/ruby/$RUBY_VERSION"/*.patch; do
echo "$i..."
patch -p1 -i "$i"
done
# Unpack Ruby
mkdir -p /usr/src/ruby
tar -xzf ruby.tar.gz -C /usr/src/ruby --strip-components=1
rm ruby.tar.gz
cd /usr/src/ruby
# Apply patches
if [[ -d "/patches/ruby/$RUBY_VERSION" ]]; then
for i in "/patches/ruby/$RUBY_VERSION"/*.patch; do
echo "$i..."
patch -p1 -i "$i"
done
fi
# Compile
# This is needed for Ruby < 3.1 on Debian bullseye: https://bugs.ruby-lang.org/issues/18409
export LDFLAGS="-Wl,--no-as-needed"
cflags="-fno-omit-frame-pointer" ./configure --enable-shared --with-jemalloc --disable-install-doc --disable-install-rdoc --disable-install-capi
make install -j $(nproc)
# Install specific version of bundler if provided
if [[ "$BUNDLER_VERSION" != "" ]]; then gem install bundler -v $BUNDLER_VERSION; fi
# Install specific version of RubyGems if provided
if [[ "$RUBYGEMS_VERSION" != "" ]]; then gem update --system $RUBYGEMS_VERSION; fi
# Cleanup
cd /
rm -rf /usr/src/ruby /usr/src/jemalloc
apt-get purge -y --auto-remove ruby
# Verify
# verify we have no "ruby" packages installed
! dpkg -l | grep -i ruby
[ "$(command -v ruby)" = '/usr/local/bin/ruby' ]
}
BUILD_OS=${BUILD_OS:-debian}
if [[ $BUILD_OS =~ debian ]]; then
build_debian "$@"
elif [[ $BUILD_OS =~ ubi ]]; then
build_ubi "$@"
fi
# Compile
# This is needed for Ruby < 3.1 on Debian bullseye: https://bugs.ruby-lang.org/issues/18409
export LDFLAGS="-Wl,--no-as-needed"
cflags="-fno-omit-frame-pointer" ./configure --enable-shared --with-jemalloc --disable-install-doc --disable-install-rdoc --disable-install-capi
make install -j $(nproc)
# Install specific version of bundler if provided
if [[ "$BUNDLER_VERSION" != "" ]]; then gem install bundler -v $BUNDLER_VERSION; fi
# Install specific version of RubyGems if provided
if [[ "$RUBYGEMS_VERSION" != "" ]]; then gem update --system $RUBYGEMS_VERSION; fi
# Cleanup
cd /
rm -rf /usr/src/ruby /usr/src/jemalloc
apt-get purge -y --auto-remove ruby
# Verify
# verify we have no "ruby" packages installed
! dpkg -l | grep -i ruby
[ "$(command -v ruby)" = '/usr/local/bin/ruby' ]
# rough smoke test
ruby --version
gem --version

View file

@ -3,55 +3,66 @@
set -xeuo pipefail
IFS=$'\n\t'
export DEBIAN_FRONTEND=noninteractive
function build_debian() {
export DEBIAN_FRONTEND=noninteractive
# echo "deb http://deb.debian.org/debian testing main" | tee -a /etc/apt/sources.list.d/testing.list
# Install packages
apt-get update
apt-get install -yq --no-install-recommends \
make gcc g++ locales \
rsync git-core \
ed file curl gnupg2 \
unzip \
python3 python3-pip python3-crcmod python-minimal \
patch
# echo "deb http://deb.debian.org/debian testing main" | tee -a /etc/apt/sources.list.d/testing.list
# Install packages
apt-get update
apt-get install -yq --no-install-recommends \
make gcc g++ locales \
rsync git-core \
ed file curl gnupg2 \
unzip \
python3 python3-pip python3-crcmod python-minimal \
patch
# Install Imagemagick for cropping the pictures on the team page
apt-get install -yq --no-install-recommends imagemagick
# Install Imagemagick for cropping the pictures on the team page
apt-get install -yq --no-install-recommends imagemagick
# Install node & yarn
NODE_INSTALL_VERSION=16.14.2
YARN_INSTALL_VERSION=1.22.10
/scripts/install-node $NODE_INSTALL_VERSION $YARN_INSTALL_VERSION && node --version && yarn --version
# Install node & yarn
NODE_INSTALL_VERSION=16.14.2
YARN_INSTALL_VERSION=1.22.10
/scripts/install-node $NODE_INSTALL_VERSION $YARN_INSTALL_VERSION && node --version && yarn --version
# Install yamllint
# We need version 1.25.0+: https://github.com/adrienverge/yamllint/blob/master/CHANGELOG.rst
YAMLLINT_VERSION=1.25.0
# Install yamllint
# We need version 1.25.0+: https://github.com/adrienverge/yamllint/blob/master/CHANGELOG.rst
YAMLLINT_VERSION=1.25.0
# Temporarily pin pyyaml and pathspec to reduce compatibility with packages from Debian bullseye (testing)
pip3 install yamllint==${YAMLLINT_VERSION} pyyaml==5.4.1 pathspec==0.8.1
# Temporarily pin pyyaml and pathspec to reduce compatibility with packages from Debian bullseye (testing)
pip3 install yamllint==${YAMLLINT_VERSION} pyyaml==5.4.1 pathspec==0.8.1
# Install gitlab-runner
curl -O -J -L https://gitlab-ci-multi-runner-downloads.s3.amazonaws.com/latest/binaries/gitlab-ci-multi-runner-linux-amd64
mv gitlab-ci-multi-runner-linux-amd64 /usr/bin/gitlab-runner-helper
chmod +x /usr/bin/gitlab-runner-helper
# Install gitlab-runner
curl -O -J -L https://gitlab-ci-multi-runner-downloads.s3.amazonaws.com/latest/binaries/gitlab-ci-multi-runner-linux-amd64
mv gitlab-ci-multi-runner-linux-amd64 /usr/bin/gitlab-runner-helper
chmod +x /usr/bin/gitlab-runner-helper
# Patch gsutil to support gzip compression with rsync command:
# https://github.com/GoogleCloudPlatform/gsutil/pull/1430
if [[ -d "/patches/gsutil" ]]; then
for i in /patches/gsutil/*.patch; do
echo "$i..."
patch -d /usr/lib/google-cloud-sdk/platform/gsutil -p1 -i "$i"
done
# Patch gsutil to support gzip compression with rsync command:
# https://github.com/GoogleCloudPlatform/gsutil/pull/1430
if [[ -d "/patches/gsutil" ]]; then
for i in /patches/gsutil/*.patch; do
echo "$i..."
patch -d /usr/lib/google-cloud-sdk/platform/gsutil -p1 -i "$i"
done
fi
# Set UTF-8
echo "C.UTF-8 UTF-8" > /etc/locale.gen
locale-gen
update-locale LANG=C.UTF-8 LC_CTYPE=C.UTF-8 LC_ALL=C.UTF-8
locale -a
# Clean up
apt-get autoremove -yq
apt-get clean -yqq
rm -rf /var/lib/apt/lists/*
}
BUILD_OS=${BUILD_OS:-debian}
if [[ $BUILD_OS =~ debian ]]; then
build_debian "$@"
elif [[ $BUILD_OS =~ ubi ]]; then
build_ubi "$@"
fi
# Set UTF-8
echo "C.UTF-8 UTF-8" > /etc/locale.gen
locale-gen
update-locale LANG=C.UTF-8 LC_CTYPE=C.UTF-8 LC_ALL=C.UTF-8
locale -a
# Clean up
apt-get autoremove -yq
apt-get clean -yqq
rm -rf /var/lib/apt/lists/*

View file

@ -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() {

View file

@ -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