Fixes 5685 - Docker stack cannot run Rails without using the docker entrypoint
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
# Skip some content to avoid blowing up images with unneeded data.
|
||||
.git/
|
||||
.yarn/cache
|
||||
config/database.yml
|
||||
node_modules
|
||||
log/*.log
|
||||
tmp/
|
||||
|
||||
14
Dockerfile
14
Dockerfile
@@ -81,6 +81,15 @@ RUN bundle exec bootsnap precompile --gemfile app/ lib/
|
||||
# Final stage for app image
|
||||
FROM base
|
||||
|
||||
# Application variables with defaults matching the Zammad docker stack.
|
||||
ENV POSTGRESQL_DB=zammad_production \
|
||||
POSTGRESQL_HOST=zammad-postgresql \
|
||||
POSTGRESQL_PORT=5432 \
|
||||
POSTGRESQL_USER=zammad \
|
||||
POSTGRESQL_PASS=zammad \
|
||||
POSTGRESQL_OPTIONS=?pool=50 \
|
||||
RAILS_TRUSTED_PROXIES=127.0.0.1,::1
|
||||
|
||||
RUN groupadd --system --gid 1000 zammad && \
|
||||
useradd --create-home --home /opt/zammad --shell /bin/bash --uid 1000 --gid 1000 zammad
|
||||
|
||||
@@ -103,6 +112,5 @@ RUN ln -s "/opt/zammad/bin/docker-entrypoint" /docker-entrypoint.sh
|
||||
USER 1000:1000
|
||||
ENTRYPOINT ["/opt/zammad/bin/docker-entrypoint"]
|
||||
|
||||
# Set labels to help portainer.io admins to access the shell and rails console.
|
||||
LABEL io.portainer.commands.bash-via-entrypoint="/opt/zammad/bin/docker-entrypoint /bin/bash"
|
||||
LABEL io.portainer.commands.rails-console="/opt/zammad/bin/docker-entrypoint bundle exec rails c"
|
||||
# Set labels to help portainer.io admins to access rails console.
|
||||
LABEL io.portainer.commands.rails-console="bundle exec rails c"
|
||||
|
||||
@@ -2,6 +2,9 @@
|
||||
|
||||
set -o errexit
|
||||
|
||||
# See DOCKERFILE for common environment variables required for the application to run.
|
||||
#
|
||||
# The following variables are only used by the docker entrypoint script.
|
||||
: "${AUTOWIZARD_JSON:=''}"
|
||||
: "${AUTOWIZARD_RELATIVE_PATH:='tmp/auto_wizard.json'}"
|
||||
: "${ELASTICSEARCH_ENABLED:=true}"
|
||||
@@ -14,33 +17,13 @@ set -o errexit
|
||||
: "${NGINX_CLIENT_MAX_BODY_SIZE:=50M}"
|
||||
: "${NGINX_SERVER_NAME:=_}"
|
||||
: "${NGINX_SERVER_SCHEME:=\$scheme}"
|
||||
: "${POSTGRESQL_DB:=zammad_production}"
|
||||
: "${POSTGRESQL_DB_CREATE:=true}"
|
||||
: "${POSTGRESQL_HOST:=zammad-postgresql}"
|
||||
: "${POSTGRESQL_PORT:=5432}"
|
||||
: "${POSTGRESQL_USER:=zammad}"
|
||||
: "${POSTGRESQL_PASS:=zammad}"
|
||||
: "${POSTGRESQL_OPTIONS:=}"
|
||||
: "${RAILS_ENV:=production}"
|
||||
: "${RAILS_LOG_TO_STDOUT:=true}"
|
||||
: "${RAILS_TRUSTED_PROXIES:=127.0.0.1,::1}"
|
||||
: "${ZAMMAD_DIR:=/opt/zammad}"
|
||||
: "${ZAMMAD_RAILSSERVER_HOST:=zammad-railsserver}"
|
||||
: "${ZAMMAD_RAILSSERVER_PORT:=3000}"
|
||||
: "${ZAMMAD_WEBSOCKET_HOST:=zammad-websocket}"
|
||||
: "${ZAMMAD_WEBSOCKET_PORT:=6042}"
|
||||
: "${RESTORE_DIR:=/var/tmp/zammad/restore}"
|
||||
|
||||
# Support both ZAMMAD_WEB_CONCURRENCY (as recommended by the Zammad docker stack & documentation)
|
||||
# and WEB_CONCURRENCY (Zammad and Rails default).
|
||||
: "${ZAMMAD_WEB_CONCURRENCY:=0}"
|
||||
: "${WEB_CONCURRENCY:=${ZAMMAD_WEB_CONCURRENCY}}"
|
||||
export WEB_CONCURRENCY
|
||||
|
||||
ESCAPED_POSTGRESQL_PASS=$(echo "$POSTGRESQL_PASS" | sed -e 's/[\/&]/\\&/g')
|
||||
export ESCAPED_POSTGRESQL_PASS
|
||||
export DATABASE_URL="postgres://${POSTGRESQL_USER}:${ESCAPED_POSTGRESQL_PASS}@${POSTGRESQL_HOST}:${POSTGRESQL_PORT}/${POSTGRESQL_DB}${POSTGRESQL_OPTIONS}"
|
||||
|
||||
function check_no_restore_running {
|
||||
echo 'Checking for active restore operations...'
|
||||
until [ ! -d "${RESTORE_DIR}" ] || [ -z "$(ls "${RESTORE_DIR}")" ]; do
|
||||
@@ -165,7 +148,7 @@ elif [ "$1" = 'zammad-nginx' ]; then
|
||||
elif [ "$1" = 'zammad-railsserver' ]; then
|
||||
check_zammad_ready
|
||||
|
||||
echo "starting railsserver... with WEB_CONCURRENCY=${WEB_CONCURRENCY}"
|
||||
echo "starting railsserver..."
|
||||
|
||||
#shellcheck disable=SC2101
|
||||
exec bundle exec puma -b tcp://[::]:"${ZAMMAD_RAILSSERVER_PORT}" -e "${RAILS_ENV}"
|
||||
|
||||
17
config/pre_initializers/database_url.rb
Normal file
17
config/pre_initializers/database_url.rb
Normal file
@@ -0,0 +1,17 @@
|
||||
# Copyright (C) 2012-2025 Zammad Foundation, https://zammad-foundation.org/
|
||||
|
||||
#
|
||||
# Populate the DATABASE_URL environment variable if it is not already set, for environments like docker and kubernetes.
|
||||
#
|
||||
database_yml_path = File.expand_path('../../config/database.yml', __dir__)
|
||||
|
||||
if !File.exist?(database_yml_path) && ENV['DATABASE_URL'].blank?
|
||||
if %w[POSTGRESQL_HOST POSTGRESQL_PORT POSTGRESQL_USER POSTGRESQL_DB].any? { |var| ENV[var].blank? }
|
||||
warn 'Error: The database is not configured. Please provide either config/database.yml or the correct environment variables.'
|
||||
exit 1 # rubocop:disable Rails/Exit
|
||||
end
|
||||
|
||||
escaped_postgresql_pass = URI.encode_uri_component(ENV['POSTGRESQL_PASS'] || '')
|
||||
|
||||
ENV['DATABASE_URL'] = "postgres://#{ENV['POSTGRESQL_USER']}:#{escaped_postgresql_pass}@#{ENV['POSTGRESQL_HOST']}:#{ENV['POSTGRESQL_PORT']}/#{ENV['POSTGRESQL_DB']}#{ENV['POSTGRESQL_OPTIONS']}"
|
||||
end
|
||||
@@ -1,6 +1,8 @@
|
||||
# Copyright (C) 2012-2025 Zammad Foundation, https://zammad-foundation.org/
|
||||
|
||||
worker_count = Integer(ENV['WEB_CONCURRENCY'] || 0)
|
||||
# Support both ZAMMAD_WEB_CONCURRENCY (as recommended by the Zammad docker stack & documentation)
|
||||
# and WEB_CONCURRENCY (Zammad and Rails default).
|
||||
worker_count = Integer(ENV['ZAMMAD_WEB_CONCURRENCY'] || ENV['WEB_CONCURRENCY'] || 0)
|
||||
workers worker_count
|
||||
|
||||
threads_count_min = Integer(ENV['MIN_THREADS'] || 5)
|
||||
|
||||
@@ -7,7 +7,10 @@ set -o pipefail
|
||||
: "${RESTORE_DIR:=/var/tmp/zammad/restore}"
|
||||
: "${BACKUP_TIME:=03:00}"
|
||||
: "${HOLD_DAYS:=10}"
|
||||
: "${POSTGRESQL_URL:="postgresql://${POSTGRESQL_USER}:${ESCAPED_POSTGRESQL_PASS}@${POSTGRESQL_HOST}:${POSTGRESQL_PORT}/${POSTGRESQL_DB}"}"
|
||||
|
||||
# See DOCKERFILE for environment variables.
|
||||
ESCAPED_POSTGRESQL_PASS=$(echo "$POSTGRESQL_PASS" | ruby -ruri -e "puts URI.encode_uri_component(readline.chomp)")
|
||||
POSTGRESQL_URL="postgresql://${POSTGRESQL_USER}:${ESCAPED_POSTGRESQL_PASS}@${POSTGRESQL_HOST}:${POSTGRESQL_PORT}/${POSTGRESQL_DB}"
|
||||
|
||||
function check_zammad_ready {
|
||||
echo 'Checking if Zammad is ready...'
|
||||
|
||||
Reference in New Issue
Block a user