From 0aaac9ef23a32a3c9c7a261997ef28769f48beb7 Mon Sep 17 00:00:00 2001 From: Muhajirin Ilyas Date: Sun, 24 Nov 2024 20:59:20 +0700 Subject: [PATCH] freeze 8.3 version into branch --- .github/workflows/ci-slim.yml | 123 ++++++++++++++++++ .github/workflows/{ci.yml => ci-ubuntu.yml} | 16 +-- README.md | 9 +- slim/cli/Dockerfile | 26 ++++ slim/fpm/Dockerfile | 18 +++ {fpm => slim/fpm}/overrides.conf | 0 {fpm => slim/fpm}/php-fpm-startup | 0 slim/nginx/Dockerfile | 41 ++++++ {nginx => slim/nginx}/index.php | 0 {nginx => slim/nginx}/site.conf | 0 .../nginx}/supervisor/conf.d/nginx.conf | 0 .../nginx}/supervisor/conf.d/php-fpm.conf | 0 .../nginx}/supervisor/supervisord.conf | 0 slim/octane/Dockerfile | 58 +++++++++ slim/octane/runner.sh | 29 +++++ {cli => ubuntu/cli}/Dockerfile | 1 + {fpm => ubuntu/fpm}/Dockerfile | 1 + ubuntu/fpm/overrides.conf | 16 +++ ubuntu/fpm/php-fpm-startup | 2 + {nginx => ubuntu/nginx}/Dockerfile | 1 + ubuntu/nginx/index.php | 1 + ubuntu/nginx/site.conf | 27 ++++ ubuntu/nginx/supervisor/conf.d/nginx.conf | 10 ++ ubuntu/nginx/supervisor/conf.d/php-fpm.conf | 10 ++ ubuntu/nginx/supervisor/supervisord.conf | 29 +++++ {octane => ubuntu/octane}/Dockerfile | 1 + {octane => ubuntu/octane}/runner.sh | 0 27 files changed, 408 insertions(+), 11 deletions(-) create mode 100644 .github/workflows/ci-slim.yml rename .github/workflows/{ci.yml => ci-ubuntu.yml} (92%) create mode 100644 slim/cli/Dockerfile create mode 100644 slim/fpm/Dockerfile rename {fpm => slim/fpm}/overrides.conf (100%) rename {fpm => slim/fpm}/php-fpm-startup (100%) create mode 100644 slim/nginx/Dockerfile rename {nginx => slim/nginx}/index.php (100%) rename {nginx => slim/nginx}/site.conf (100%) rename {nginx => slim/nginx}/supervisor/conf.d/nginx.conf (100%) rename {nginx => slim/nginx}/supervisor/conf.d/php-fpm.conf (100%) rename {nginx => slim/nginx}/supervisor/supervisord.conf (100%) create mode 100644 slim/octane/Dockerfile create mode 100755 slim/octane/runner.sh rename {cli => ubuntu/cli}/Dockerfile (97%) rename {fpm => ubuntu/fpm}/Dockerfile (94%) create mode 100644 ubuntu/fpm/overrides.conf create mode 100755 ubuntu/fpm/php-fpm-startup rename {nginx => ubuntu/nginx}/Dockerfile (96%) create mode 100644 ubuntu/nginx/index.php create mode 100644 ubuntu/nginx/site.conf create mode 100644 ubuntu/nginx/supervisor/conf.d/nginx.conf create mode 100644 ubuntu/nginx/supervisor/conf.d/php-fpm.conf create mode 100644 ubuntu/nginx/supervisor/supervisord.conf rename {octane => ubuntu/octane}/Dockerfile (98%) rename {octane => ubuntu/octane}/runner.sh (100%) diff --git a/.github/workflows/ci-slim.yml b/.github/workflows/ci-slim.yml new file mode 100644 index 0000000..6ef0e10 --- /dev/null +++ b/.github/workflows/ci-slim.yml @@ -0,0 +1,123 @@ +name: Docker build for slim variant +on: + push: + branches: + - 8.3 + schedule: + - cron: '0 0 1 * *' + workflow_dispatch: + +jobs: + build-cli: + runs-on: ubuntu-latest + steps: + - + name: Checkout + uses: actions/checkout@v4 + - + name: Set up QEMU + uses: docker/setup-qemu-action@v3 + - + name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + - + name: Login to GitHub Container Registry + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ secrets.GHCR_USR }} + password: ${{ secrets.GHCR_PAT }} + - + name: Build and push + uses: docker/build-push-action@v6 + with: + context: slim/cli/ + platforms: linux/amd64,linux/arm64 + push: true + tags: ghcr.io/digital-entropy/dokar-php/cli:8.3-slim + + build-fpm: + needs: build-cli + runs-on: ubuntu-latest + steps: + - + name: Checkout + uses: actions/checkout@v4 + - + name: Set up QEMU + uses: docker/setup-qemu-action@v3 + - + name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + - + name: Login to GitHub Container Registry + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ secrets.GHCR_USR }} + password: ${{ secrets.GHCR_PAT }} + - + name: Build and push + uses: docker/build-push-action@v6 + with: + context: ubuntu/fpm/ + platforms: linux/amd64,linux/arm64 + push: true + tags: ghcr.io/digital-entropy/dokar-php/fpm:8.3-slim + + build-octane: + runs-on: ubuntu-latest + steps: + - + name: Checkout + uses: actions/checkout@v4 + - + name: Set up QEMU + uses: docker/setup-qemu-action@v3 + - + name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + - + name: Login to GitHub Container Registry + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ secrets.GHCR_USR }} + password: ${{ secrets.GHCR_PAT }} + - + name: Build and push + uses: docker/build-push-action@v6 + with: + context: ubuntu/octane/ + platforms: linux/amd64,linux/arm64 + push: true + tags: ghcr.io/digital-entropy/dokar-php/octane:8.3-slim + + build-nginx: + needs: build-fpm + runs-on: ubuntu-latest + steps: + - + name: Checkout + uses: actions/checkout@v4 + - + name: Set up QEMU + uses: docker/setup-qemu-action@v3 + - + name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + - + name: Login to GitHub Container Registry + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ secrets.GHCR_USR }} + password: ${{ secrets.GHCR_PAT }} + - + name: Build and push + uses: docker/build-push-action@v6 + with: + context: ubuntu/nginx/ + platforms: linux/amd64,linux/arm64 + push: true + tags: ghcr.io/digital-entropy/dokar-php/nginx:8.3-slim diff --git a/.github/workflows/ci.yml b/.github/workflows/ci-ubuntu.yml similarity index 92% rename from .github/workflows/ci.yml rename to .github/workflows/ci-ubuntu.yml index ae10f1d..39e277f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci-ubuntu.yml @@ -9,7 +9,7 @@ on: jobs: build-cli: - runs-on: ubuntu-22.04 + runs-on: ubuntu-latest steps: - name: Checkout @@ -31,14 +31,14 @@ jobs: name: Build and push uses: docker/build-push-action@v6 with: - context: cli/ + context: ubuntu/cli/ platforms: linux/amd64,linux/arm64 push: true tags: ghcr.io/digital-entropy/dokar-php/cli:8.3 build-fpm: needs: build-cli - runs-on: ubuntu-22.04 + runs-on: ubuntu-latest steps: - name: Checkout @@ -60,13 +60,13 @@ jobs: name: Build and push uses: docker/build-push-action@v6 with: - context: fpm/ + context: ubuntu/fpm/ platforms: linux/amd64,linux/arm64 push: true tags: ghcr.io/digital-entropy/dokar-php/fpm:8.3 build-octane: - runs-on: ubuntu-22.04 + runs-on: ubuntu-latest steps: - name: Checkout @@ -88,14 +88,14 @@ jobs: name: Build and push uses: docker/build-push-action@v6 with: - context: octane/ + context: ubuntu/octane/ platforms: linux/amd64,linux/arm64 push: true tags: ghcr.io/digital-entropy/dokar-php/octane:8.3 build-nginx: needs: build-fpm - runs-on: ubuntu-22.04 + runs-on: ubuntu-latest steps: - name: Checkout @@ -117,7 +117,7 @@ jobs: name: Build and push uses: docker/build-push-action@v6 with: - context: nginx/ + context: ubuntu/nginx/ platforms: linux/amd64,linux/arm64 push: true tags: ghcr.io/digital-entropy/dokar-php/nginx:8.3 diff --git a/README.md b/README.md index 2b72699..2363711 100644 --- a/README.md +++ b/README.md @@ -3,11 +3,14 @@ DOKAR PHP PHP 8.3 of dokar-php -There is 4 variant in this images. +### There are 4 flavors in this image -| Variant | Description | Usage | +| Flavor | Description | Usage | | --- | --- | --- | | Only CLI | Provide only php-cli. This image can be useful to run such as `laravel-horizon, laravel-websocket, tinker`. | `docker pull ghcr.io/digital-entropy/dokar-php/cli:8.3` | -| Only PHP-FPM | Provide php-fpm from php-cli variant. This image listen on `fastcgi 0.0.0.0:9008`. | `docker pull ghcr.io/digital-entropy/dokar-php/fpm:8.3` | +| Only PHP-FPM | Provide php-fpm from php-cli. This image listen on `fastcgi 0.0.0.0:9008`. | `docker pull ghcr.io/digital-entropy/dokar-php/fpm:8.3` | | With Nginx | Production ready php image that use nginx as web server. This image will serve `/var/www/public` directory. | `docker pull ghcr.io/digital-entropy/dokar-php/nginx:8.3` | Octane | Crafted for running octane with `swoole` driver. use `DOCKER_WORKERS=` env to define specific worker you need.| `docker pull ghcr.io/digital-entropy/dokar-php/octane:8.3` + +> Dokar PHP by default is using Ubuntu image, but we also provide Alpine image. +> You can add `-slim` in tag to use Alpine based image. e.g., `docker pull ghcr.io/digital-entropy/dokar-php/octane:8.3-slim` \ No newline at end of file diff --git a/slim/cli/Dockerfile b/slim/cli/Dockerfile new file mode 100644 index 0000000..9e2473e --- /dev/null +++ b/slim/cli/Dockerfile @@ -0,0 +1,26 @@ +FROM alpine:3 + +LABEL org.opencontainers.image.source=https://github.com/digital-entropy/dokar-php +LABEL org.opencontainers.image.branch=8.3 + +ENV TERM=linux + +ENV TZ=UTC + +RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone + +RUN apk update \ + && apk add --repository=https://dl-cdn.alpinelinux.org/alpine/edge/testing gosu \ + && apk add bash curl ca-certificates zip unzip git sqlite libcap libpng-dev \ + php83 php83-dev php83-gd php83-curl php83-soap \ + php83-sqlite3 php83-pgsql php83-mysqli \ + php83-mbstring php83-xml php83-zip php83-bcmath \ + php83-intl php83-ldap php83-pecl-igbinary php83-pecl-redis \ + composer \ + && apk cache clean \ + && rm -rf /var/cache/apk/* /tmp/* /var/tmp/* + +RUN composer global require --quiet --no-ansi laravel/envoy \ + && composer clear-cache --quiet \ + && ln -s /root/.composer/vendor/laravel/envoy/bin/envoy /usr/bin/envoy + diff --git a/slim/fpm/Dockerfile b/slim/fpm/Dockerfile new file mode 100644 index 0000000..723a9aa --- /dev/null +++ b/slim/fpm/Dockerfile @@ -0,0 +1,18 @@ +FROM ghcr.io/digital-entropy/dokar-php/cli:8.3-slim + +LABEL org.opencontainers.image.source=https://github.com/digital-entropy/dokar-php +LABEL org.opencontainers.image.branch=8.3 + +# Install FPM +RUN apk update \ + && apk add php83-fpm \ + && apk cache clean \ + && rm -rf /var/cache/apk/* /tmp/* /var/tmp/* + +# PHP-FPM packages need a nudge to make them docker-friendly +COPY overrides.conf /etc/php/8.3/fpm/pool.d/z-overrides.conf + +# PHP-FPM has really dirty logs, certainly not good for dockerising +# The following startup script contains some magic to clean these up +COPY php-fpm-startup /usr/bin/php-fpm +CMD /usr/bin/php-fpm diff --git a/fpm/overrides.conf b/slim/fpm/overrides.conf similarity index 100% rename from fpm/overrides.conf rename to slim/fpm/overrides.conf diff --git a/fpm/php-fpm-startup b/slim/fpm/php-fpm-startup similarity index 100% rename from fpm/php-fpm-startup rename to slim/fpm/php-fpm-startup diff --git a/slim/nginx/Dockerfile b/slim/nginx/Dockerfile new file mode 100644 index 0000000..efb4406 --- /dev/null +++ b/slim/nginx/Dockerfile @@ -0,0 +1,41 @@ +FROM ghcr.io/digital-entropy/dokar-php/fpm:8.3-slim + +LABEL org.opencontainers.image.source=https://github.com/digital-entropy/dokar-php +LABEL org.opencontainers.image.branch=8.3 + +RUN apk update \ + && apk add nginx supervisor \ + && apk cache clean \ + && rm -rf /var/cache/apk/* /tmp/* /var/tmp/* \ + && rm /etc/nginx/http.d/* + +RUN mkdir -p /var/www/public + +COPY index.php /var/www/public + +WORKDIR /var/www + +COPY site.conf /etc/nginx/http.d/site.conf + +COPY supervisor /etc/supervisor + +# Add a non-root user to prevent files being created with root permissions on host machine. +ONBUILD ARG USER_CONTAINER=dokar +ONBUILD ENV USER_CONTAINER=${USER_CONTAINER} +ONBUILD ARG PUID=1000 +ONBUILD ENV PUID=${PUID} +ONBUILD ARG PGID=1000 +ONBUILD ENV PGID=${PGID} + +ONBUILD RUN if [ "${PGID}" != "0" ] && [ "${PUID}" != "0" ]; then \ + (grep -q ":${PGID}:" /etc/group && old_group=$(getent group ${PGID} | cut -d: -f1) && delgroup ${old_group} \ + || addgroup -g ${PGID} ${USER_CONTAINER}) \ + && (grep -q ":${PUID}:" /etc/passwd && old_user=$(getent passwd ${PUID} | cut -d: -f1) && deluser --remove-home ${old_user} \ + || adduser -h /home/${USER_CONTAINER} -G ${USER_CONTAINER} -u ${PUID} ${USER_CONTAINER} -D) \ + fi + +EXPOSE 80 + +STOPSIGNAL SIGTERM + +CMD ["/usr/bin/supervisord", "-n", "-c", "/etc/supervisor/supervisord.conf"] diff --git a/nginx/index.php b/slim/nginx/index.php similarity index 100% rename from nginx/index.php rename to slim/nginx/index.php diff --git a/nginx/site.conf b/slim/nginx/site.conf similarity index 100% rename from nginx/site.conf rename to slim/nginx/site.conf diff --git a/nginx/supervisor/conf.d/nginx.conf b/slim/nginx/supervisor/conf.d/nginx.conf similarity index 100% rename from nginx/supervisor/conf.d/nginx.conf rename to slim/nginx/supervisor/conf.d/nginx.conf diff --git a/nginx/supervisor/conf.d/php-fpm.conf b/slim/nginx/supervisor/conf.d/php-fpm.conf similarity index 100% rename from nginx/supervisor/conf.d/php-fpm.conf rename to slim/nginx/supervisor/conf.d/php-fpm.conf diff --git a/nginx/supervisor/supervisord.conf b/slim/nginx/supervisor/supervisord.conf similarity index 100% rename from nginx/supervisor/supervisord.conf rename to slim/nginx/supervisor/supervisord.conf diff --git a/slim/octane/Dockerfile b/slim/octane/Dockerfile new file mode 100644 index 0000000..4eab9c6 --- /dev/null +++ b/slim/octane/Dockerfile @@ -0,0 +1,58 @@ +FROM alpine:3 + +LABEL org.opencontainers.image.source=https://github.com/digital-entropy/dokar-php +LABEL org.opencontainers.image.branch=8.3 + +ENV TERM=linux + +ENV TZ=UTC + +RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone + +RUN apk update \ + && apk add --repository=https://dl-cdn.alpinelinux.org/alpine/edge/testing gosu \ + && apk add bash curl ca-certificates zip unzip git sqlite libcap libpng-dev \ + php83 php83-dev php83-gd php83-curl php83-soap \ + php83-sqlite3 php83-pgsql php83-mysqli \ + php83-mbstring php83-xml php83-zip php83-bcmath \ + php83-intl php83-ldap \ + php83-pecl-igbinary php83-pecl-redis php83-pecl-swoole + +RUN apk add composer \ + && composer global require --quiet --no-ansi laravel/envoy \ + && composer clear-cache --quiet \ + && ln -s /root/.composer/vendor/laravel/envoy/bin/envoy /usr/bin/envoy + +RUN apk add nodejs npm \ + && npm install -g chokidar pnpm + +RUN apk cache clean \ + && rm -rf /var/cache/apk/* /tmp/* /var/tmp/* + +COPY runner.sh /runner.sh + +# Add a non-root user to prevent files being created with root permissions on host machine. +ONBUILD ARG USER_CONTAINER=dokar +ONBUILD ENV USER_CONTAINER=${USER_CONTAINER} +ONBUILD ARG PUID=1000 +ONBUILD ENV PUID=${PUID} +ONBUILD ARG PGID=1000 +ONBUILD ENV PGID=${PGID} + +# Convert to alpine +ONBUILD RUN if [ "${PGID}" != "0" ] && [ "${PUID}" != "0" ]; then \ + (grep -q ":${PGID}:" /etc/group && old_group=$(getent group ${PGID} | cut -d: -f1) && delgroup ${old_group} \ + || addgroup -g ${PGID} ${USER_CONTAINER}) \ + && (grep -q ":${PUID}:" /etc/passwd && old_user=$(getent passwd ${PUID} | cut -d: -f1) && deluser --remove-home ${old_user} \ + || adduser -h /home/${USER_CONTAINER} -G ${USER_CONTAINER} -u ${PUID} ${USER_CONTAINER} -D) \ + fi + +EXPOSE 80 + +WORKDIR /var/www + +ARG DOCKER_ENV=production +ENV DOCKER_ENV=${DOCKER_ENV} +ENV DOCKER_WORKERS=auto + +CMD ["/runner.sh"] diff --git a/slim/octane/runner.sh b/slim/octane/runner.sh new file mode 100755 index 0000000..07d3c87 --- /dev/null +++ b/slim/octane/runner.sh @@ -0,0 +1,29 @@ +#!/usr/bin/env bash + +set -Eeo pipefail +set -o errexit # Used to exit upon error, avoiding cascading errors + +IFS=$'\n\t' + +cd /var/www + +if [ -d vendor ]; then + echo "vendor ok!" +else + composer install +fi + +echo "run on '$DOCKER_ENV' environment!" +echo "run with '$DOCKER_WORKERS' workers!" + +if [ $DOCKER_ENV == "production" ]; then + php artisan octane:start --host=0.0.0.0 --port=80 --workers=$DOCKER_WORKERS --task-workers=$DOCKER_WORKERS +else + if [ -d node_modules ]; then + echo "node_modules ok!" + else + npm install + fi + + php artisan octane:start --host=0.0.0.0 --watch --port=80 --workers=$DOCKER_WORKERS --task-workers=$DOCKER_WORKERS +fi diff --git a/cli/Dockerfile b/ubuntu/cli/Dockerfile similarity index 97% rename from cli/Dockerfile rename to ubuntu/cli/Dockerfile index 037cead..0722365 100644 --- a/cli/Dockerfile +++ b/ubuntu/cli/Dockerfile @@ -1,6 +1,7 @@ FROM ubuntu:noble LABEL org.opencontainers.image.source=https://github.com/digital-entropy/dokar-php +LABEL org.opencontainers.image.branch=8.3 ENV DEBIAN_FRONTEND=noninteractive diff --git a/fpm/Dockerfile b/ubuntu/fpm/Dockerfile similarity index 94% rename from fpm/Dockerfile rename to ubuntu/fpm/Dockerfile index 19cf46f..5fda2a0 100644 --- a/fpm/Dockerfile +++ b/ubuntu/fpm/Dockerfile @@ -1,6 +1,7 @@ FROM ghcr.io/digital-entropy/dokar-php/cli:8.3 LABEL org.opencontainers.image.source=https://github.com/digital-entropy/dokar-php +LABEL org.opencontainers.image.branch=8.3 # Install FPM RUN export DEBIAN_FRONTEND=noninteractive \ diff --git a/ubuntu/fpm/overrides.conf b/ubuntu/fpm/overrides.conf new file mode 100644 index 0000000..86bc35a --- /dev/null +++ b/ubuntu/fpm/overrides.conf @@ -0,0 +1,16 @@ +[global] +; Override default pid file +pid = /run/php-fpm.pid + +; Avoid logs being sent to syslog +error_log = /dev/stderr + +[www] +listen = 0.0.0.0:9008 + +; Redirect logs to stdout - FPM closes /dev/std* on startup +access.log = /dev/stdout +catch_workers_output = yes + +; Required to allow config-by-environment +clear_env = no diff --git a/ubuntu/fpm/php-fpm-startup b/ubuntu/fpm/php-fpm-startup new file mode 100755 index 0000000..195d3da --- /dev/null +++ b/ubuntu/fpm/php-fpm-startup @@ -0,0 +1,2 @@ +#!/usr/bin/env bash +/usr/sbin/php-fpm8.3 -F -O 2>&1 | sed -u 's,.*: \"\(.*\)$,\1,'| sed -u 's,"$,,' 1>&1 diff --git a/nginx/Dockerfile b/ubuntu/nginx/Dockerfile similarity index 96% rename from nginx/Dockerfile rename to ubuntu/nginx/Dockerfile index df3bd5b..80ce3bd 100644 --- a/nginx/Dockerfile +++ b/ubuntu/nginx/Dockerfile @@ -1,6 +1,7 @@ FROM ghcr.io/digital-entropy/dokar-php/fpm:8.3 LABEL org.opencontainers.image.source=https://github.com/digital-entropy/dokar-php +LABEL org.opencontainers.image.branch=8.3 RUN export DEBIAN_FRONTEND=noninteractive \ && apt-get update \ diff --git a/ubuntu/nginx/index.php b/ubuntu/nginx/index.php new file mode 100644 index 0000000..e974c40 --- /dev/null +++ b/ubuntu/nginx/index.php @@ -0,0 +1 @@ +