Skip to content

Commit b329691

Browse files
committed
Configure postgresql usage in production
1 parent 0237058 commit b329691

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

.github/workflows/deb.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,13 +90,25 @@ jobs:
9090
9191
# Create a postinstall script that enables all the shipped units
9292
# and symlinks our nginx configuration in place of the default one.
93+
# We also set up the database user in this block
9394
echo "#/bin/sh" > postinstall.sh
9495
for f in ./systemd/*; do
9596
echo "systemctl enable $(basename $f)" >> postinstall.sh
9697
done
9798
echo "ln -sf /opt/hackman/nginx/default /etc/nginx/sites-enabled/default" >> postinstall.sh
99+
100+
# Ugly auto-generated escape sequences galore! \o/
101+
echo 'echo '"'"'CREATE DATABASE hackman;'"'"' | sudo -u postgres psql' >> postinstall.sh
102+
echo 'echo '"'"'CREATE USER hackman WITH PASSWORD '"'"'"'"'"'"'"'"'hackman'"'"'"'"'"'"'"'"';'"'"' | sudo -u postgres psql' >> postinstall.sh
103+
echo 'echo '"'"'ALTER ROLE hackman SET client_encoding TO '"'"'"'"'"'"'"'"'utf8'"'"'"'"'"'"'"'"';'"'"' | sudo -u postgres psql' >> postinstall.sh
104+
echo 'echo '"'"'ALTER ROLE hackman SET default_transaction_isolation TO '"'"'"'"'"'"'"'"'read committed'"'"'"'"'"'"'"'"';'"'"' | sudo -u postgres psql' >> postinstall.sh
105+
echo 'echo '"'"'ALTER ROLE hackman SET timezone TO '"'"'"'"'"'"'"'"'UTC'"'"'"'"'"'"'"'"';'"'"' | sudo -u postgres psql' >> postinstall.sh
106+
echo 'echo '"'"'GRANT ALL PRIVILEGES ON DATABASE hackman TO hackman;'"'"' | sudo -u postgres psql' >> postinstall.sh
107+
108+
# Reload main systemd units
98109
echo "systemctl start hackman" >> postinstall.sh
99110
echo "systemctl reload nginx" >> postinstall.sh
111+
100112
chmod +x postinstall.sh
101113
102114
# Build deb

hackman/settings_prod.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,12 @@ def _gen_key() -> str:
4949

5050
DATABASES = {
5151
"default": {
52-
"ENGINE": "django.db.backends.sqlite3",
53-
"NAME": "/var/lib/hackman/db.sqlite3",
52+
"ENGINE": "django.db.backends.postgresql",
53+
"NAME": "hackman",
54+
"USER": "hackman",
55+
"PASSWORD": "hackman",
56+
"HOST": "localhost",
57+
"PORT": "",
5458
}
5559
}
5660

0 commit comments

Comments
 (0)