2021-06-06 11:14:30 +02:00
|
|
|
#!/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
|
|
|
|
|
2022-12-26 07:00:15 +01:00
|
|
|
EVENT="$1"
|
|
|
|
IMAGE="$2"
|
2021-09-29 19:41:07 +02:00
|
|
|
EDGE=false
|
2021-09-29 20:03:42 +02:00
|
|
|
[ "$3" = edge ] && EDGE=true
|
2021-07-11 19:40:47 +02:00
|
|
|
|
|
|
|
build_image() {
|
2021-10-14 21:05:30 +02:00
|
|
|
# shellcheck disable=SC2068
|
|
|
|
docker build \
|
2021-07-14 20:24:07 +02:00
|
|
|
--pull \
|
2021-10-14 21:26:14 +02:00
|
|
|
--no-cache \
|
2021-10-14 21:30:50 +02:00
|
|
|
--load \
|
2021-10-14 20:56:14 +02:00
|
|
|
$@ \
|
2021-10-14 20:44:53 +02:00
|
|
|
.
|
|
|
|
}
|
|
|
|
|
|
|
|
push_image() {
|
2021-10-14 21:05:30 +02:00
|
|
|
# shellcheck disable=SC2068
|
2021-10-14 20:44:53 +02:00
|
|
|
docker buildx build \
|
|
|
|
--platform linux/amd64,linux/386,linux/arm/v6,linux/arm/v7,linux/arm64,linux/ppc64le \
|
2021-10-14 21:32:23 +02:00
|
|
|
--pull \
|
|
|
|
--no-cache \
|
2021-10-14 20:44:53 +02:00
|
|
|
--push \
|
2021-10-14 20:56:14 +02:00
|
|
|
$@ \
|
2021-07-14 20:24:07 +02:00
|
|
|
.
|
|
|
|
}
|
2021-07-11 19:40:47 +02:00
|
|
|
|
2021-07-14 20:24:07 +02:00
|
|
|
docker_login() {
|
|
|
|
printenv DOCKER_PASSWORD | docker login \
|
2022-12-26 07:00:15 +01:00
|
|
|
--username "${DOCKER_USERNAME}" \
|
2021-07-14 20:24:07 +02:00
|
|
|
--password-stdin
|
2021-07-11 19:40:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
is_image_push_required() {
|
2022-12-26 07:00:15 +01:00
|
|
|
[ "${EVENT}" != pull_request ] && { \
|
|
|
|
[ "${GITHUB_REF}" != refs/heads/master ] || \
|
|
|
|
[ "${EVENT}" = schedule ]
|
2021-07-14 20:24:07 +02:00
|
|
|
}
|
2021-07-11 19:40:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
main() {
|
2022-12-26 07:00:15 +01:00
|
|
|
local TAG BUILD_ARGS IMAGE_TAGS
|
2021-07-11 19:40:47 +02:00
|
|
|
|
2022-12-26 07:00:15 +01:00
|
|
|
if [ "${EVENT}" = schedule ] ; then
|
2021-07-14 20:24:07 +02:00
|
|
|
TAG=nightly
|
|
|
|
else
|
|
|
|
TAG=${GITHUB_REF##*/}
|
|
|
|
fi
|
2021-07-11 19:40:47 +02:00
|
|
|
|
2022-12-26 07:00:15 +01:00
|
|
|
case "${IMAGE}" in
|
2021-09-29 20:03:42 +02:00
|
|
|
fs)
|
|
|
|
BUILD_ARGS="--build-arg ALPINE_PACKAGES= --build-arg COMPOSER_PACKAGES="
|
|
|
|
;;
|
2022-10-22 18:13:11 +02:00
|
|
|
gcs)
|
2022-11-12 07:58:20 +01:00
|
|
|
BUILD_ARGS="--build-arg ALPINE_PACKAGES=php81-openssl --build-arg COMPOSER_PACKAGES=google/cloud-storage"
|
2022-10-22 18:13:11 +02:00
|
|
|
;;
|
2021-09-29 20:03:42 +02:00
|
|
|
pdo)
|
2022-11-05 08:09:58 +01:00
|
|
|
BUILD_ARGS="--build-arg ALPINE_PACKAGES=php81-pdo_mysql,php81-pdo_pgsql --build-arg COMPOSER_PACKAGES="
|
2021-09-29 20:03:42 +02:00
|
|
|
;;
|
2022-10-22 18:13:11 +02:00
|
|
|
s3)
|
2023-01-03 19:57:33 +01:00
|
|
|
BUILD_ARGS="--build-arg ALPINE_PACKAGES=php81-curl,php81-openssl,php81-simplexml --build-arg COMPOSER_PACKAGES=aws/aws-sdk-php"
|
2021-09-29 20:03:42 +02:00
|
|
|
;;
|
|
|
|
*)
|
|
|
|
BUILD_ARGS=""
|
|
|
|
;;
|
|
|
|
esac
|
2022-12-31 08:10:50 +01:00
|
|
|
IMAGE="privatebin/${IMAGE}"
|
|
|
|
IMAGE_TAGS="--tag ${IMAGE}:latest --tag ${IMAGE}:${TAG} --tag ${IMAGE}:${TAG%%-*}"
|
2021-09-29 20:03:42 +02:00
|
|
|
|
2022-12-26 07:00:15 +01:00
|
|
|
if [ "${EDGE}" = true ] ; then
|
2022-12-26 06:34:52 +01:00
|
|
|
# build from alpine:edge instead of the stable release
|
2021-09-29 19:41:07 +02:00
|
|
|
sed -e 's/^FROM alpine:.*$/FROM alpine:edge/' Dockerfile > Dockerfile.edge
|
2022-12-26 06:34:52 +01:00
|
|
|
BUILD_ARGS+=" -f Dockerfile.edge"
|
|
|
|
|
|
|
|
# replace the default tags, build just the edge one
|
2022-12-31 08:10:50 +01:00
|
|
|
IMAGE_TAGS="--tag ${IMAGE}:edge"
|
|
|
|
IMAGE+=":edge"
|
2022-12-25 14:07:23 +01:00
|
|
|
else
|
2022-12-26 07:00:15 +01:00
|
|
|
if [ "${EVENT}" = push ] ; then
|
2022-12-26 06:34:52 +01:00
|
|
|
# append the stable tag on explicit pushes to master or (git) tags
|
2022-12-31 08:10:50 +01:00
|
|
|
IMAGE_TAGS+=" --tag ${IMAGE}:stable"
|
2022-12-26 06:34:52 +01:00
|
|
|
fi
|
2022-12-31 08:10:50 +01:00
|
|
|
# always build latest on non-edge builds
|
|
|
|
IMAGE+=":latest"
|
2021-10-14 20:44:53 +02:00
|
|
|
fi
|
2022-12-26 07:00:15 +01:00
|
|
|
build_image "${BUILD_ARGS} ${IMAGE_TAGS}"
|
2021-10-14 20:44:53 +02:00
|
|
|
|
2022-12-26 07:00:15 +01:00
|
|
|
docker run -d --rm -p 127.0.0.1:8080:8080 --read-only --name smoketest "${IMAGE}"
|
2021-10-14 20:44:53 +02:00
|
|
|
sleep 5 # give the services time to start up and the log to collect any errors that might occur
|
|
|
|
test "$(docker inspect --format="{{.State.Running}}" smoketest)" = true
|
|
|
|
curl --silent --show-error -o /dev/null http://127.0.0.1:8080/
|
2022-02-13 09:53:42 +01:00
|
|
|
if docker logs smoketest 2>&1 | grep -i -E "warn|emerg|fatal|panic|error"
|
2021-10-14 20:44:53 +02:00
|
|
|
then
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
docker stop smoketest
|
|
|
|
|
|
|
|
if is_image_push_required ; then
|
|
|
|
docker_login
|
2022-12-26 07:06:14 +01:00
|
|
|
push_image "${BUILD_ARGS} ${IMAGE_TAGS}"
|
2021-09-29 19:41:07 +02:00
|
|
|
fi
|
2021-07-11 19:40:47 +02:00
|
|
|
|
2022-12-26 07:00:15 +01:00
|
|
|
rm -f Dockerfile.edge "${HOME}/.docker/config.json"
|
2021-07-11 19:40:47 +02:00
|
|
|
}
|
2021-06-06 11:14:30 +02:00
|
|
|
|
2021-07-14 20:24:07 +02:00
|
|
|
[ "$(basename "$0")" = 'buildx.sh' ] && main
|