privatebin-docker-nginx-fpm.../buildx.sh

79 lines
1.9 KiB
Bash
Raw Normal View History

#!/bin/bash
# exit immediately on non-zero return code, including during a pipe stage or on
# accessing an uninitialized variable and print commands before executing them
set -euxo pipefail
EVENT=$1
EDGE=false
[ "$2" = edge ] && EDGE=true
build_image() {
2021-07-14 20:24:07 +02:00
local PUSH
PUSH=$1
shift 1
docker buildx build \
--platform linux/amd64,linux/386,linux/arm/v6,linux/arm/v7,linux/arm64,linux/ppc64le \
--output type=image,push="$PUSH" \
--pull \
--no-cache \
--progress plain \
$@ \
.
}
2021-07-14 20:24:07 +02:00
docker_login() {
printenv DOCKER_PASSWORD | docker login \
--username "$DOCKER_USERNAME" \
--password-stdin
}
image_build_arguments() {
cat<<!
privatebin/fs --build-arg ALPINE_PACKAGES= --build-arg COMPOSER_PACKAGES=
2021-07-14 21:29:37 +02:00
privatebin/pdo --build-arg ALPINE_PACKAGES=php8-pdo_mysql,php8-pdo_pgsql --build-arg COMPOSER_PACKAGES=
2021-07-14 20:24:07 +02:00
privatebin/gcs --build-arg ALPINE_PACKAGES=php8-openssl
privatebin/nginx-fpm-alpine
!
}
is_image_push_required() {
2021-07-14 20:24:07 +02:00
[ "$EVENT" != pull_request ] && { \
[ "$GITHUB_REF" != refs/heads/master ] || \
[ "$EVENT" = schedule ]
}
}
main() {
2021-07-14 20:24:07 +02:00
local PUSH TAG IMAGE BUILD_ARGS
2021-07-14 21:32:17 +02:00
if [ "$EVENT" = schedule ] ; then
2021-07-14 20:24:07 +02:00
TAG=nightly
else
TAG=${GITHUB_REF##*/}
fi
2021-07-14 21:32:17 +02:00
if is_image_push_required ; then
2021-07-14 20:24:07 +02:00
PUSH=true
docker_login
else
2021-07-14 20:24:07 +02:00
PUSH=false
fi
if [ "$EDGE" = true ] ; then
sed -e 's/^FROM alpine:.*$/FROM alpine:edge/' Dockerfile > Dockerfile.edge
fi
2021-07-14 21:32:17 +02:00
image_build_arguments | while read -r IMAGE BUILD_ARGS ; do
if [ "$EDGE" = false ] ; then
build_image $PUSH --tag "$IMAGE:latest" --tag "$IMAGE:$TAG" --tag "${IMAGE}:${TAG%%-*}" "$BUILD_ARGS"
else
build_image $PUSH -f Dockerfile.edge --tag "$IMAGE:edge" "$BUILD_ARGS"
fi
done
2021-07-14 20:24:07 +02:00
rm -f Dockerfile.edge "$HOME/.docker/config.json"
}
2021-07-14 20:24:07 +02:00
[ "$(basename "$0")" = 'buildx.sh' ] && main