adapt to Amazon Linux v2

This commit is contained in:
Changaco 2021-05-20 13:59:36 +02:00
parent cfc49489d5
commit 5b79b09316
15 changed files with 24 additions and 73 deletions

View File

@ -1,13 +0,0 @@
files:
"/etc/httpd/conf.d/zzz_liberapay.conf":
mode: "000644"
owner: root
group: root
content: |
LogFormat "%t %s %{us}Tus %{Host}i \"%r\" %B \"%{Referer}i\"" combined
WSGIPassAuthorization On
# Hide health check requests from access logs
SetEnvIfNoCase User-Agent "^ELB-HealthChecker" dontlog
commands:
01_customlog:
command: "sed -e 's|^\\s*CustomLog .logs/access_log. combined$|\\0 env=!dontlog|' -i /etc/httpd/conf/httpd.conf"

View File

@ -5,9 +5,8 @@ files:
group: root
content: |
#!/bin/sh
source /opt/python/current/env
export PGHOST=$RDS_HOSTNAME
export PGPORT=$RDS_PORT
export PGDATABASE=$RDS_DB_NAME
export PGUSER=$RDS_USERNAME
export PGPASSWORD=$RDS_PASSWORD
export PGHOST=$(/opt/elasticbeanstalk/bin/get-config environment -k PGHOST)
export PGPORT=$(/opt/elasticbeanstalk/bin/get-config environment -k PGPORT)
export PGDATABASE=$(/opt/elasticbeanstalk/bin/get-config environment -k PGDATABASE)
export PGUSER=$(/opt/elasticbeanstalk/bin/get-config environment -k PGUSER)
export PGPASSWORD=$(/opt/elasticbeanstalk/bin/get-config environment -k PGPASSWORD)

View File

@ -1,6 +0,0 @@
# See https://github.com/liberapay/liberapay.com/issues/1405
commands:
01_ld_preload:
command: "echo $(gcc --print-file-name=libgcc_s.so.1) >>/etc/ld.so.preload"
02_ldconfig:
command: "ldconfig"

View File

@ -1,3 +0,0 @@
commands:
01_log_dir:
command: "install -o wsgi -g wsgi -m 755 -d /home/wsgi"

View File

@ -1,7 +1,3 @@
packages:
rpm:
postgresql96: "https://download.postgresql.org/pub/repos/yum/9.6/redhat/rhel-6-x86_64/pgdg-ami201503-96-9.6-2.noarch.rpm"
yum:
libffi-devel: [] # for misaka
postgresql96: [] # pg_dump
postgresql96-devel: [] # for psycopg2

View File

@ -1,11 +0,0 @@
files:
"/opt/elasticbeanstalk/hooks/appdeploy/pre/98pip.sh":
mode: "000755"
owner: root
group: root
content: |
#!/bin/bash -e
source /opt/python/ondeck/env
cd /opt/python/ondeck/app
pip install --upgrade pip
pip install --require-hashes -r requirements_base.txt

View File

@ -1,13 +0,0 @@
files:
"/opt/elasticbeanstalk/hooks/appdeploy/pre/99checkconf.sh":
mode: "000755"
owner: root
group: root
content: |
#!/bin/bash
sudo -u wsgi /bin/bash -e <<EOF
source /opt/python/ondeck/env
cd /opt/python/ondeck/app
export PYTHONPATH="/opt/python/ondeck/app/:$PYTHONPATH"
python liberapay/wireup.py
EOF

View File

@ -0,0 +1,3 @@
#!/bin/bash -eu
amazon-linux-extras install -y postgresql11

View File

@ -0,0 +1,3 @@
#!/bin/bash -eu
/var/app/venv/staging-*/bin/pip install --require-hashes -r requirements_base.txt

View File

@ -0,0 +1,3 @@
#!/bin/bash -eu
sudo -u webapp -E PYTHONPATH=. /var/app/venv/staging-*/bin/python liberapay/wireup.py

View File

@ -39,7 +39,7 @@ schema: $(env)
$(with_local_env) ./recreate-schema.sh
schema-diff: test-schema
eb ssh liberapay-prod -c 'pg_dump -sO' | sed -e '/^INFO: /d' >prod.sql
eb ssh liberapay -c 'pg_dump -sO' | sed -e '/^INFO: /d' >prod.sql
$(with_tests_env) sh -c 'pg_dump -sO "$$DATABASE_URL"' >local.sql
sed -E -e '/^--/d' -e '/^\s*$$/d' -e '/^SET /d' -e 's/\bpg_catalog\.//g' -i prod.sql local.sql
diff -uw prod.sql local.sql

1
Procfile Normal file
View File

@ -0,0 +1 @@
web: python app.py

16
app.py
View File

@ -7,27 +7,19 @@ Docs: http://docs.gunicorn.org/en/stable/settings.html
"""
from os import environ as env, execlp
import sys
_canonical_host = env['CANONICAL_HOST']
_production = _canonical_host == 'liberapay.com'
if __name__ == '__main__':
# Exec gunicorn, ask it to read its settings from this file
program = 'gunicorn'
execlp(program, program, 'liberapay.main:website', '--config', 'app.py')
execlp(program, program, 'liberapay.main:website', '--config', 'app.py', *sys.argv[1:])
accesslog = '-' # stderr
access_log_format = (
'%(t)s %(s)s %(L)ss %({Host}i)s "%(r)s" %(b)s "%(f)s"'
)
bind = [
env['OPENSHIFT_PYTHON_IP'] + ':' + env['OPENSHIFT_PYTHON_PORT']
if _production else
_canonical_host
]
chdir = env['OPENSHIFT_REPO_DIR'] if _production else ''
if _production:
pidfile = env['OPENSHIFT_DATA_DIR'] + '/gunicorn.pid'
if ':' in _canonical_host:
bind = [_canonical_host]

View File

@ -6,6 +6,6 @@ if [ "$(basename "$dest_dir")" != 'liberapay' ]; then echo "parent directory sho
dest_dir="$dest_dir/backups"
mkdir -p "$dest_dir"
dest="$dest_dir/$(date -u -Iseconds).psql"
eb ssh liberapay-prod -c "pg_dump -Fc" > "$dest"
eb ssh liberapay -c "pg_dump -Fc" > "$dest"
chmod 400 "$dest"
ls -lh "$dest_dir" | tail -10

View File

@ -145,13 +145,13 @@ git tag $version
# Deploy
if [ -s $branch_before ]; then
echo "Running $branch_before..."
eb ssh liberapay-prod -c 'psql -v ON_ERROR_STOP=on' <$branch_before
eb ssh liberapay -c 'psql -v ON_ERROR_STOP=on' <$branch_before
fi
[ -e $branch_before ] && rm $branch_before
eb deploy liberapay-prod --label $version
eb deploy liberapay --label $version
if [ -s $branch_after ]; then
echo "Running $branch_after..."
eb ssh liberapay-prod -c 'psql -v ON_ERROR_STOP=on' <$branch_after
eb ssh liberapay -c 'psql -v ON_ERROR_STOP=on' <$branch_after
fi
[ -e $branch_after ] && rm $branch_after