Create base image for sharing common code
This commit is contained in:
parent
59118cd6a4
commit
f394bf42eb
@ -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 <kacper@kadet.net>"
|
||||
|
||||
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"]
|
||||
|
@ -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 <kacper@kadet.net>"
|
||||
|
||||
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
|
||||
|
||||
|
28
build/base/Dockerfile
Normal file
28
build/base/Dockerfile
Normal file
@ -0,0 +1,28 @@
|
||||
FROM php:7.4-alpine
|
||||
|
||||
LABEL maintainer="Kacper Donat <kacper@kadet.net>"
|
||||
|
||||
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"]
|
@ -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] <image> <context>
|
||||
# usage: build [-d|--default] [-v|--variant variant] [-R|--no-register] <image> <context>
|
||||
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"
|
||||
|
@ -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 && \
|
||||
{ \
|
||||
|
@ -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 <kacper@kadet.net>"
|
||||
|
||||
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"]
|
||||
|
Loading…
Reference in New Issue
Block a user