1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98
|
#!/usr/bin/env bash
set -eEo pipefail
SCRIPTPATH="$(
cd "$(dirname "$0")"
pwd -P
)"
# shellcheck source=ci/docker_commands
source "${SCRIPTPATH}/docker_commands"
# shellcheck source=ci/.colors
source "${SCRIPTPATH}/.colors"
TARGET_FLAVOR=$1
TARGET_ARCH=$2
TARGET_FILE=$3
if [ -z "${TARGET_ARCH}" ] || [ -z "${TARGET_FILE}" ]; then
echo -e "${RED}Missing required arguments. Usage: build_helper_docker TARGET_ARCH TARGET_FILE${RST}"
exit 1
fi
DOCKERFILE=${TARGET_DOCKERFILE:-"Dockerfile.${TARGET_FLAVOR}"}
HELPER_BINARY_POSTFIX=${HELPER_BINARY_POSTFIX:-}
if [[ $IMAGE_SHELL == 'pwsh' ]]; then
if [ -z "${TARGET_FLAVOR}" ] || [ -z "${PWSH_VERSION}" ] || [ -z "${PWSH_TARGET_FLAVOR_IMAGE_VERSION}" ] || [ -z "${PWSH_IMAGE_DATE}" ]; then
echo -e "${RED}Missing required arguments. When IMAGE_SHELL is 'pwsh', PWSH_VERSION, " \
"TARGET_FLAVOR, PWSH_TARGET_FLAVOR_IMAGE_VERSION, and PWSH_IMAGE_DATE must be defined${RST}"
exit 1
fi
# NOTE: To find the most recent Powershell Core tag that supports the desired Powershell Core version on the
# desired ${TARGET_FLAVOR} version, run the following command:
# ```
# export PWSH_VERSION="7.1.1"
# export PWSH_TARGET_FLAVOR_IMAGE_VERSION="3.12"
# curl -sL https://mcr.microsoft.com/v2/powershell/tags/list | \
# jq -r '.tags[]' | \
# grep "${PWSH_VERSION}-${TARGET_FLAVOR}-${PWSH_TARGET_FLAVOR_IMAGE_VERSION}" | \
# tail -n 1
# ```
BASE_IMAGE="mcr.microsoft.com/powershell:${PWSH_VERSION}-${TARGET_FLAVOR}-${PWSH_TARGET_FLAVOR_IMAGE_VERSION}-${PWSH_IMAGE_DATE}"
else
if [ -z "${TARGET_FLAVOR}" ] || [ -z "${TARGET_FLAVOR_IMAGE_VERSION}" ]; then
echo -e "${RED}Missing required arguments. TARGET_FLAVOR and TARGET_FLAVOR_IMAGE_VERSION must be defined${RST}"
exit 1
fi
BASE_IMAGE="${TARGET_FLAVOR}:${TARGET_FLAVOR_IMAGE_VERSION}"
fi
REVISION=${REVISION:-}
if [[ -z "${REVISION}" ]]; then
REVISION=$(git rev-parse --short=8 HEAD || echo "unknown")
fi
case "${TARGET_ARCH}" in
"x86_64")
platform_arch='amd64'
;;
*)
platform_arch="${TARGET_ARCH}"
;;
esac
binary_file="out/binaries/gitlab-runner-helper/gitlab-runner-helper.${TARGET_ARCH}${HELPER_BINARY_POSTFIX}"
if [ ! -f "$binary_file" ]; then
echo -e "${RED}Missing binary file. You probably need to run 'make helper-bin'.${RST}"
exit 1
fi
cp "$binary_file" dockerfiles/runner-helper/binaries/gitlab-runner-helper
chmod +x dockerfiles/runner-helper/binaries/gitlab-runner-helper
os=$(_docker version -f '{{.Server.Os}}')
platform="${os}/${platform_arch}"
echo -e "Building helper image for: ${GRN}${platform}${RST} based on ${GRN}${BASE_IMAGE}${RST}"
trap cleanup_docker_context_trap ERR SIGINT SIGTERM
setup_docker_context
# shellcheck disable=SC2154
_docker_buildx build \
--platform "${platform}" \
--no-cache \
--build-arg "BASE_IMAGE=${BASE_IMAGE}" \
--build-arg "http_proxy=${http_proxy}" \
--output "type=tar,dest=$TARGET_FILE" \
--tag "gitlab/gitlab-runner-helper:$TARGET_ARCH-$REVISION" \
--file "dockerfiles/runner-helper/${DOCKERFILE}" \
dockerfiles/runner-helper
trap - ERR SIGINT SIGTERM
cleanup_docker_context
|