Skip to content

Commit

Permalink
use existing postgres for asset precompilation
Browse files Browse the repository at this point in the history
  • Loading branch information
machisuji committed May 12, 2023
1 parent 891b1a7 commit 5126b5d
Showing 1 changed file with 3 additions and 9 deletions.
12 changes: 3 additions & 9 deletions docker/prod/setup/postinstall-common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,19 @@ npm install
popd

# Bundle assets
su - postgres -c "$PGBIN/initdb -D /tmp/nulldb"
su - postgres -c "bash -c '$PGBIN/pg_ctl -D /tmp/nulldb -l /tmp/pg_ctl.log -w start -o \"-p 5433\" || cat /tmp/pg_ctl.log'"
echo "create database assets; create user assets with encrypted password 'p4ssw0rd'; grant all privileges on database assets to assets;" | su - postgres -c 'psql -p 5433'
echo "create database assets; create user assets with encrypted password 'p4ssw0rd'; grant all privileges on database assets to assets;" | su - postgres -c psql

# give some more time for DB to start
sleep 5

# dump schema
DATABASE_URL=postgres://assets:p4ssw0rd@127.0.0.1:5433/assets RAILS_ENV=production bundle exec rake db:migrate db:schema:dump db:schema:cache:dump
DATABASE_URL=postgres://assets:p4ssw0rd@127.0.0.1:5432/assets RAILS_ENV=production bundle exec rake db:migrate db:schema:dump db:schema:cache:dump

# this line requires superuser rights, which is not always available and doesn't matter anyway
sed -i '/^COMMENT ON EXTENSION/d' db/structure.sql

# precompile assets
DATABASE_URL=postgres://assets:p4ssw0rd@127.0.0.1:5433/assets RAILS_ENV=production bundle exec rake assets:precompile

su - postgres -c "$PGBIN/pg_ctl -D /tmp/nulldb stop"

rm -rf /tmp/nulldb
DATABASE_URL=postgres://assets:p4ssw0rd@127.0.0.1:5432/assets RAILS_ENV=production bundle exec rake assets:precompile

# Remove sprockets cache
rm -rf "$APP_PATH/tmp/cache/assets"
Expand Down

0 comments on commit 5126b5d

Please sign in to comment.