diff --git a/Dockerfile b/Dockerfile index 2f13b5e..e0821a5 100644 --- a/Dockerfile +++ b/Dockerfile @@ -74,6 +74,6 @@ USER 1000:1000 # Entrypoint prepares the database. ENTRYPOINT ["/rails/bin/docker-entrypoint"] -# Start either web server or job worker based on WORKER env var +# Start either web server or job worker based on PROCESS_TYPE env var EXPOSE 80 -CMD ["./bin/thrust", "./bin/rails", "server"] +CMD ["./bin/start-process"] diff --git a/Procfile b/Procfile new file mode 100644 index 0000000..f69c5b1 --- /dev/null +++ b/Procfile @@ -0,0 +1,2 @@ +web: bundle exec rails server -b 0.0.0.0 -p $PORT +worker: bundle exec good_job start diff --git a/bin/start-process b/bin/start-process new file mode 100755 index 0000000..c8bbcd8 --- /dev/null +++ b/bin/start-process @@ -0,0 +1,18 @@ +#!/bin/bash -e + +# Start the appropriate process based on PROCESS_TYPE environment variable +case "$PROCESS_TYPE" in + web) + echo "Starting web server..." + exec ./bin/thrust ./bin/rails server -b 0.0.0.0 -p ${PORT:-80} + ;; + worker) + echo "Starting GoodJob worker..." + exec bundle exec good_job start + ;; + *) + echo "Unknown PROCESS_TYPE: $PROCESS_TYPE" + echo "Valid options: web, worker" + exit 1 + ;; +esac diff --git a/config/initializers/good_job.rb b/config/initializers/good_job.rb index a05ff90..a448eb4 100644 --- a/config/initializers/good_job.rb +++ b/config/initializers/good_job.rb @@ -9,7 +9,7 @@ Rails.application.configure do config.good_job.poll_interval = -1 # Disable polling config.good_job.execution_mode = :inline # Run jobs inline in development else - config.good_job.execution_mode = :async + config.good_job.execution_mode = :external end config.good_job.enable_cron = Rails.env.production? diff --git a/docker-compose.coolify.yml b/docker-compose.coolify.yml new file mode 100644 index 0000000..2491378 --- /dev/null +++ b/docker-compose.coolify.yml @@ -0,0 +1,24 @@ +version: '3.8' + +services: + web: + build: . + environment: + - PROCESS_TYPE=web + - PORT=80 + - RAILS_ENV=production + - DATABASE_URL=${DATABASE_URL} + - RAILS_MASTER_KEY=${RAILS_MASTER_KEY} + ports: + - "80:80" + depends_on: + - worker + + worker: + build: . + environment: + - PROCESS_TYPE=worker + - RAILS_ENV=production + - DATABASE_URL=${DATABASE_URL} + - RAILS_MASTER_KEY=${RAILS_MASTER_KEY} + # No ports exposed for worker