Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tags to pups templates #751

Merged
merged 6 commits into from
Apr 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
108 changes: 62 additions & 46 deletions templates/postgres.template.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,14 @@ hooks:
- replace:
filename: /etc/service/unicorn/run
from: "# postgres"
to: sv start postgres || exit 1
to: |
if [ -f /root/install_postgres ]; then
/root/install_postgres
rm /root/install_postgres
fi
sv start postgres || exit 1

run:
- exec: locale-gen $LANG && update-locale
- exec: mkdir -p /shared/postgres_run
- exec: chown postgres:postgres /shared/postgres_run
- exec: chmod 775 /shared/postgres_run
- exec: rm -fr /var/run/postgresql
- exec: ln -s /shared/postgres_run /var/run/postgresql
- exec: socat /dev/null UNIX-CONNECT:/shared/postgres_run/.s.PGSQL.5432 || exit 0 && echo postgres already running stop container ; exit 1
- exec: rm -fr /shared/postgres_run/.s*
- exec: rm -fr /shared/postgres_run/*.pid
- exec: mkdir -p /shared/postgres_run/13-main.pg_stat_tmp
- exec: chown postgres:postgres /shared/postgres_run/13-main.pg_stat_tmp
- file:
path: /etc/service/postgres/run
chmod: "+x"
Expand All @@ -51,6 +45,35 @@ run:
#!/bin/bash
sv stop postgres

- file:
path: /root/install_postgres
chmod: "+x"
contents: |
#!/bin/bash
locale-gen $LANG && update-locale
mkdir -p /shared/postgres_run
chown postgres:postgres /shared/postgres_run
chmod 775 /shared/postgres_run
rm -fr /var/run/postgresql
ln -s /shared/postgres_run /var/run/postgresql
if [ -e /shared/postgres_run/.s.PGSQL.5432 ]; then
socat /dev/null UNIX-CONNECT:/shared/postgres_run/.s.PGSQL.5432 || exit 0 && echo postgres already running stop container ; exit 1
fi
rm -fr /shared/postgres_run/.s*
rm -fr /shared/postgres_run/*.pid
mkdir -p /shared/postgres_run/13-main.pg_stat_tmp
chown postgres:postgres /shared/postgres_run/13-main.pg_stat_tmp
chown -R root /var/lib/postgresql/13/main
[ ! -e /shared/postgres_data ] && install -d -m 0755 -o postgres -g postgres /shared/postgres_data && sudo -E -u postgres /usr/lib/postgresql/13/bin/initdb -D /shared/postgres_data || exit 0
chown -R postgres:postgres /shared/postgres_data
chown -R postgres:postgres /var/run/postgresql
if [ -f /root/upgrade_postgres ]; then
/root/upgrade_postgres
rm /root/upgrade_postgres
fi
# Necessary to enable backups
install -d -m 0755 -o postgres -g postgres /shared/postgres_backup

- file:
path: /root/upgrade_postgres
chmod: "+x"
Expand Down Expand Up @@ -116,16 +139,6 @@ run:
exit 77
fi

- exec:
cmd:
- chown -R root /var/lib/postgresql/13/main
- "[ ! -e /shared/postgres_data ] && install -d -m 0755 -o postgres -g postgres /shared/postgres_data && sudo -E -u postgres /usr/lib/postgresql/13/bin/initdb -D /shared/postgres_data || exit 0"
- chown -R postgres:postgres /shared/postgres_data
- chown -R postgres:postgres /var/run/postgresql

- exec: /root/upgrade_postgres
- exec: rm /root/upgrade_postgres

- replace:
filename: "/etc/postgresql/13/main/postgresql.conf"
from: "data_directory = '/var/lib/postgresql/13/main'"
Expand Down Expand Up @@ -161,11 +174,6 @@ run:
from: /#?default_text_search_config *=.*/
to: "default_text_search_config = '$db_default_text_search_config'"

