take shellcheck to town

This commit is contained in:
El RIDO 2021-07-14 20:24:07 +02:00
parent 09912939fe
commit c2ff69021d
No known key found for this signature in database
GPG key ID: 0F5C940A6BD81F92

View file

@ -5,67 +5,71 @@
set -euxo pipefail set -euxo pipefail
EVENT=$1 EVENT=$1
VERSION=${GITHUB_REF##*/}
build_image() { build_image() {
local push build_args local PUSH
push=$1; shift 1; PUSH=$1
build_args="$@" shift 1
docker buildx build \ docker buildx build \
--platform linux/amd64,linux/386,linux/arm/v6,linux/arm/v7,linux/arm64,linux/ppc64le \ --platform linux/amd64,linux/386,linux/arm/v6,linux/arm/v7,linux/arm64,linux/ppc64le \
--output type=image,push=$push \ --output type=image,push="$PUSH" \
--pull \ --pull \
--no-cache \ --no-cache \
--progress plain \ --progress plain \
$build_args \ $@ \
. .
}
docker_login() {
printenv DOCKER_PASSWORD | docker login \
--username "$DOCKER_USERNAME" \
--password-stdin
} }
image_build_arguments() { image_build_arguments() {
cat<<! cat<<!
privatebin/fs --build-arg ALPINE_PACKAGES= --build-arg COMPOSER_PACKAGES= privatebin/fs --build-arg ALPINE_PACKAGES= --build-arg COMPOSER_PACKAGES=
privatebin/pdo --build-arg COMPOSER_PACKAGES= privatebin/pdo --build-arg ALPINE_PACKAGES="php8-pdo_mysql php8-pdo_pgsql" COMPOSER_PACKAGES=
privatebin/gcs --build-arg ALPINE_PACKAGES= privatebin/gcs --build-arg ALPINE_PACKAGES=php8-openssl
privatebin/nginx-fpm-alpine privatebin/nginx-fpm-alpine
! !
} }
docker_login() {
printenv DOCKER_PASSWORD | docker login --username "$DOCKER_USERNAME" --password-stdin
}
is_image_push_required() { is_image_push_required() {
[[ $EVENT != pull_request ]] && ([[ $GITHUB_REF != refs/heads/master ]] || [[ $EVENT = schedule ]]) [ "$EVENT" != pull_request ] && { \
[ "$GITHUB_REF" != refs/heads/master ] || \
[ "$EVENT" = schedule ]
}
} }
main() { main() {
local push tag image build_args local PUSH TAG IMAGE BUILD_ARGS
# tag the image with nightly, if it is the scheduled event if [ "$EVENT" = schedule ]
then
[[ $EVENT == schedule ]] && tag=nightly || tag=$VERSION TAG=nightly
if is_image_push_required; then
push=true
docker_login
else else
push=false TAG=${GITHUB_REF##*/}
fi fi
image_build_arguments | while read image build_args ; do if is_image_push_required
build_image $push --tag $image:latest --tag $image:$tag "$build_args" then
done PUSH=true
docker_login
else
PUSH=false
fi
sed -e 's/^FROM alpine:.*$/FROM alpine:edge/' Dockerfile > Dockerfile.edge sed -e 's/^FROM alpine:.*$/FROM alpine:edge/' Dockerfile > Dockerfile.edge
image_build_arguments | while read image build_args ; do image_build_arguments | while read -r IMAGE BUILD_ARGS
build_image $push -f Dockerfile.edge --tag $image:edge "$build_args" do
build_image $PUSH --tag "$IMAGE:latest" --tag "$IMAGE:$TAG" $BUILD_ARGS
build_image $PUSH -f Dockerfile.edge --tag "$IMAGE:edge" $BUILD_ARGS
done done
rm -f Dockerfile.edge rm -f Dockerfile.edge "$HOME/.docker/config.json"
rm -f "$HOME/.docker/config.json"
} }
main [ "$(basename "$0")" = 'buildx.sh' ] && main