Make CTS SPOC-compatible

This commit is contained in:
Disassembler 2020-03-16 21:35:33 +01:00
parent f6328158ed
commit 512895a6f2
Signed by: Disassembler
GPG Key ID: 524BD33A0EE29499
5 changed files with 47 additions and 48 deletions

26
lxc-apps/cts/app Normal file
View File

@ -0,0 +1,26 @@
{
"version": "0.8.0-200313",
"meta": {
"title": "CTS",
"desc-cs": "Sledovací systém komodit",
"desc-en": "Commodity tracking system",
"license": "GPL"
},
"containers": {
"cts": {
"image": "cts_0.8.0-200313",
"depends": [
"cts-postgres"
],
"mounts": {
"cts/cts_conf": "srv/cts/cts/settings"
}
},
"cts-postgres": {
"image": "postgis_3.0.0-200313",
"mounts": {
"cts/postgres_data": "var/lib/postgresql"
}
}
}
}

View File

@ -1,9 +1,9 @@
IMAGE cts_0.8.0-190620
FROM alpine3.9-python2.7_2.7.16-190620
IMAGE cts_0.8.0-200313
FROM alpine3.11-python2.7_2.7.16-200313
RUN EOF
# Install runtime dependencies
apk --no-cache add geos@vm libpq nginx zlib
apk --no-cache add geos libpq nginx zlib
# Install build dependencies
apk --no-cache add --virtual .deps build-base git postgresql-dev python2-dev py2-pip zlib-dev

View File

@ -1,44 +1,43 @@
#!/bin/sh
set -ev
# Volumes
POSTGRES_DATA="${VOLUMES_DIR}/cts/postgres_data"
CTS_CONF="${VOLUMES_DIR}/cts/cts_conf"
# Create Postgres instance
mkdir -p /srv/cts/postgres_data
chown -R 105432:105432 /srv/cts/postgres_data
chmod 700 /srv/cts/postgres_data
lxc-execute -n cts-postgres -- initdb -D /var/lib/postgresql
install -o 105432 -g 105432 -m 700 -d ${POSTGRES_DATA}
spoc-container exec cts-postgres -- initdb -D /var/lib/postgresql
# Configure Postgres
cp postgres_data/postgresql.conf /srv/cts/postgres_data/postgresql.conf
cp postgres_data/pg_hba.conf /srv/cts/postgres_data/pg_hba.conf
install -o 105432 -g 105432 -m 600 postgres_data/postgresql.conf ${POSTGRES_DATA}/postgresql.conf
install -o 105432 -g 105432 -m 600 postgres_data/pg_hba.conf ${POSTGRES_DATA}/pg_hba.conf
# Create database
export CTS_PWD=$(head -c 18 /dev/urandom | base64 | tr -d '+/=')
service lxc-cts-postgres start
envsubst <createdb.sql | lxc-attach -u 5432 -g 5432 cts-postgres -- psql
spoc-container start cts-postgres
envsubst <createdb.sql | spoc-container exec cts-postgres -- psql
# Copy existing config files into persistent storage
lxchelper extract cts /srv/cts/cts/settings /srv/cts/cts_conf
cp -rp ${LAYERS_DIR}/cts_0.8.0-200313/srv/cts/cts/settings ${CTS_CONF}
# Configure CTS
export CTS_SECRET=$(head -c 26 /dev/urandom | base64 | tr -d '+/=')
envsubst <cts_conf/spotter.py >/srv/cts/cts_conf/spotter.py
touch /srv/cts/cts_conf/__init__.py
envsubst <cts_conf/spotter.py | install -o 100000 -g 108080 -m 640 /dev/stdin ${CTS_CONF}/spotter.py
install -o 100000 -g 108080 -m 640 /dev/null ${CTS_CONF}/__init__.py
# Populate database
lxc-execute cts -- manage.py migrate
spoc-container exec cts -- manage.py migrate
# Create admin account
export CTS_ADMIN_EMAIL=admin@example.com
export CTS_ADMIN_PWD=$(head -c 12 /dev/urandom | base64 | tr -d '+/=')
export CTS_ADMIN_HASH=$(lxc-execute cts -- python -c "from django.contrib.auth.hashers import make_password; print make_password('${CTS_ADMIN_PWD}')")
export CTS_ADMIN_HASH=$(spoc-container exec cts -- python -c "from django.contrib.auth.hashers import make_password; print make_password('${CTS_ADMIN_PWD}')")
export CTS_ADMIN_SECRET=$(head -c 12 /dev/urandom | sha256sum | cut -c1-13)
envsubst <adminpwd.sql | lxc-attach -u 5432 -g 5432 cts-postgres -- psql cts
# Install config update script
cp update-conf.sh /srv/cts/update-conf.sh
envsubst <adminpwd.sql | spoc-container exec cts-postgres -- psql cts
# Stop services required for setup
service lxc-cts-postgres stop
spoc-container stop cts-postgres
# Register application
vmmgr register-app cts cts "${CTS_ADMIN_EMAIL}" "${CTS_ADMIN_PWD}"

View File

@ -1,26 +0,0 @@
{
"version": "0.8.0-190620",
"meta": {
"title": "CTS",
"desc-cs": "Sledovací systém komodit",
"desc-en": "Commodity tracking system",
"license": "GPL"
},
"containers": {
"cts": {
"image": "cts_0.8.0-190620",
"depends": [
"cts-postgres"
],
"mounts": [
["DIR", "/srv/cts/cts_conf", "/srv/cts/cts/settings"]
]
},
"cts-postgres": {
"image": "postgis_2.5.1-190620",
"mounts": [
["DIR", "/srv/cts/postgres_data", "/var/lib/postgresql"]
]
}
}
}

View File

@ -2,7 +2,7 @@
set -ev
# Remove persistent data
rm -rf /srv/cts
rm -rf "${VOLUMES_DIR}/cts"
# Unregister application
vmmgr unregister-app cts