# Necessary to enable backups
- exec:
cmd:
- install -d -m 0755 -o postgres -g postgres /shared/postgres_backup

- replace:
filename: "/etc/postgresql/13/main/postgresql.conf"
from: /#?checkpoint_segments *=.*/
Expand Down Expand Up @@ -199,29 +207,32 @@ run:
to: "host all all ::/0 md5"

- exec:
tag: db
cmd: "[ -f /root/install_postgres ] && /root/install_postgres && rm -f /root/install_postgres"

- exec:
tag: db
background: true
# use fast shutdown for pg
stop_signal: INT
cmd: HOME=/var/lib/postgresql USER=postgres exec chpst -u postgres:postgres:ssl-cert -U postgres:postgres:ssl-cert /usr/lib/postgresql/13/bin/postmaster -D /etc/postgresql/13/main

# give db a few secs to start up
- exec: "sleep 5"

- exec: su postgres -c 'createdb $db_name' || true
- exec: su postgres -c 'psql $db_name -c "create user $db_user;"' || true
- exec: su postgres -c 'psql $db_name -c "grant all privileges on database $db_name to $db_user;"' || true
- exec: su postgres -c 'psql $db_name -c "alter schema public owner to $db_user;"'
- exec: su postgres -c 'psql template1 -c "create extension if not exists hstore;"'
- exec: su postgres -c 'psql template1 -c "create extension if not exists pg_trgm;"'
- exec: su postgres -c 'psql template1 -c "create extension if not exists vector;"'
- exec: su postgres -c 'psql $db_name -c "create extension if not exists hstore;"'
- exec: su postgres -c 'psql $db_name -c "create extension if not exists pg_trgm;"'
- exec: su postgres -c 'psql $db_name -c "create extension if not exists vector;"'
- exec:
stdin: |
update pg_database set encoding = pg_char_to_encoding('UTF8') where datname = '$db_name' AND encoding = pg_char_to_encoding('SQL_ASCII');
cmd: sudo -u postgres psql $db_name
raise_on_fail: false
- file:
path: /usr/local/bin/create_db
chmod: +x
contents: |
#!/bin/bash
su postgres -c 'createdb $db_name' || true
su postgres -c 'psql $db_name -c "create user $db_user;"' || true
su postgres -c 'psql $db_name -c "grant all privileges on database $db_name to $db_user;"' || true
su postgres -c 'psql $db_name -c "alter schema public owner to $db_user;"'
su postgres -c 'psql template1 -c "create extension if not exists hstore;"'
su postgres -c 'psql template1 -c "create extension if not exists pg_trgm;"'
su postgres -c 'psql template1 -c "create extension if not exists vector;"'
su postgres -c 'psql $db_name -c "create extension if not exists hstore;"'
su postgres -c 'psql $db_name -c "create extension if not exists pg_trgm;"'
su postgres -c 'psql $db_name -c "create extension if not exists vector;"'
sudo -u postgres psql $db_name <<< "update pg_database set encoding = pg_char_to_encoding('UTF8') where datname = '$db_name' AND encoding = pg_char_to_encoding('SQL_ASCII');" || true

- file:
path: /var/lib/postgresql/take-database-backup
Expand All @@ -242,5 +253,10 @@ run:
#0 */4 * * * /var/lib/postgresql/take-database-backup

- exec:
tag: db
hook: postgres
cmd: "echo postgres installed!"
cmd:
# give db a few secs to start up
- "sleep 5"
- /usr/local/bin/create_db
- "echo postgres installed!"
10 changes: 7 additions & 3 deletions templates/redis.template.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ run:
to: ""

- exec:
tag: db
cmd:
- install -d -m 0755 -o redis -g redis /shared/redis_data

Expand Down Expand Up @@ -68,16 +69,19 @@ run:

- exec:
background: true
tag: db
cmd: exec chpst -u redis -U redis /usr/bin/redis-server /etc/redis/redis.conf

- exec: sleep 10
- exec:
tag: db
cmd: sleep 10

