Clean up our Docker scripts (#8214)

* rewrite build step

* rewrite deploy script

* fix exit status

* clean up comments

* fix typo

* correct comment
This commit is contained in:
Brad Warren
2020-08-18 10:51:30 +02:00
committed by GitHub
parent e8a232297d
commit 63ec74276c
11 changed files with 110 additions and 232 deletions
-127
View File
@@ -31,130 +31,3 @@ export CERTBOT_PLUGINS=(
"dns-linode"
"dns-sakuracloud"
)
# Returns the translation from Docker to QEMU architecture
# Usage: GetQemuArch [amd64|arm32v6|arm64v8]
GetQemuArch() {
ARCH=$1
case "$ARCH" in
"amd64")
echo "x86_64"
;;
"arm32v6")
echo "arm"
;;
"arm64v8")
echo "aarch64"
;;
"*")
echo "Not supported build architecture '$1'." >&2
exit -1
esac
}
# Downloads QEMU static binary file for architecture
# Usage: DownloadQemuStatic [x86_64|arm|aarch64]
DownloadQemuStatic() {
ARCH=$1
QEMU_ARCH=$(GetQemuArch "$ARCH")
if [ ! -f "qemu-${QEMU_ARCH}-static" ]; then
QEMU_DOWNLOAD_URL="https://github.com/multiarch/qemu-user-static/releases/download"
QEMU_LATEST_TAG=$(curl -s https://api.github.com/repos/multiarch/qemu-user-static/tags \
| grep 'name.*v[0-9]' \
| head -n 1 \
| cut -d '"' -f 4)
curl -SL "${QEMU_DOWNLOAD_URL}/${QEMU_LATEST_TAG}/x86_64_qemu-$QEMU_ARCH-static.tar.gz" \
| tar xzv
fi
}
# Executes the QEMU register script
# Usage: RegisterQemuHandlers
RegisterQemuHandlers() {
docker run --rm --privileged multiarch/qemu-user-static:register --reset
}
# Builds docker certbot core image for a specific architecture.
# Usage: BuildDockerCoreImage [amd64|arm32v6|arm64v8]
BuildDockerCoreImage() {
ARCH=$1
QEMU=$(GetQemuArch "$ARCH")
docker build \
--build-arg TARGET_ARCH="${ARCH}" \
--build-arg QEMU_ARCH="${QEMU}" \
-f "${DOCKERFILE_PATH}" \
-t "${DOCKER_REPO}:${ARCH}-${DOCKER_TAG}" \
.
}
# Builds docker certbot plugin image for a specific architecture and tag.
# Usage: BuildDockerPluginImage [amd64|arm32v6|arm64v8]
BuildDockerPluginImage() {
ARCH=$1
QEMU=$(GetQemuArch "$ARCH")
BASE_IMAGE="${DOCKER_HUB_ORG}/certbot:${TARGET_ARCH}-${DOCKER_TAG}"
docker build \
--build-arg BASE_IMAGE="${BASE_IMAGE}" \
--build-arg QEMU_ARCH="${QEMU}" \
-f "${DOCKERFILE_PATH}" \
-t "${DOCKER_REPO}:${ARCH}-${DOCKER_TAG}" \
.
}
# Pushes docker image for a specific architecture.
# Usage: BuildDockerCoreImage [amd64|arm32v6|arm64v8]
PushDockerImage() {
ARCH=$1
docker push "${DOCKER_REPO}:${ARCH}-${DOCKER_TAG}"
}
# Creates any docker images aliases for a given architecture.
# If DOCKER_TAG tag is a version tag such as v0.35.0, the "latest" tag is also
# updated. In the case of the default architecture, tags without the
# architecture part are also created.
# As an example, for amd64 (the default architecture) and the tag v0.35.0, the
# following tags would be created:
# - certbot/certbot:v0.35.0
# - certbot/certbot:latest
# - certbot/certbot:amd64-latest
# For the architecture arm32v6 and the tag v0.35.0, only the following tag
# would be created:
# - certbot/certbot:arm32v6-latest
# For other tags such as "nightly", aliases are only created for the default
# architecture where the tag "nightly" would be used without an architecture
# part.
# Usage: TagDockerImageAliases [amd64|arm32v6|arm64v8]
TagDockerImageAliases() {
ARCH=$1
if [[ "${DOCKER_TAG}" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
docker tag "${DOCKER_REPO}:${ARCH}-${DOCKER_TAG}" "${DOCKER_REPO}:${ARCH}-latest"
if [ "${ARCH}" == "${DEFAULT_ARCH}" ]; then
docker tag "${DOCKER_REPO}:${ARCH}-${DOCKER_TAG}" "${DOCKER_REPO}:latest"
fi
fi
if [ "${ARCH}" == "${DEFAULT_ARCH}" ]; then
docker tag "${DOCKER_REPO}:${ARCH}-${DOCKER_TAG}" "${DOCKER_REPO}:${DOCKER_TAG}"
fi
}
# Pushes docker images aliases created by the TagDockerImageAliases function.
# Usage: PushDockerImageAliases [amd64|arm32v6|arm64v8]
PushDockerImageAliases() {
ARCH=$1
if [[ "${DOCKER_TAG}" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
docker push "${DOCKER_REPO}:${ARCH}-latest"
if [ "${ARCH}" == "${DEFAULT_ARCH}" ]; then
docker push "${DOCKER_REPO}:latest"
fi
fi
if [ "${ARCH}" == "${DEFAULT_ARCH}" ]; then
docker push "${DOCKER_REPO}:${DOCKER_TAG}"
fi
}