create separate images for fs, pdo and gcs

- modified buildx.sh to build privatebin/fs, privatebin/pdo, privatebin/gcs and privatebin/nginx-fpm-alpine
- default build of privatebin/nginx-fpm-alpine contains everything
This commit is contained in:
Mark van Holsteijn 2021-07-11 19:40:47 +02:00
parent 9568519e50
commit 0a39c4075b
3 changed files with 69 additions and 26 deletions

1
.gitignore vendored Normal file
View file

@ -0,0 +1 @@
Dockerfile.edge

View file

@ -2,16 +2,19 @@ FROM alpine:3.14
MAINTAINER PrivateBin <support@privatebin.org>
ENV RELEASE 1.3.5
ENV PBURL https://github.com/PrivateBin/PrivateBin/
ARG ALPINE_PACKAGES="php8-pdo_mysql php8-pdo_pgsql"
ARG COMPOSER_PACKAGES="google/cloud-storage"
ENV RELEASE 1.3.5
ENV PBURL https://github.com/PrivateBin/PrivateBin/
ENV S6_READ_ONLY_ROOT 1
ENV CONFIG_PATH /srv/cfg
RUN \
# Install dependencies
apk add --no-cache gnupg nginx php8 php8-curl php8-fpm php8-json php8-gd \
php8-mbstring php8-opcache php8-pdo_mysql php8-pdo_pgsql php8-phar \
s6-overlay tzdata \
php8-mbstring php8-opcache php8-phar \
s6-overlay tzdata php8-openssl $ALPINE_PACKAGES \
&& apk upgrade --no-cache \
# Remove (some of the) default nginx config
&& rm -f /etc/nginx.conf /etc/nginx/http.d/default.conf /etc/php8/php-fpm.d/www.conf \
@ -35,7 +38,7 @@ RUN \
&& wget -q $(echo ${PBURL} | sed s/github.com/raw.githubusercontent.com/)${RELEASE}/composer.json \
&& wget -q $(echo ${PBURL} | sed s/github.com/raw.githubusercontent.com/)${RELEASE}/composer.lock \
&& composer remove --dev --no-update phpunit/phpunit \
&& composer require --no-update google/cloud-storage \
&& ([ -z "$COMPOSER_PACKAGES"] || composer require --no-update $COMPOSER_PACKAGES) \
&& composer update --no-dev --optimize-autoloader \
&& rm *.md cfg/conf.sample.php composer.* /usr/local/bin/* \
&& mv cfg lib tpl vendor /srv \

View file

@ -4,29 +4,68 @@
# accessing an uninitialized variable and print commands before executing them
set -euxo pipefail
IMAGE=privatebin/nginx-fpm-alpine
QEMU_PLATFORMS=linux/amd64,linux/386,linux/arm/v6,linux/arm/v7,linux/arm64,linux/ppc64le
VERSION=${GITHUB_REF##*/}
EVENT=$1
[ "${EVENT}" = "schedule" ] && VERSION=nightly
VERSION=${GITHUB_REF##*/}
BUILDX_ARGS="--tag ${IMAGE}:latest \
--tag ${IMAGE}:${VERSION} --tag ${IMAGE}:${VERSION%%-*} \
--platform ${QEMU_PLATFORMS} ."
BUILDX_EDGE_ARGS="--tag ${IMAGE}:edge \
--platform ${QEMU_PLATFORMS} -f Dockerfile-edge ."
# build images
docker build --no-cache --pull --output "type=image,push=false" ${BUILDX_ARGS}
sed 's/^FROM alpine:.*$/FROM alpine:edge/' Dockerfile > Dockerfile-edge
docker build --no-cache --pull --output "type=image,push=false" ${BUILDX_EDGE_ARGS}
build_image() {
local push build_args
push=$1; shift 1;
build_args="$@"
# push cached images
if [ "${EVENT}" != "pull_request" ] && ([ "${GITHUB_REF}" != "refs/heads/master" ] || [ "${EVENT}" = "schedule" ])
then
printenv DOCKER_PASSWORD | docker login --username "${DOCKER_USERNAME}" --password-stdin
docker build --output "type=image,push=true" ${BUILDX_ARGS}
docker build --output "type=image,push=true" ${BUILDX_EDGE_ARGS}
rm -f ${HOME}/.docker/config.json
fi
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 \
$build_args \
.
}
image_build_arguments() {
cat<<!
privatebin/fs --build-arg ALPINE_PACKAGES= --build-arg COMPOSER_PACKAGES=
privatebin/pdo --build-arg COMPOSER_PACKAGES=
privatebin/gcs --build-arg ALPINE_PACKAGES=
privatebin/nginx-fpm-alpine
!
}
docker_login() {
printenv DOCKER_PASSWORD | docker login --username "$DOCKER_USERNAME" --password-stdin
}
is_image_push_required() {
[[ $EVENT != pull_request ]] && ([[ $GITHUB_REF != refs/heads/master ]] || [[ $EVENT = schedule ]])
}
main() {
local push tag image build_args
# tag the image with nightly, if it is the scheduled event
[[ $EVENT == schedule ]] && tag=nightly || tag=$VERSION
if is_image_push_required; then
push=true
docker_login
else
push=false
fi
image_build_arguments | while read image build_args ; do
build_image $push --tag $image:latest --tag $image:$tag "$build_args"
done
sed -e 's/^FROM alpine:.*$/FROM alpine:edge/' Dockerfile > Dockerfile.edge
image_build_arguments | while read image build_args ; do
build_image $push -f Dockerfile.edge --tag $image:edge "$build_args"
done
rm -f Dockerfile.edge
rm -f "$HOME/.docker/config.json"
}
main