Skip to content

Commit

Permalink
Closes zammad#5383 - Allow Asset Precompilation Without PostgreSQL Co…
Browse files Browse the repository at this point in the history
…nnection

- The intent of this is to be able to use `ZAMMAD_SAFE_MODE=1 bundle exec rake assets:precompile`
or similar to allow assets to precompile without a PG connection
- Remove Postgres from docker builder

Co-authored-by: Martin Gruner <[email protected]>
  • Loading branch information
2 people authored and mgruner committed Nov 22, 2024
1 parent 3770a59 commit 6bc24ac
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 13 deletions.
3 changes: 3 additions & 0 deletions config/initializers/models_preload.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,8 @@
Models.all
rescue ActiveRecord::StatementInvalid
nil
rescue ActiveRecord::ConnectionNotEstablished, ActiveRecord::NoDatabaseError => e
warn e
Zammad::SafeMode.continue_or_exit!
end
end
2 changes: 1 addition & 1 deletion config/initializers/zzz_action_cable_preferences.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
Rails.application.config.action_cable.allowed_request_origins = request_origins
Rails.application.config.action_cable.disable_request_forgery_protection = true if !Rails.env.production?
Rails.logger.info { "ActionCable is configured to accept requests from #{request_origins.join(', ')}." }
rescue ActiveRecord::NoDatabaseError, ActiveRecord::StatementInvalid
rescue ActiveRecord::ConnectionNotEstablished, ActiveRecord::NoDatabaseError, ActiveRecord::StatementInvalid
Rails.logger.warn { "Database doesn't exist. Skipping allowed_request_origins configuration." }
end
end
19 changes: 7 additions & 12 deletions contrib/docker/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ set -e
apt-get update
apt-get upgrade -y

# Add official PostgreSQL apt repository to not depend on Debian's version.
# https://www.postgresql.org/download/linux/debian/
apt-get install -y postgresql-common
/usr/share/postgresql-common/pgdg/apt.postgresql.org.sh -y

if [ "$1" = 'builder' ]; then
PACKAGES="build-essential curl git libimlib2-dev libpq-dev shared-mime-info postgresql-17"
PACKAGES="build-essential curl git libimlib2-dev libpq-dev"
elif [ "$1" = 'runner' ]; then
# Add official PostgreSQL apt repository to not depend on Debian's version.
# https://www.postgresql.org/download/linux/debian/
apt-get install -y postgresql-common
/usr/share/postgresql-common/pgdg/apt.postgresql.org.sh -y

PACKAGES="curl libimlib2 libpq5 nginx gnupg postgresql-client-17"
fi

Expand All @@ -20,11 +20,6 @@ apt-get install -y --no-install-recommends ${PACKAGES}
rm -rf /var/lib/apt/lists/*

if [ "$1" = 'builder' ]; then
# Create an empty DB just so that the Rails stack can run.
/etc/init.d/postgresql start
su - postgres bash -c "createuser zammad -R -S"
su - postgres bash -c "createdb --encoding=utf8 --owner=zammad zammad"

cd "${ZAMMAD_DIR}"
bundle config set --local without 'test development mysql'
# Don't use the 'deployment' switch here as it would require always using 'bundle exec'
Expand All @@ -33,7 +28,7 @@ if [ "$1" = 'builder' ]; then
bundle install

touch db/schema.rb
ZAMMAD_SAFE_MODE=1 DATABASE_URL=postgresql://zammad:/zammad bundle exec rake assets:precompile # Don't require Redis.
ZAMMAD_SAFE_MODE=1 DATABASE_URL=postgresql://zammad:/zammad bundle exec rake assets:precompile # Don't require Redis or Postgres.

script/build/cleanup.sh
fi
Expand Down

0 comments on commit 6bc24ac

Please sign in to comment.