mirror of
https://github.com/certbot/certbot.git
synced 2026-05-28 04:34:11 -04:00
refactor docker script arg parsing and fix merge bugs
This commit is contained in:
parent
a8c85ab0f8
commit
4d7ed3f692
5 changed files with 32 additions and 62 deletions
|
|
@ -15,19 +15,7 @@ set -euxo pipefail
|
|||
|
||||
source "$(realpath $(dirname ${BASH_SOURCE[0]}))/lib/common"
|
||||
|
||||
#used by docker buildx bake, so mark export
|
||||
export TAG_VER="$1"
|
||||
if [ -z "$TAG_VER" ]; then
|
||||
echo "We cannot tag Docker images with an empty string!" >&2
|
||||
exit 1
|
||||
fi
|
||||
ARCH_LIST="$2"
|
||||
if [ -z "$ARCH_LIST" ]; then
|
||||
echo "Architectures must be specified!" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
export REGISTRY_SPEC="${DOCKER_HUB_ORG}/"
|
||||
ParseArgs $@
|
||||
|
||||
#jump to root, matching popd handed by Cleanup on EXIT via trap
|
||||
pushd "${REPO_ROOT}"
|
||||
|
|
@ -36,6 +24,7 @@ pushd "${REPO_ROOT}"
|
|||
trap Cleanup EXIT
|
||||
# Create the builder
|
||||
CreateBuilder
|
||||
InstallMultiarchSupport
|
||||
|
||||
|
||||
BuildAndCacheByArch() {
|
||||
|
|
@ -43,7 +32,7 @@ BuildAndCacheByArch() {
|
|||
docker buildx build --target certbot --builder certbot_builder \
|
||||
--platform $(arch2platform $TAG_ARCH) \
|
||||
-f "${WORK_DIR}/Dockerfile" \
|
||||
-t "${REGISTRY_SPEC}certbot:${TAG_ARCH}-${TAG_VER}" \
|
||||
-t "${DOCKER_HUB_ORG}/certbot:${TAG_ARCH}-${TAG_VER}" \
|
||||
--load \
|
||||
.
|
||||
for plugin in "${CERTBOT_PLUGINS[@]}"; do
|
||||
|
|
@ -51,7 +40,7 @@ BuildAndCacheByArch() {
|
|||
--platform $(arch2platform $TAG_ARCH) \
|
||||
--build-context plugin-src="${REPO_ROOT}/certbot-${plugin}" \
|
||||
-f "${WORK_DIR}/Dockerfile" \
|
||||
-t "${REGISTRY_SPEC}${plugin}:${TAG_ARCH}-${TAG_VER}" \
|
||||
-t "${DOCKER_HUB_ORG}/${plugin}:${TAG_ARCH}-${TAG_VER}" \
|
||||
--load \
|
||||
.
|
||||
done
|
||||
|
|
@ -62,11 +51,6 @@ BuildAndCacheByArch() {
|
|||
# of such a build. See the branch buildx-bake and
|
||||
# https://github.com/certbot/certbot/issues/9587.
|
||||
|
||||
# split arch list into an array for per-arch image building and saving
|
||||
IFS_OLD="$IFS"
|
||||
IFS=","
|
||||
read -ra REQUESTED_ARCH_ARRAY <<< $(InterpretArchRequest "$ARCH_LIST")
|
||||
IFS="$IFS_OLD"
|
||||
for ARCH in "${REQUESTED_ARCH_ARRAY[@]}"; do
|
||||
BuildAndCacheByArch $ARCH
|
||||
done
|
||||
|
|
|
|||
|
|
@ -17,12 +17,7 @@ set -euxo pipefail
|
|||
|
||||
source "$(realpath $(dirname ${BASH_SOURCE[0]}))/lib/common"
|
||||
|
||||
TAG_VER="$1"
|
||||
if [ -z "$TAG_VER" ]; then
|
||||
echo "We cannot tag Docker images with an empty string!" >&2
|
||||
exit 1
|
||||
fi
|
||||
REQUESTED_ARCH_LIST=$(InterpretArchRequest "$2")
|
||||
ParseArgs $@
|
||||
|
||||
#jump to root, matching popd handed by Cleanup on EXIT via trap
|
||||
pushd "${REPO_ROOT}"
|
||||
|
|
@ -35,21 +30,18 @@ REGISTRY_SPEC="${DOCKER_HUB_ORG}/"
|
|||
DeployImage() {
|
||||
IMAGE_NAME=$1
|
||||
TAG_ARCH=$2
|
||||
TAG_VER=$3
|
||||
docker push "${REGISTRY_SPEC}${IMAGE_NAME}:${TAG_ARCH}-${TAG_VER}"
|
||||
if [[ "${TAG_VER}" =~ ^v([2-9]|[1-9][0-9]+)\.[0-9]+\.[0-9]+$ ]]; then
|
||||
docker tag "${REGISTRY_SPEC}${IMAGE_NAME}:${TAG_ARCH}-${TAG_VER}" "${REGISTRY_SPEC}${IMAGE_NAME}:${TAG_ARCH}-latest"
|
||||
docker push "${REGISTRY_SPEC}${IMAGE_NAME}:${TAG_ARCH}-latest"
|
||||
fi
|
||||
}
|
||||
|
||||
IFS_OLD="$IFS"
|
||||
IFS=","
|
||||
read -ra REQUESTED_ARCH_ARRAY <<< $(InterpretArchRequest "$2")
|
||||
IFS="$IFS_OLD"
|
||||
|
||||
for TAG_ARCH in "${REQUESTED_ARCH_ARRAY[@]}"; do
|
||||
DeployImage certbot $TAG_ARCH $TAG_VER
|
||||
DeployImage certbot $TAG_ARCH
|
||||
for PLUGIN in "${CERTBOT_PLUGINS[@]}"; do
|
||||
DeployImage $PLUGIN $TAG_ARCH $TAG_VER
|
||||
DeployImage $PLUGIN $TAG_ARCH
|
||||
done
|
||||
done
|
||||
|
||||
|
|
|
|||
|
|
@ -18,12 +18,7 @@ set -euxo pipefail
|
|||
|
||||
source "$(realpath $(dirname ${BASH_SOURCE[0]}))/lib/common"
|
||||
|
||||
TAG_VER="$1"
|
||||
if [ -z "$TAG_VER" ]; then
|
||||
echo "We cannot tag Docker images with an empty string!" >&2
|
||||
exit 1
|
||||
fi
|
||||
REQUESTED_ARCH_LIST=$(InterpretArchRequest "$2")
|
||||
ParseArgs $@
|
||||
|
||||
#jump to root, matching popd handed by Cleanup on EXIT via trap
|
||||
pushd "${REPO_ROOT}"
|
||||
|
|
@ -35,11 +30,6 @@ REGISTRY_SPEC="${DOCKER_HUB_ORG}/"
|
|||
|
||||
DeployManifest() {
|
||||
IMAGE_NAME=$1
|
||||
local IFS=","
|
||||
read -ra REQUESTED_ARCH_ARRAY <<< ${REQUESTED_ARCH_LIST}
|
||||
TAG_VER=$3
|
||||
|
||||
IFS=" "
|
||||
|
||||
SRC_IMAGES=""
|
||||
for TAG_ARCH in "${REQUESTED_ARCH_ARRAY[@]}"; do
|
||||
|
|
@ -52,9 +42,9 @@ DeployManifest() {
|
|||
fi
|
||||
}
|
||||
|
||||
DeployManifest certbot ${REQUESTED_ARCH_LIST} $TAG_VER
|
||||
DeployManifest certbot
|
||||
for PLUGIN in "${CERTBOT_PLUGINS[@]}"; do
|
||||
DeployManifest $PLUGIN ${REQUESTED_ARCH_LIST} $TAG_VER
|
||||
DeployManifest $PLUGIN
|
||||
done
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -32,8 +32,6 @@ export CERTBOT_PLUGINS=(
|
|||
export WORK_DIR="$(realpath $(dirname ${BASH_SOURCE[0]})/..)"
|
||||
# REPO_ROOT is two levels above that
|
||||
export REPO_ROOT="$(realpath ${WORK_DIR}/../..)"
|
||||
# location where docker cache should be created (may be anywhere accessble on the host filesystem)
|
||||
export DOCKER_CACHE="${REPO_ROOT}/.docker_cache"
|
||||
|
||||
# Converts input architecture identifier to the platform specification
|
||||
# understood by `docker build buildx --platform <specification>`.
|
||||
|
|
@ -82,6 +80,24 @@ InterpretArchRequest() {
|
|||
echo "$USER_INPUT"
|
||||
}
|
||||
|
||||
ParseArgs() {
|
||||
|
||||
export TAG_VER="$1"
|
||||
if [ -z "$TAG_VER" ]; then
|
||||
echo "We cannot tag Docker images with an empty string!" >&2
|
||||
exit 1
|
||||
fi
|
||||
ARCH_LIST="$2"
|
||||
if [ -z "$ARCH_LIST" ]; then
|
||||
echo "Architectures must be specified!" >&2
|
||||
exit 1
|
||||
fi
|
||||
# split arch list into an array for per-arch image building and saving
|
||||
local IFS=","
|
||||
read -ra REQUESTED_ARCH_ARRAY <<< $(InterpretArchRequest "$ARCH_LIST")
|
||||
export REQUESTED_ARCH_ARRAY
|
||||
}
|
||||
|
||||
|
||||
# Function for use with trap in the primary scripts to remove the
|
||||
# docker builder and restore the original directory
|
||||
|
|
@ -90,6 +106,7 @@ Cleanup() {
|
|||
popd
|
||||
}
|
||||
|
||||
# add binfmt tools to the docker environment, with integration into the new builder instance
|
||||
InstallMultiarchSupport() {
|
||||
docker run --privileged --rm tonistiigi/binfmt --install all
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,20 +14,7 @@ set -euxo pipefail
|
|||
|
||||
source "$(realpath $(dirname ${BASH_SOURCE[0]}))/lib/common"
|
||||
|
||||
TAG_VER="$1"
|
||||
if [ -z "$TAG_VER" ]; then
|
||||
echo "We cannot tag Docker images with an empty string!" >&2
|
||||
exit 1
|
||||
fi
|
||||
if [ -z "$2" ]; then
|
||||
echo "Architectures must be specified!" >&2
|
||||
exit 1
|
||||
fi
|
||||
IFS_OLD="$IFS"
|
||||
IFS=","
|
||||
read -ra REQUESTED_ARCH_ARRAY <<< $(InterpretArchRequest "$2")
|
||||
IFS="$IFS_OLD"
|
||||
|
||||
ParseArgs $@
|
||||
|
||||
#jump to root, matching popd handed by Cleanup on EXIT via trap
|
||||
pushd "${REPO_ROOT}"
|
||||
|
|
|
|||
Loading…
Reference in a new issue