# we can not migrate without redis, launch it if needed
hooks:
before_code:
before_db_migrate:
- exec:
background: true
cmd: exec chpst -u redis -U redis /usr/bin/redis-server /etc/redis/redis.conf
- exec: sleep 10
after_code:
- replace:
filename: /etc/service/unicorn/run
Expand Down
30 changes: 26 additions & 4 deletions templates/web.template.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,12 @@ params:

run:
- exec: thpoff echo "thpoff is installed!"
- exec: /usr/local/bin/ruby -e 'if ENV["DISCOURSE_SMTP_ADDRESS"] == "smtp.example.com"; puts "Aborting! Mail is not configured!"; exit 1; end'
- exec: /usr/local/bin/ruby -e 'if ENV["DISCOURSE_HOSTNAME"] == "discourse.example.com"; puts "Aborting! Domain is not configured!"; exit 1; end'
- exec: /usr/local/bin/ruby -e 'if (ENV["DISCOURSE_CDN_URL"] || "")[0..1] == "//"; puts "Aborting! CDN must have a protocol specified. Once fixed you should rebake your posts now to correct all posts."; exit 1; end'
- exec:
tag: precompile
cmd:
- /usr/local/bin/ruby -e 'if ENV["DISCOURSE_SMTP_ADDRESS"] == "smtp.example.com"; puts "Aborting! Mail is not configured!"; exit 1; end'
- /usr/local/bin/ruby -e 'if ENV["DISCOURSE_HOSTNAME"] == "discourse.example.com"; puts "Aborting! Domain is not configured!"; exit 1; end'
- /usr/local/bin/ruby -e 'if (ENV["DISCOURSE_CDN_URL"] || "")[0..1] == "//"; puts "Aborting! CDN must have a protocol specified. Once fixed you should rebake your posts now to correct all posts."; exit 1; end'
# TODO: move to base image (anacron can not be fired up using rc.d)
- exec: rm -f /etc/cron.d/anacron
- file:
Expand Down Expand Up @@ -55,6 +58,12 @@ run:
# postgres
cd $home
chown -R discourse:www-data /shared/log/rails
if [[ -z "$PRECOMPILE_ON_BOOT" ]]; then
PRECOMPILE_ON_BOOT=1
fi
if [ -f /usr/local/bin/create_db ] && [ "$CREATE_DB_ON_BOOT" = "1" ]; then /usr/local/bin/create_db; fi;
if [ "$MIGRATE_ON_BOOT" = "1" ]; then su discourse -c 'bundle exec rake db:migrate'; fi
if [ "$PRECOMPILE_ON_BOOT" = "1" ]; then SKIP_EMBER_CLI_COMPILE=1 su discourse -c 'bundle exec rake assets:precompile'; fi
LD_PRELOAD=$RUBY_ALLOCATOR HOME=/home/discourse USER=discourse exec thpoff chpst -u discourse:www-data -U discourse:www-data bundle exec config/unicorn_launcher -E production -c config/unicorn.conf.rb

- file:
Expand Down Expand Up @@ -193,14 +202,27 @@ run:

- exec:
cd: $home
tag: migrate
hook: db_migrate
cmd:
- su discourse -c 'bundle exec rake db:migrate'
- exec:
cd: $home
tag: build
hook: assets_precompile_build
cmd:
- su discourse -c 'bundle exec rake assets:precompile:build'
- exec:
cd: $home
tag: precompile
hook: assets_precompile
cmd:
- su discourse -c 'bundle exec rake themes:update assets:precompile'
- su discourse -c 'SKIP_EMBER_CLI_COMPILE=1 bundle exec rake themes:update assets:precompile'
- replace:
tag: precompile
filename: /etc/service/unicorn/run
from: PRECOMPILE_ON_BOOT=1
to: "PRECOMPILE_ON_BOOT=0"

- file:
path: /usr/local/bin/discourse
Expand Down