From 0a0547e0246afa2e8b03dd1150cf98b71663bc82 Mon Sep 17 00:00:00 2001 From: 24c02 <163450896+24c02@users.noreply.github.com> Date: Thu, 22 Jan 2026 15:00:40 -0500 Subject: [PATCH] add worker dockerfile --- Dockerfile.worker | 78 +++++++++++++++++++++++++++++++++ config/initializers/good_job.rb | 2 +- 2 files changed, 79 insertions(+), 1 deletion(-) create mode 100644 Dockerfile.worker diff --git a/Dockerfile.worker b/Dockerfile.worker new file mode 100644 index 0000000..1a70309 --- /dev/null +++ b/Dockerfile.worker @@ -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= --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"] diff --git a/config/initializers/good_job.rb b/config/initializers/good_job.rb index 1da4558..ccdbe0c 100644 --- a/config/initializers/good_job.rb +++ b/config/initializers/good_job.rb @@ -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: {