add source code and readme
This commit is contained in:
37
build/bookwyrm/bookwyrm-worker/Dockerfile
Normal file
37
build/bookwyrm/bookwyrm-worker/Dockerfile
Normal file
@@ -0,0 +1,37 @@
|
||||
# BookWyrm Worker Container - Production Optimized
|
||||
# Celery background task processor
|
||||
|
||||
FROM bookwyrm-base AS bookwyrm-worker
|
||||
|
||||
# Switch to root for system package installation
|
||||
USER root
|
||||
|
||||
# Install only supervisor for worker management
|
||||
RUN apt-get update && apt-get install -y --no-install-recommends \
|
||||
supervisor \
|
||||
&& rm -rf /var/lib/apt/lists/* \
|
||||
&& apt-get clean \
|
||||
&& apt-get autoremove -y
|
||||
|
||||
# Install Celery in virtual environment
|
||||
RUN /opt/venv/bin/pip install --no-cache-dir celery[redis]
|
||||
|
||||
# Copy worker-specific configuration
|
||||
COPY supervisord-worker.conf /etc/supervisor/conf.d/supervisord.conf
|
||||
COPY entrypoint-worker.sh /entrypoint.sh
|
||||
|
||||
# Set permissions efficiently
|
||||
RUN chmod +x /entrypoint.sh \
|
||||
&& mkdir -p /var/log/supervisor /var/log/celery \
|
||||
&& chown -R bookwyrm:bookwyrm /var/log/celery \
|
||||
&& chown -R bookwyrm:bookwyrm /app
|
||||
|
||||
# Health check for worker
|
||||
HEALTHCHECK --interval=60s --timeout=10s --start-period=60s --retries=3 \
|
||||
CMD /opt/venv/bin/celery -A celerywyrm inspect ping -d celery@$HOSTNAME || exit 1
|
||||
|
||||
# Run as root to manage celery via supervisor
|
||||
USER root
|
||||
|
||||
ENTRYPOINT ["/entrypoint.sh"]
|
||||
CMD ["supervisord", "-c", "/etc/supervisor/conf.d/supervisord.conf"]
|
||||
42
build/bookwyrm/bookwyrm-worker/entrypoint-worker.sh
Normal file
42
build/bookwyrm/bookwyrm-worker/entrypoint-worker.sh
Normal file
@@ -0,0 +1,42 @@
|
||||
#!/bin/bash
|
||||
# BookWyrm Worker Container Entrypoint
|
||||
# Simplified - init containers handle Redis readiness
|
||||
|
||||
set -e
|
||||
|
||||
echo "[$(date +'%Y-%m-%d %H:%M:%S')] Starting BookWyrm Worker Container..."
|
||||
|
||||
# Only handle worker-specific tasks (Redis handled by init container)
|
||||
|
||||
# Create temp directory for worker processes
|
||||
mkdir -p /tmp/bookwyrm
|
||||
chown bookwyrm:bookwyrm /tmp/bookwyrm
|
||||
|
||||
# Clean up any stale supervisor sockets and pid files
|
||||
rm -f /tmp/bookwyrm-supervisor.sock
|
||||
rm -f /tmp/supervisord-worker.pid
|
||||
|
||||
# Test Celery connectivity (quick verification)
|
||||
echo "[$(date +'%Y-%m-%d %H:%M:%S')] Testing Celery broker connectivity..."
|
||||
python -c "
|
||||
from celery import Celery
|
||||
import os
|
||||
|
||||
app = Celery('bookwyrm')
|
||||
app.config_from_object('django.conf:settings', namespace='CELERY')
|
||||
|
||||
try:
|
||||
# Test broker connection
|
||||
with app.connection() as conn:
|
||||
conn.ensure_connection(max_retries=3)
|
||||
print('✓ Celery broker connection successful')
|
||||
except Exception as e:
|
||||
print(f'✗ Celery broker connection failed: {e}')
|
||||
exit(1)
|
||||
"
|
||||
|
||||
echo "[$(date +'%Y-%m-%d %H:%M:%S')] BookWyrm worker container initialization completed"
|
||||
echo "[$(date +'%Y-%m-%d %H:%M:%S')] Starting worker services..."
|
||||
|
||||
# Execute the provided command (usually supervisord)
|
||||
exec "$@"
|
||||
53
build/bookwyrm/bookwyrm-worker/supervisord-worker.conf
Normal file
53
build/bookwyrm/bookwyrm-worker/supervisord-worker.conf
Normal file
@@ -0,0 +1,53 @@
|
||||
[supervisord]
|
||||
nodaemon=true
|
||||
logfile=/dev/stdout
|
||||
logfile_maxbytes=0
|
||||
pidfile=/tmp/supervisord-worker.pid
|
||||
silent=false
|
||||
|
||||
[unix_http_server]
|
||||
file=/tmp/bookwyrm-supervisor.sock
|
||||
chmod=0700
|
||||
|
||||
[supervisorctl]
|
||||
serverurl=unix:///tmp/bookwyrm-supervisor.sock
|
||||
|
||||
[rpcinterface:supervisor]
|
||||
supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface
|
||||
|
||||
# Celery Worker - General background tasks
|
||||
[program:celery-worker]
|
||||
command=celery -A celerywyrm worker --loglevel=info --concurrency=2 --queues=high_priority,medium_priority,low_priority,streams,images,suggested_users,email,connectors,lists,inbox,imports,import_triggered,broadcast,misc
|
||||
directory=/app
|
||||
user=bookwyrm
|
||||
autostart=true
|
||||
autorestart=true
|
||||
startsecs=10
|
||||
startretries=3
|
||||
stdout_logfile=/dev/stdout
|
||||
stdout_logfile_maxbytes=0
|
||||
stderr_logfile=/dev/stderr
|
||||
stderr_logfile_maxbytes=0
|
||||
environment=CONTAINER_TYPE="worker"
|
||||
|
||||
# Celery Beat - Moved to separate deployment (deployment-beat.yaml)
|
||||
# This eliminates port conflicts and allows proper scaling of workers
|
||||
# while maintaining single beat scheduler instance
|
||||
|
||||
# Celery Flower - Task monitoring (disabled by default, no external access needed)
|
||||
# [program:celery-flower]
|
||||
# command=celery -A celerywyrm flower --port=5555 --address=0.0.0.0
|
||||
# directory=/app
|
||||
# user=bookwyrm
|
||||
# autostart=false
|
||||
# autorestart=true
|
||||
# startsecs=10
|
||||
# startretries=3
|
||||
# stdout_logfile=/dev/stdout
|
||||
# stdout_logfile_maxbytes=0
|
||||
# stderr_logfile=/dev/stderr
|
||||
# stderr_logfile_maxbytes=0
|
||||
# environment=PATH="/app/venv/bin",CONTAINER_TYPE="worker"
|
||||
|
||||
# Log rotation no longer needed since logs go to stdout/stderr
|
||||
# Kubernetes handles log rotation automatically
|
||||
Reference in New Issue
Block a user