From adb79db8f5c9a2b6e547c0db1224d8bfbe12865a Mon Sep 17 00:00:00 2001 From: Brock H Caldwell Date: Tue, 4 Nov 2025 12:19:37 -0600 Subject: [PATCH] feat: allows configuring the worker service and processes via command options and env vars --- bash/build_base.sh | 9 ++++++-- docker/Dockerfile.base.worker | 40 +++++++++++++++++++++------------- docker/Dockerfile.worker | 33 ++++++++-------------------- docker/worker/supervisord.conf | 33 ---------------------------- 4 files changed, 41 insertions(+), 74 deletions(-) diff --git a/bash/build_base.sh b/bash/build_base.sh index 875a35f..9e48da3 100755 --- a/bash/build_base.sh +++ b/bash/build_base.sh @@ -1,14 +1,19 @@ # torsearch-app is built from this base export APP_FRANKENPHP_TAG=php8.4 -docker buildx build --platform=linux/amd64 -f docker/Dockerfile.base.app -t code.caldwell.digital/home/torsearch-base:${APP_FRANKENPHP_TAG} -t code.caldwell.digital/home/torsearch-base:latest --build-arg "FRANKENPHP_TAG=${APP_FRANKENPHP_TAG}" . +docker buildx build --platform=linux/amd64,linux/arm64 -f docker/Dockerfile.base.app -t code.caldwell.digital/home/torsearch-base:${APP_FRANKENPHP_TAG} -t code.caldwell.digital/home/torsearch-base:latest --build-arg "FRANKENPHP_TAG=${APP_FRANKENPHP_TAG}" . docker push code.caldwell.digital/home/torsearch-base:${APP_FRANKENPHP_TAG} docker push code.caldwell.digital/home/torsearch-base:latest # torsearch-worker & torsearch-scheduler are built from this base export WORKER_FRANKENPHP_TAG=php8.4-alpine -docker buildx build --platform=linux/amd64 -f docker/Dockerfile.base.worker -t code.caldwell.digital/home/torsearch-base-worker:${WORKER_FRANKENPHP_TAG} -t code.caldwell.digital/home/torsearch-base-worker:latest --build-arg "FRANKENPHP_TAG=${WORKER_FRANKENPHP_TAG}" . +docker buildx build --platform=linux/amd64,linux/arm64 -f docker/Dockerfile.base.worker -t code.caldwell.digital/home/torsearch-base-worker:${WORKER_FRANKENPHP_TAG} -t code.caldwell.digital/home/torsearch-base-worker:latest --build-arg "FRANKENPHP_TAG=${WORKER_FRANKENPHP_TAG}" . docker push code.caldwell.digital/home/torsearch-base-worker:${WORKER_FRANKENPHP_TAG} docker push code.caldwell.digital/home/torsearch-base-worker:latest +# torsearch-worker-supervisord +export ALPINE_VERSION=3.22 + +docker buildx build --platform=linux/amd64,linux/arm64 -f docker/Dockerfile.base.worker -t code.caldwell.digital/home/torsearch-base-worker-supervisord:latest --build-arg "ALPINE_VERSION=${ALPINE_VERSION}" . +docker push code.caldwell.digital/home/torsearch-base-worker-supervisord:latest diff --git a/docker/Dockerfile.base.worker b/docker/Dockerfile.base.worker index 668e6ce..8432d23 100644 --- a/docker/Dockerfile.base.worker +++ b/docker/Dockerfile.base.worker @@ -1,19 +1,29 @@ -ARG FRANKENPHP_TAG +##### +# This version of Torsearch runs the scheduler, downloader, and worker +# in a single container. Each process is managerd by supervisord +# and can be configured via environment variables and more +# than one of these containers cans till be run. +##### +ARG ALPINE_VERSION="3.22" +FROM alpine:${ALPINE_VERSION} AS build_stage -FROM dunglas/frankenphp:${FRANKENPHP_TAG} +RUN apk add --no-cache \ + curl \ + php84 \ + php84-curl \ + php84-fileinfo \ + php84-gd \ + php84-mbstring \ + php84-mysqli \ + php84-opcache \ + php84-openssl \ + php84-pdo_mysql \ + supervisor -ENV SERVER_NAME=":80" -ENV CADDY_GLOBAL_OPTIONS="auto_https off" -ENV APP_RUNTIME="Runtime\\FrankenPhpSymfony\\Runtime" +RUN ln -s /usr/bin/php84 /usr/bin/php -ARG APP_VERSION="0.dev" -ENV APP_VERSION="${APP_VERSION}" +RUN mkdir -p /etc/supervisor/conf.d -RUN install-php-extensions \ - pdo_mysql \ - gd \ - intl \ - zip \ - opcache - -RUN apk add --no-cache wget +# We start supervisord and supervisord starts +# respective service in the configuration file. +ENTRYPOINT ["/app/bin/console", "init:worker"] diff --git a/docker/Dockerfile.worker b/docker/Dockerfile.worker index 4a80979..82b1a11 100644 --- a/docker/Dockerfile.worker +++ b/docker/Dockerfile.worker @@ -9,33 +9,18 @@ ARG APP_VERSION="latest" FROM code.caldwell.digital/home/torsearch-app:${APP_VERSION} AS base_image -FROM alpine:3.22 AS build_stage +FROM code.caldwell.digital/home/torsearch-base-worker-supervisord:latest -COPY --from=base_image --chown=1000:1000 /app /app +ENV APP_VERSION=${APP_VERSION} -RUN apk add --no-cache \ - curl \ - nginx \ - php84 \ - php84-ctype \ - php84-curl \ - php84-dom \ - php84-fileinfo \ - php84-fpm \ - php84-gd \ - php84-mbstring \ - php84-mysqli \ - php84-opcache \ - php84-openssl \ - php84-pdo_mysql \ - php84-tokenizer \ - supervisor - -RUN ln -s /usr/bin/php84 /usr/bin/php - -COPY docker/worker/supervisord.conf /etc/supervisor/conf.d/supervisord.conf -COPY docker/ app/docker +COPY --from=base_image --chown=1000:1000 /app /app +COPY docker/ /app/docker # We start supervisord and supervisord starts # respective service in the configuration file. ENTRYPOINT ["/app/bin/console", "init:worker"] + +# Message transports can be enabled by passing them as command options. +# Inlcluding a number with the option will start that amount of processes +# for the transport. Not supplying a number will default to 1. +# --download --monitor OR --download 2 --monitor diff --git a/docker/worker/supervisord.conf b/docker/worker/supervisord.conf index d20b963..bf3a927 100644 --- a/docker/worker/supervisord.conf +++ b/docker/worker/supervisord.conf @@ -3,36 +3,3 @@ nodaemon=true logfile=/dev/null logfile_maxbytes=0 pidfile=/run/supervisord.pid - -[program:torsearch-worker] -command=/app/bin/console messenger:consume async -vv --time-limit 3600 -numprocs=1 -stdout_logfile=/dev/stdout -stdout_logfile_maxbytes=0 -stderr_logfile=/dev/stderr -stderr_logfile_maxbytes=0 -autorestart=true -startretries=3 -process_name=%(program_name)s_%(process_num)02d - -[program:torsearch-worker] -command=/app/bin/console messenger:consume download -vv --time-limit 3600 -numprocs=1 -stdout_logfile=/dev/stdout -stdout_logfile_maxbytes=0 -stderr_logfile=/dev/stderr -stderr_logfile_maxbytes=0 -autorestart=true -startretries=3 -process_name=%(program_name)s_%(process_num)02d - -[program:torsearch-scheduler] -command=/app/bin/console messenger:consume scheduler_monitor monitor -vv --time-limit 21600 -numprocs=1 -stdout_logfile=/dev/stdout -stdout_logfile_maxbytes=0 -stderr_logfile=/dev/stderr -stderr_logfile_maxbytes=0 -autorestart=true -startretries=3 -process_name=%(program_name)s_%(process_num)02d