From fd1eae843ab59c9b6e6649388c6a83703fac2d7a Mon Sep 17 00:00:00 2001 From: Quadrubo <71718414+Quadrubo@users.noreply.github.com> Date: Wed, 19 Jul 2023 15:04:37 +0200 Subject: [PATCH] feat: switch to alpine based image (#20) --- Dockerfile | 73 ++++++++++++------- docker/deploy/etc/s6-overlay/s6-rc.d/cron/run | 2 +- .../etc/s6-overlay/s6-rc.d/nginx/data/check | 16 ---- 3 files changed, 47 insertions(+), 44 deletions(-) delete mode 100644 docker/deploy/etc/s6-overlay/s6-rc.d/nginx/data/check diff --git a/Dockerfile b/Dockerfile index 262b271..ac3d4f1 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,34 +1,21 @@ -FROM serversideup/php:8.2-fpm-nginx +FROM ghcr.io/quadrubo/php-fpm-alpine-s6-nginx:php8.2-alpine3.18 as waky_builder -ARG NODE_VERSION=18 +# Install node +ENV NODE_VERSION=18.16.0 -# Add /config to allowed directory tree -ENV PHP_OPEN_BASEDIR=$WEBUSER_HOME:/config/:/dev/stdout:/tmp - -# Enable mixed ssl mode so port 80 or 443 can be used -ENV SSL_MODE="mixed" +ENV NODE_PACKAGE_URL=https://unofficial-builds.nodejs.org/download/release/v$NODE_VERSION/node-v$NODE_VERSION-linux-x64-musl.tar.xz -# Install additional packages and cron file -RUN apt-get update \ - && apt-get install -y --no-install-recommends \ - curl \ - cron \ - iputils-ping \ - openssh-client \ - # Needed for envsubst - gettext-base \ -# Install cron file - && echo "MAILTO=\"\"\n* * * * * webuser /usr/bin/php /var/www/html/artisan schedule:run" > /etc/cron.d/laravel \ -# Install node & npm - && curl -sLS https://deb.nodesource.com/setup_$NODE_VERSION.x | bash - \ - && apt-get install -y nodejs \ - && npm install -g npm \ -# Clean up package lists - && apt-get clean \ - && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* /usr/share/doc/* +RUN apk update && \ + apk add --no-cache libstdc++ -# Copy package configs -COPY --chmod=755 docker/deploy/etc/s6-overlay/ /etc/s6-overlay/ +RUN curl -fsSLO --compressed $NODE_PACKAGE_URL \ + && tar -xJf "node-v$NODE_VERSION-linux-x64-musl.tar.xz" -C /usr/local --strip-components=1 --no-same-owner \ + && ln -s /usr/local/bin/node /usr/local/bin/nodejs \ + # fi + && rm -f "node-v$NODE_VERSION-linux-x64-musl.tar.xz" \ + # smoke tests + && node --version \ + && npm --version WORKDIR /var/www/html @@ -49,4 +36,36 @@ RUN npm ci \ && npm cache clean --force \ && rm -rf node_modules +# main image +FROM ghcr.io/quadrubo/php-fpm-alpine-s6-nginx:php8.2-alpine3.18 + +# Add /config to allowed directory tree +ENV PHP_OPEN_BASEDIR=$WEBUSER_HOME:/config/:/dev/stdout:/tmp + +# Enable mixed ssl mode so port 80 or 443 can be used +ENV SSL_MODE="mixed" + +# Install additional packages and cron file +RUN apk update \ + && apk add --no-cache \ + curl \ + # cron \ + iputils-ping \ + openssh-client \ + # Needed for envsubst + gettext \ + # Install cron file + && echo "MAILTO=\"\"\n* * * * * webuser /usr/bin/php /var/www/html/artisan schedule:run" > /var/spool/cron/crontabs/root \ + # Clean up package lists + # && apt-get clean \ + && rm -rf /tmp/* /var/tmp/* /usr/share/doc/* + +# Copy package configs +COPY --chmod=755 docker/deploy/etc/s6-overlay/ /etc/s6-overlay/ + +WORKDIR /var/www/html + +# Copy app +COPY --from=waky_builder --chown=webuser:webgroup /var/www/html /var/www/html/ + VOLUME /config \ No newline at end of file diff --git a/docker/deploy/etc/s6-overlay/s6-rc.d/cron/run b/docker/deploy/etc/s6-overlay/s6-rc.d/cron/run index 13f7e3d..0a472d7 100644 --- a/docker/deploy/etc/s6-overlay/s6-rc.d/cron/run +++ b/docker/deploy/etc/s6-overlay/s6-rc.d/cron/run @@ -1,2 +1,2 @@ #!/command/with-contenv bash -s6-setuidgid root /usr/sbin/cron -f -l 8 \ No newline at end of file +s6-setuidgid root /usr/sbin/crond -f -l 8 \ No newline at end of file diff --git a/docker/deploy/etc/s6-overlay/s6-rc.d/nginx/data/check b/docker/deploy/etc/s6-overlay/s6-rc.d/nginx/data/check deleted file mode 100644 index d9ed7b0..0000000 --- a/docker/deploy/etc/s6-overlay/s6-rc.d/nginx/data/check +++ /dev/null @@ -1,16 +0,0 @@ -#!/command/with-contenv bash -if [[ -z "${HTTP_PORT}" ]]; then - url="http://localhost/ping" -else - url="http://localhost:${HTTP_PORT}/ping" -fi - -response=$(curl --location --insecure --silent "$url") - -if [[ $response == "pong" ]]; then - exit 0 -else - echo "❌ There seems to be a failure in checking the web server + PHP-FPM. Here's the response:" - echo $response - exit 1 -fi \ No newline at end of file