diff --git a/build/api/fpm.Dockerfile b/build/api/fpm.Dockerfile index d683658..3e1a422 100644 --- a/build/api/fpm.Dockerfile +++ b/build/api/fpm.Dockerfile @@ -1,29 +1,24 @@ +ARG BASE_VERSION=latest +ARG REGISTRY=docker.io + +FROM $REGISTRY/cojedzie/base:$BASE_VERSION as base + FROM php:7.4-fpm-alpine LABEL maintainer="Kacper Donat " COPY --from=mlocati/php-extension-installer /usr/bin/install-php-extensions /usr/local/bin/ -COPY --from=composer:latest /usr/bin/composer /usr/bin/composer WORKDIR /var/www RUN install-php-extensions bcmath intl opcache zip sockets; -COPY composer.json composer.lock ./ - -RUN apk add git && \ - composer install --no-dev --no-scripts --no-plugins --prefer-dist --no-progress --no-interaction && \ - composer dump-autoload --optimize && \ - composer check-platform-reqs && \ - composer clear-cache && \ - apk del --purge git - -COPY . . +COPY --from=base /var/www /var/www ENV APP_ENV=prod ENV DATABASE_URL="sqlite:////var/db/app.db" ENV PATH=$PATH:/var/www/bin -RUN composer run-script post-install-cmd +VOLUME /var/db CMD ["./bin/docker-init.sh", "php-fpm"] diff --git a/build/api/rr.Dockerfile b/build/api/rr.Dockerfile index bcdf906..854d3b2 100644 --- a/build/api/rr.Dockerfile +++ b/build/api/rr.Dockerfile @@ -1,36 +1,25 @@ +ARG BASE_VERSION=latest +ARG REGISTRY=docker.io + +FROM $REGISTRY/cojedzie/base:$BASE_VERSION as base + FROM php:7.4-alpine LABEL maintainer="Kacper Donat " COPY --from=mlocati/php-extension-installer /usr/bin/install-php-extensions /usr/local/bin/ -COPY --from=composer:latest /usr/bin/composer /usr/bin/composer WORKDIR /var/www RUN install-php-extensions bcmath intl opcache zip sockets; -COPY composer.json composer.lock ./ - -RUN apk add git && \ - composer install --no-dev --no-scripts --no-plugins --prefer-dist --no-progress --no-interaction && \ - composer dump-autoload --optimize && \ - composer check-platform-reqs && \ - composer clear-cache && \ - apk del --purge git - -# this touch is needed because get-binary calls the autoloader -RUN mkdir -p ./src/Functions && \ - touch src/Functions/index.php && \ - ./vendor/bin/rr get-binary --location /usr/local/bin - -COPY . . +COPY --from=base /var/www /var/www ENV APP_ENV=prod ENV DATABASE_URL="sqlite:////var/db/app.db" ENV PATH=$PATH:/var/www/bin -RUN composer run-script post-install-cmd -RUN mkdir /var/db +VOLUME /var/db EXPOSE 8080 diff --git a/build/base/Dockerfile b/build/base/Dockerfile new file mode 100644 index 0000000..5d6dcef --- /dev/null +++ b/build/base/Dockerfile @@ -0,0 +1,28 @@ +FROM php:7.4-alpine + +LABEL maintainer="Kacper Donat " + +COPY --from=mlocati/php-extension-installer /usr/bin/install-php-extensions /usr/local/bin/ +COPY --from=composer:latest /usr/bin/composer /usr/bin/composer + +WORKDIR /var/www + +RUN install-php-extensions bcmath intl opcache zip sockets; + +COPY composer.json composer.lock ./ + +RUN apk add git && \ + composer install --no-dev --no-scripts --no-plugins --prefer-dist --no-progress --no-interaction && \ + composer dump-autoload --optimize && \ + composer check-platform-reqs && \ + composer clear-cache && \ + apk del --purge git + +COPY . . + +ENV APP_ENV=prod + +RUN composer run-script post-install-cmd + +# This image is not meant to be run, just to prepare all required files +CMD ["/bin/false"] diff --git a/build/release.sh b/build/release.sh index 62171a4..ba72706 100755 --- a/build/release.sh +++ b/build/release.sh @@ -8,13 +8,14 @@ REGISTRY="docker.io" TAGS=() DRY=0 PUSH=0 +BUILD_BASE=1 BUILT_TAGS=() export DOCKER_BUILDKIT=1 usage () { - echo "usage: $0 [-h|--help] [-d|--dry] [-r|--registry registry] [-t|--tag tag] [-p|--push] -- images..."; + echo "usage: $0 [-h|--help] [-d|--dry] [--no-base|-B] [-p|--push] [-r|--registry registry] [-t|--tag tag] -- images..."; } run () { @@ -25,14 +26,15 @@ run () { fi } -# usage: build [-d|--default] [-v|--variant variant] +# usage: build [-d|--default] [-v|--variant variant] [-R|--no-register] build () { ARGS=() IS_DEFAULT=0 SUFFIX="" VARIANT="" + REGISTER=1 - options=$(getopt -l "default,variant:" -o "dv:" -- "$@") + options=$(getopt -l "default,variant:,no-register" -o "dv:R" -- "$@") eval set -- "$options" while true; @@ -46,6 +48,10 @@ build () { VARIANT="$2" shift 2 ;; + -R|--no-register) + REGISTER=0 + shift + ;; --) shift break @@ -70,18 +76,19 @@ build () { for TAG in "${TAGS[@]}"; do ARGS+=("-t" "$REGISTRY/cojedzie/$IMAGE:$TAG$SUFFIX") - BUILT_TAGS+=("$REGISTRY/cojedzie/$IMAGE:$TAG$SUFFIX") + [[ $REGISTER -eq 1 ]] && BUILT_TAGS+=("$REGISTRY/cojedzie/$IMAGE:$TAG$SUFFIX") if [[ $IS_DEFAULT == 1 ]]; then ARGS+=("-t" "$REGISTRY/cojedzie/$IMAGE:$TAG") - BUILT_TAGS+=("$REGISTRY/cojedzie/$IMAGE:$TAG") + [[ $REGISTER -eq 1 ]] && BUILT_TAGS+=("$REGISTRY/cojedzie/$IMAGE:$TAG") fi done - run docker build $CONTEXT "${ARGS[@]}" "$@" + echo "Building $IMAGE $VARIANT" + run docker build --build-arg "BASE_VERSION=${TAGS[0]}" --build-arg "REGISTRY=$REGISTRY" "$CONTEXT" "${ARGS[@]}" "$@" } -options=$(getopt -l "help,dry,registry:,tag:,push" -o "hdr:t:p" -- "$@") +options=$(getopt -l "help,dry,registry:,tag:,push,no-base" -o "hdr:t:pB" -- "$@") eval set -- "$options" while true; @@ -99,6 +106,10 @@ do PUSH=1 shift ;; + -B|--no-base) + BUILD_BASE=0 + shift + ;; -r|--registry) REGISTRY="$2" shift 2 @@ -122,21 +133,25 @@ if [ $# -eq 0 ]; then set -- api standalone worker front fi +if [ $BUILD_BASE -eq 1 ]; then + build --no-register base $ROOT/api/ || exit 1 +fi + while [ $# -gt 0 ] do case "$1" in api) - build api $ROOT/api/ --variant rr --default - build api $ROOT/api/ --variant fpm + build api $ROOT/api/ --variant rr --default || exit 1 + build api $ROOT/api/ --variant fpm || exit 1 ;; standalone) - build standalone $ROOT/api/ --variant rr --default + build standalone $ROOT/api/ --variant rr --default || exit 1 ;; worker) - build worker $ROOT/api/ + build worker $ROOT/api/ || exit 1 ;; front) - build front $ROOT/front/ + build front $ROOT/front/ || exit 1 ;; *) >&2 echo "$1 is not a valid image to build" diff --git a/build/standalone/rr.Dockerfile b/build/standalone/rr.Dockerfile index d68903e..0fcd071 100644 --- a/build/standalone/rr.Dockerfile +++ b/build/standalone/rr.Dockerfile @@ -1,6 +1,7 @@ -ARG COJEDZIE_VER=latest +ARG BASE_VERSION=latest +ARG REGISTRY=docker.io -FROM cojedzie/api:${COJEDZIE_VER}-rr +FROM ${REGISTRY}/cojedzie/api:${BASE_VERSION}-rr RUN apk add supervisor && \ { \ diff --git a/build/worker/Dockerfile b/build/worker/Dockerfile index 76d78b5..eeb7cee 100644 --- a/build/worker/Dockerfile +++ b/build/worker/Dockerfile @@ -1,31 +1,24 @@ +ARG BASE_VERSION=latest +ARG REGISTRY=docker.io + +FROM $REGISTRY/cojedzie/base:$BASE_VERSION as base + FROM php:7.4-cli-alpine LABEL maintainer="Kacper Donat " COPY --from=mlocati/php-extension-installer /usr/bin/install-php-extensions /usr/local/bin/ -COPY --from=composer:latest /usr/bin/composer /usr/bin/composer WORKDIR /var/www RUN install-php-extensions bcmath intl opcache zip sockets; -COPY composer.json composer.lock ./ - -RUN apk add git && \ - composer install --no-dev --no-scripts --no-plugins --prefer-dist --no-progress --no-interaction && \ - composer dump-autoload --optimize && \ - composer check-platform-reqs && \ - composer clear-cache && \ - apk del --purge git - -COPY . . +COPY --from=base /var/www /var/www ENV APP_ENV=prod ENV DATABASE_URL="sqlite:////var/db/app.db" ENV PATH=$PATH:/var/www/bin -RUN composer run-script post-install-cmd - RUN apk add supervisor && \ { \ echo '[supervisord]'; \ @@ -42,4 +35,6 @@ RUN apk add supervisor && \ echo 'stderr_logfile_maxbytes=0'; \ } | tee /etc/supervisord.conf; +VOLUME /var/db + CMD ["supervisord", "-c", "/etc/supervisord.conf"]