Change to Alpine for x2 smaller image

This commit is contained in:
Quentin McGaw (desktop) 2021-08-04 11:03:28 -04:00
parent ce263e49eb
commit 78ba73f34b
4 changed files with 31 additions and 33 deletions

View File

@ -1,7 +1,7 @@
ARG BUILDPLATFORM=linux/amd64 ARG BUILDPLATFORM=linux/amd64
ARG TARGETPLATFORM ARG TARGETPLATFORM
ARG DEBIAN_VERSION=buster-slim ARG ALPINE_VERSION=3.14
ARG PHP_VERSION=7.3-buster ARG PHP_VERSION=7.3-alpine${ALPINE_VERSION}
ARG COMPOSER_VERSION=2.1 ARG COMPOSER_VERSION=2.1
ARG SUPERVISORD_VERSION=v0.7.3 ARG SUPERVISORD_VERSION=v0.7.3
@ -10,15 +10,13 @@ FROM composer:${COMPOSER_VERSION} AS composer
FROM qmcgaw/binpot:supervisord-${SUPERVISORD_VERSION} AS supervisord FROM qmcgaw/binpot:supervisord-${SUPERVISORD_VERSION} AS supervisord
FROM --platform=${BUILDPLATFORM} php:${PHP_VERSION} AS vendor FROM --platform=${BUILDPLATFORM} php:${PHP_VERSION} AS vendor
ENV DEBIAN_FRONTEND=noninteractive
COPY --from=build-composer --chown=${UID}:${GID} /usr/bin/composer /usr/bin/composer COPY --from=build-composer --chown=${UID}:${GID} /usr/bin/composer /usr/bin/composer
RUN apt-get update && \ RUN apk add --no-cache unzip
apt-get install -y --no-install-recommends unzip && \
rm -rf /var/cache/* /var/lib/apt/lists/*
WORKDIR /srv WORKDIR /srv
COPY artisan composer.json composer.lock ./ COPY artisan composer.json composer.lock ./
COPY database ./database COPY database ./database
RUN composer install --prefer-dist --no-scripts --no-dev --no-autoloader RUN composer install --prefer-dist --no-scripts --no-dev --no-autoloader
RUN composer dump-autoload --no-scripts --no-dev --optimize
FROM --platform=${BUILDPLATFORM} vendor AS test FROM --platform=${BUILDPLATFORM} vendor AS test
COPY . . COPY . .
@ -27,8 +25,7 @@ RUN composer install
RUN php artisan key:generate RUN php artisan key:generate
ENTRYPOINT [ "/srv/vendor/bin/phpunit" ] ENTRYPOINT [ "/srv/vendor/bin/phpunit" ]
FROM debian:${DEBIAN_VERSION} FROM alpine:${ALPINE_VERSION}
ENV DEBIAN_FRONTEND=noninteractive
ARG UID=1000 ARG UID=1000
ARG GID=1000 ARG GID=1000
@ -39,39 +36,40 @@ COPY --from=composer --chown=${UID}:${GID} /usr/bin/composer /usr/bin/composer
COPY --from=supervisord --chown=${UID}:${GID} /bin /usr/local/bin/supervisord COPY --from=supervisord --chown=${UID}:${GID} /bin /usr/local/bin/supervisord
# Install PHP and PHP system dependencies # Install PHP and PHP system dependencies
RUN apt-get update && \ RUN apk add --update --no-cache \
apt-get install -y --no-install-recommends \
# PHP # PHP
php7.3 \ php7 \
# Composer dependencies
php7-phar \
# PHP SQLite driver # PHP SQLite driver
php7.3-sqlite3 \ php7-pdo_sqlite php7-sqlite3 \
# PHP extensions # PHP extensions
php-xml php7.3-gd php7.3-mbstring \ php7-xml php7-gd php7-mbstring \
# Runtime dependencies
php7-session php7-json php7-openssl \
# Nginx and PHP FPM to serve over HTTP # Nginx and PHP FPM to serve over HTTP
php7.3-fpm nginx \ php7-fpm nginx \
&& \ && \
# Clean up # Clean up
apt-get clean && \ rm /etc/nginx/nginx.conf && \
rm -rf /var/cache/* /var/lib/apt/lists/* /etc/nginx/nginx.conf && \
# Fix ownership to ${UID}:${GID} # Fix ownership to ${UID}:${GID}
chown -R ${UID}:${GID} /var/log/nginx /var/lib/nginx/ chown -R ${UID}:${GID} /var/lib/nginx/
# PHP FPM configuration # PHP FPM configuration
# Change username and ownership in php-fpm pool config # Change username and ownership in php-fpm pool config
RUN sed -i '/user = www-data/d' /etc/php/7.3/fpm/pool.d/www.conf && \ RUN sed -i '/user = nobody/d' /etc/php7/php-fpm.d/www.conf && \
sed -i '/group = www-data/d' /etc/php/7.3/fpm/pool.d/www.conf && \ sed -i '/group = nobody/d' /etc/php7/php-fpm.d/www.conf && \
sed -i 's/listen.owner = www-data/listen.owner = ${UID}/g' /etc/php/7.3/fpm/pool.d/www.conf && \ sed -i '/listen.owner/d' /etc/php7/php-fpm.d/www.conf && \
sed -i 's/listen.group = www-data/listen.group = ${GID}/g' /etc/php/7.3/fpm/pool.d/www.conf sed -i '/listen.group/d' /etc/php7/php-fpm.d/www.conf
# Pre-create files with the correct permissions # Pre-create files with the correct permissions
RUN mkdir /run/php && \ RUN mkdir /run/php && \
touch /var/log/php7.3-fpm.log && \ chown ${UID}:${GID} /run/php /var/log/php7 && \
chown ${UID}:${GID} /run/php /var/log/php7.3-fpm.log && \ chmod 700 /run/php /var/log/php7
chmod 700 /run/php /var/log/php7.3-fpm.log
# Nginx configuration # Nginx configuration
EXPOSE 8000/tcp EXPOSE 8000/tcp
RUN touch /run/nginx.pid && \ RUN touch /run/nginx/nginx.pid /var/lib/nginx/logs/error.log && \
chown ${UID}:${GID} /run/nginx.pid chown ${UID}:${GID} /run/nginx/nginx.pid /var/lib/nginx/logs/error.log
COPY --chown=${UID}:${GID} docker/nginx.conf /etc/nginx/nginx.conf COPY --chown=${UID}:${GID} docker/nginx.conf /etc/nginx/nginx.conf
RUN nginx -t RUN nginx -t
@ -96,7 +94,7 @@ COPY --from=vendor --chown=${UID}:${GID} /srv/vendor /srv/vendor
# Copy the rest of the code # Copy the rest of the code
COPY --chown=${UID}:${GID} . . COPY --chown=${UID}:${GID} . .
RUN composer dump-autoload --no-scripts --no-dev --optimize # RUN composer dump-autoload --no-scripts --no-dev --optimize
# Entrypoint # Entrypoint
ENTRYPOINT [ "/usr/local/bin/entrypoint.sh" ] ENTRYPOINT [ "/usr/local/bin/entrypoint.sh" ]

View File

@ -1,4 +1,4 @@
#!/bin/bash #!/bin/sh
set -e set -e
@ -6,7 +6,7 @@ echo "Running version ${VERSION} commit ${COMMIT} built on ${CREATED}"
# Show versions # Show versions
echo "supervisord version: $(supervisord version)" echo "supervisord version: $(supervisord version)"
php-fpm7.3 -v | head -n 1 php-fpm7 -v | head -n 1
nginx -v nginx -v
if [ "${DB_CONNECTION}" = "sqlite" ]; then if [ "${DB_CONNECTION}" = "sqlite" ]; then
@ -14,7 +14,7 @@ if [ "${DB_CONNECTION}" = "sqlite" ]; then
touch /2fauth/database.sqlite touch /2fauth/database.sqlite
fi fi
rm -f /srv/database/database.sqlite rm -f /srv/database/database.sqlite
ln -sF /2fauth/database.sqlite /srv/database/database.sqlite ln -s /2fauth/database.sqlite /srv/database/database.sqlite
fi fi
# Inject storage in /2fauth and use it with a symlink # Inject storage in /2fauth and use it with a symlink
@ -23,7 +23,7 @@ if [ ! -d /2fauth/storage ]; then
else else
rm -r /srv/storage rm -r /srv/storage
fi fi
ln -sF /2fauth/storage /srv/storage ln -s /2fauth/storage /srv/storage
# Note: ${COMMIT} is set by the CI # Note: ${COMMIT} is set by the CI
if [ -f /2fauth/installed ]; then if [ -f /2fauth/installed ]; then

View File

@ -24,7 +24,7 @@ http {
error_page 404 /index.php; error_page 404 /index.php;
location ~ \.php$ { location ~ \.php$ {
fastcgi_pass unix:/var/run/php/php7.3-fpm.sock; fastcgi_pass 127.0.0.1:9000;
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name; fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
include fastcgi_params; include fastcgi_params;
} }

View File

@ -12,7 +12,7 @@ autorestart=false
startretries=0 startretries=0
[program:php-fpm] [program:php-fpm]
command=/usr/sbin/php-fpm7.3 -F command=/usr/sbin/php-fpm7 -F
[program:nginx] [program:nginx]
command=/usr/sbin/nginx -g 'daemon off;' command=/usr/sbin/nginx -g 'daemon off;'