add worker dockerfile

This commit is contained in:
24c02 2026-01-22 15:00:40 -05:00
parent 0bc70de3e5
commit 0a0547e024
2 changed files with 79 additions and 1 deletions

78
Dockerfile.worker Normal file
View file

@ -0,0 +1,78 @@
# syntax=docker/dockerfile:1
# check=error=true;skip=SecretsUsedInArgOrEnv
# Worker Dockerfile for running GoodJob background jobs
# Build: docker build -f Dockerfile.worker -t theseus-worker .
# Run: docker run -d -e RAILS_MASTER_KEY=<value from config/master.key> --name theseus-worker theseus-worker
# Make sure RUBY_VERSION matches the Ruby version in .ruby-version
ARG RUBY_VERSION=3.4.4
FROM docker.io/library/ruby:$RUBY_VERSION-slim
# Set production environment
ENV RAILS_ENV="production" \
BUNDLE_DEPLOYMENT="1" \
BUNDLE_PATH="/usr/local/bundle" \
BUNDLE_WITHOUT="development"
# Install base packages and build dependencies
RUN apt-get update -qq && apt-get install --no-install-recommends -y \
curl \
libjemalloc2 \
libvips \
postgresql-client \
wget \
build-essential \
git \
libpq-dev \
node-gyp \
pkg-config \
python-is-python3 \
imagemagick \
libmagickwand-dev \
ghostscript \
libyaml-dev \
chromium
RUN sed -i '/disable ghostscript format types/,+6d' /etc/ImageMagick-6/policy.xml
# Install Node.js and Yarn
ARG NODE_VERSION=23.6.0
ARG YARN_VERSION=1.22.22
ENV PATH=/usr/local/node/bin:$PATH
RUN curl -sL https://github.com/nodenv/node-build/archive/master.tar.gz | tar xz -C /tmp/ && \
/tmp/node-build-master/bin/node-build "${NODE_VERSION}" /usr/local/node && \
npm install -g yarn@$YARN_VERSION && \
rm -rf /tmp/node-build-master
# Rails app lives here
WORKDIR /rails
# Install application gems
COPY Gemfile Gemfile.lock ./
RUN bundle install && \
rm -rf ~/.bundle/ "${BUNDLE_PATH}"/ruby/*/cache "${BUNDLE_PATH}"/ruby/*/bundler/gems/*/.git && \
bundle exec bootsnap precompile --gemfile
# Install node modules
COPY package.json yarn.lock ./
RUN yarn install --frozen-lockfile
# Copy application code
COPY . .
# Precompile bootsnap code (skip asset precompilation for worker)
RUN bundle exec bootsnap precompile app/ lib/ && \
rm -rf node_modules
# Run and own only the runtime files as a non-root user for security
RUN groupadd --system --gid 1000 rails && \
useradd rails --uid 1000 --gid 1000 --create-home --shell /bin/bash && \
chown -R rails:rails db log storage tmp
USER 1000:1000
# Entrypoint prepares the database.
ENTRYPOINT ["/rails/bin/docker-entrypoint"]
# Start GoodJob worker
CMD ["bundle", "exec", "good_job", "start"]

View file

@ -1,7 +1,7 @@
Rails.application.configure do
config.good_job.preserve_job_records = true
config.good_job.enable_cron = Rails.env.production?
config.good_job.execution_mode = :async
config.good_job.execution_mode = :external
config.good_job.cron = {
update_mailing_info: {