certbot/tools/docker/lib/common
Yaroslav Halchenko 86f76cd3df
Add codespell support (CI to check, not to fix) and make it fix a few typos (#10297)
Another token of gratitude for a super useful tool and service.

More about codespell: https://github.com/codespell-project/codespell .

I personally introduced it to dozens if not hundreds of projects already
and so far only positive feedback.

CI workflow has 'permissions' set only to 'read' so also should be safe.

---------

Signed-off-by: Yaroslav O. Halchenko <debian@onerussian.com>
2025-06-24 13:14:31 +09:00

116 lines
3.5 KiB
Bash

#!/bin/bash
set -euxo pipefail
# Current supported architectures
export ALL_TARGET_ARCH=(amd64 arm32v6 arm64v8)
# Name of the Certbot Docker organizaation on GitHub. After creating
# repositories with the same names (e.g. "certbot", "dns-dnsmadeeasy", etc.)
# using a different account on Docker Hub, you can change this value to have
# the scripts modify those Docker repositories rather than the repositories for
# the official Certbot Docker images.
export DOCKER_HUB_ORG="certbot"
# List of Certbot plugins
export CERTBOT_PLUGINS=(
"dns-dnsmadeeasy"
"dns-dnsimple"
"dns-ovh"
"dns-cloudflare"
"dns-digitalocean"
"dns-google"
"dns-luadns"
"dns-nsone"
"dns-rfc2136"
"dns-route53"
"dns-gehirn"
"dns-linode"
"dns-sakuracloud"
)
# WORK_DIR is two levels above this file
export WORK_DIR="$(realpath "$(dirname "${BASH_SOURCE[0]}")/..")"
# REPO_ROOT is two levels above that
export REPO_ROOT="$(realpath "${WORK_DIR}/../..")"
# Converts input architecture identifier to the platform specification
# understood by `docker build buildx --platform <specification>`.
# Usage: arch2platform [arm64|arm32v6|arm64v8]
# If the input is not recognized, an error is returned
arch2platform() {
REQUESTED_ARCH="${1}"
case $REQUESTED_ARCH in
amd64)
echo "linux/amd64"
;;
arm32v6)
echo "linux/arm/v6"
;;
arm64v8)
echo "linux/arm64"
;;
*)
return 1
;;
esac
}
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
local IFS=","
# Handle the special value "all"
if [[ "${ARCH_LIST}" == "all" ]]; then
# Replace with comma separated
ARCH_LIST="${ALL_TARGET_ARCH[*]}"
fi
# Turn arch list into an array
read -ra REQUESTED_ARCH_ARRAY <<< "$ARCH_LIST"
# And make sure all individual elements are in the list of all known architectures
for REQUESTED_ARCH in "${REQUESTED_ARCH_ARRAY[@]}"; do
local IFS=" "
if [[ ! " ${ALL_TARGET_ARCH[*]} " =~ " ${REQUESTED_ARCH} " ]]; then
echo "unknown architecture identifier: ${REQUESTED_ARCH}" >&2
exit 1
fi
done
export REQUESTED_ARCH_ARRAY
}
# Function for use with trap in the primary scripts to remove the
# docker builder and restore the original directory
Cleanup() {
docker buildx rm certbot_builder || true
popd
}
# add binfmt tools to the docker environment, with integration into the new builder instance
InstallMultiarchSupport() {
docker run --privileged --rm tonistiigi/binfmt --install all
}
# Function to create a docker builder using the buildkit docker-container
# driver
CreateBuilder() {
# just in case the env is not perfectly clean, remove any old instance of the builder
docker buildx rm certbot_builder || true
# create the builder instance
#
# BUILDKIT_STEP_LOG_MAX_* environment variables are set to prevent docker
# from truncating build logs that can be useful during debugging. See
# https://github.com/docker/buildx/issues/484#issuecomment-749352728
docker buildx create --name certbot_builder --driver docker-container \
--driver-opt=network=host --driver-opt env.BUILDKIT_STEP_LOG_MAX_SIZE=-1 \
--driver-opt env.BUILDKIT_STEP_LOG_MAX_SPEED=-1 --bootstrap
}