Make ODK SPOC-compatible

This commit is contained in:
Disassembler 2020-03-21 22:42:35 +01:00
parent f63e78a800
commit fea0a7911a
Signed by: Disassembler
GPG Key ID: 524BD33A0EE29499
11 changed files with 75 additions and 74 deletions

37
lxc-apps/opendatakit/app Normal file
View File

@ -0,0 +1,37 @@
{
"version": "2.0.5-200313",
"meta": {
"title": "OpenDataKit",
"desc-cs": "Sběr formulářových dat",
"desc-en": "Form data collection",
"license": "GPL"
},
"containers": {
"opendatakit": {
"image": "opendatakit_2.0.5-200313",
"depends": [
"opendatakit-postgres"
],
"mounts": {
"opendatakit/odk_conf/server.xml": "srv/tomcat/conf/server.xml:file",
"opendatakit/odk_conf/jdbc.properties": "srv/tomcat/webapps/ROOT/WEB-INF/classes/jdbc.properties:file",
"opendatakit/odk_conf/security.properties": "srv/tomcat/webapps/ROOT/WEB-INF/classes/security.properties:file"
}
},
"opendatakit-build": {
"image": "opendatakit-build_0.3.5-200313",
"depends": [
"opendatakit-postgres"
],
"mounts": {
"opendatakit/odkbuild_conf/config.yml": "srv/opendatakit-build/config.yml:file"
}
},
"opendatakit-postgres": {
"image": "postgres_12.2.0-200313",
"mounts": {
"opendatakit/postgres_data": "var/lib/postgresql"
}
}
}
}

View File

@ -1,57 +1,55 @@
#!/bin/sh
set -ev
# Volumes
POSTGRES_DATA="${VOLUMES_DIR}/opendatakit/postgres_data"
ODK_CONF="${VOLUMES_DIR}/opendatakit/odk_conf"
ODKBUILD_CONF="${VOLUMES_DIR}/opendatakit/odkbuild_conf"
# Create Postgres instance
mkdir -p /srv/opendatakit/postgres_data
chown -R 105432:105432 /srv/opendatakit/postgres_data
chmod 700 /srv/opendatakit/postgres_data
lxc-execute -n opendatakit-postgres -- initdb -D /var/lib/postgresql
install -o 105432 -g 105432 -m 700 -d ${POSTGRES_DATA}
spoc-container exec opendatakit-postgres -- initdb -D /var/lib/postgresql
# Configure Postgres
cp postgres_data/postgresql.conf /srv/opendatakit/postgres_data/postgresql.conf
cp postgres_data/pg_hba.conf /srv/opendatakit/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 databases
export OPENDATAKIT_PWD=$(head -c 18 /dev/urandom | base64 | tr -d '+/=')
export OPENDATAKITBUILD_PWD=$(head -c 18 /dev/urandom | base64 | tr -d '+/=')
service lxc-opendatakit-postgres start
envsubst <createdb.sql | lxc-attach -u 5432 -g 5432 opendatakit-postgres -- psql
spoc-container start opendatakit-postgres
envsubst <createdb.sql | spoc-container exec opendatakit-postgres -- psql
# Configure OpenDataKit
mkdir -p /srv/opendatakit/odk_conf
export OPENDATAKIT_ADMIN_USER=admin
export OPENDATAKIT_ADMIN_REALM=spotter
envsubst <odk_conf/jdbc.properties >/srv/opendatakit/odk_conf/jdbc.properties
envsubst <odk_conf/security.properties >/srv/opendatakit/odk_conf/security.properties
cp odk_conf/server.xml /srv/opendatakit/odk_conf/server.xml
chown -R 108080:108080 /srv/opendatakit/odk_conf
install -o 108080 -g 108080 -m 750 -d ${ODK_CONF}
envsubst <odk_conf/jdbc.properties | install -o 108080 -g 108080 -m 640 /dev/stdin ${ODK_CONF}/jdbc.properties
envsubst <odk_conf/security.properties | install -o 108080 -g 108080 -m 640 /dev/stdin ${ODK_CONF}/security.properties
install -o 108080 -g 108080 -m 640 odk_conf/server.xml ${ODK_CONF}/server.xml
# Configure OpenDataKit Build
export OPENDATAKITBUILD_COOKIE_SECRET=$(head -c 8 /dev/urandom | hexdump -e '"%x"')
mkdir -p /srv/opendatakit/odkbuild_conf
envsubst <odkbuild_conf/config.yml >/srv/opendatakit/odkbuild_conf/config.yml
lxc-execute opendatakit-build -- sh -c 'cd /srv/opendatakit-build; rake db:migrate'
chown -R 100000:100000 /srv/opendatakit/odkbuild_conf
install -o 108080 -g 108080 -m 750 -d ${ODKBUILD_CONF}
envsubst <odkbuild_conf/config.yml | install -o 108080 -g 108080 -m 640 /dev/stdin ${ODKBUILD_CONF}/config.yml
spoc-container exec opendatakit-build -- sh -c 'cd /srv/opendatakit-build; rake db:migrate'
# Populate database
service lxc-opendatakit start
until grep -q 'org.apache.catalina.startup.Catalina.start Server startup' /var/log/lxc/opendatakit.log; do
spoc-container start opendatakit
until grep -q 'org.apache.catalina.startup.Catalina.start Server startup' /var/log/spoc/opendatakit.log; do
sleep 1
done
service lxc-opendatakit stop
spoc-container stop opendatakit
# Update admin account
export OPENDATAKIT_ADMIN_PWD=$(head -c 12 /dev/urandom | base64 | tr -d '+/=')
export OPENDATAKIT_ADMIN_SALT=$(head -c 4 /dev/urandom | hexdump -e '"%x"') # Must be exactly 8 characters
export OPENDATAKIT_ADMIN_BASIC_HASH=$(echo -n "${OPENDATAKIT_ADMIN_PWD}{${OPENDATAKIT_ADMIN_SALT}}" | sha1sum | tr -d " -")
export OPENDATAKIT_ADMIN_DIGEST_HASH=$(echo -n "${OPENDATAKIT_ADMIN_USER}:${OPENDATAKIT_ADMIN_REALM}:${OPENDATAKIT_ADMIN_PWD}" | md5sum | tr -d " -")
envsubst <adminpwd.sql | lxc-attach -u 5432 -g 5432 opendatakit-postgres -- psql opendatakit
# Install config update script
cp update-conf.sh /srv/opendatakit/update-conf.sh
envsubst <adminpwd.sql | spoc-container exec opendatakit-postgres -- psql opendatakit
# Stop services required for setup
service lxc-opendatakit-postgres stop
spoc-container stop opendatakit-postgres
# Register application
vmmgr register-app opendatakit odk "${OPENDATAKIT_ADMIN_USER}" "${OPENDATAKIT_ADMIN_PWD}"

View File

@ -1,38 +0,0 @@
{
"version": "2.0.3-190620",
"meta": {
"title": "OpenDataKit",
"desc-cs": "Sběr formulářových dat",
"desc-en": "Form data collection",
"license": "GPL"
},
"containers": {
"opendatakit": {
"image": "opendatakit_2.0.3-190620",
"depends": [
"opendatakit-postgres"
],
"mounts": [
["FILE", "/srv/opendatakit/odk_conf/server.xml", "/srv/tomcat/conf/server.xml"],
["FILE", "/srv/opendatakit/odk_conf/jdbc.properties", "/srv/tomcat/webapps/ROOT/WEB-INF/classes/jdbc.properties"],
["FILE", "/srv/opendatakit/odk_conf/security.properties", "/srv/tomcat/webapps/ROOT/WEB-INF/classes/security.properties"]
]
},
"opendatakit-build": {
"image": "opendatakit-build_0.3.5-190620",
"depends": [
"opendatakit-postgres"
],
"mounts": [
["FILE", "/etc/ssl/services.pem", "/usr/local/share/ca-certificates/services.crt"],
["FILE", "/srv/opendatakit/odkbuild_conf/config.yml", "/srv/opendatakit-build/config.yml"]
]
},
"opendatakit-postgres": {
"image": "postgres_11.3.0-190620",
"mounts": [
["DIR", "/srv/opendatakit/postgres_data", "/var/lib/postgresql"]
]
}
}
}

View File

@ -1,9 +1,9 @@
IMAGE opendatakit-build_0.3.5-190620
FROM alpine3.9-ruby2.4_2.4.5-190620
IMAGE opendatakit-build_0.3.5-200313
FROM alpine3.11-ruby2.4_2.4.9-200313
RUN EOF
# Install runtime dependencies
apk --no-cache add libpq nodejs
apk --no-cache add libpq nodejs openssl
# Install build dependencies
apk --no-cache add --virtual .deps build-base git linux-headers make npm openjdk8-jre-base postgresql-dev
@ -34,6 +34,6 @@ RUN EOF
rm -rf /root/.bundle /root/.config /root/.npm
EOF
COPY opendatakit-build.lxc
COPY opendatakit-build.image.d
CMD /bin/s6-svscan /etc/services.d

View File

@ -0,0 +1,4 @@
#!/bin/sh
true | openssl s_client -connect host:443 | openssl x509 -out /usr/local/share/ca-certificates/host.crt
update-ca-certificates

View File

@ -1,4 +1,4 @@
#!/bin/execlineb -P
foreground { s6-svwait -d -t 3000 build2xlsform }
foreground { s6-svwait -d -t 3000 build2xlsform }
foreground { s6-svwait -d -t 3000 odkbuild }

View File

@ -2,6 +2,6 @@
cd /srv/opendatakit-build
fdmove -c 2 1
foreground { update-ca-certificates }
foreground { /bin/add-ca-cert }
s6-setuidgid odkbuild
bundle exec rackup config.ru -o 0.0.0.0 -p 8080

View File

@ -1,9 +1,9 @@
IMAGE opendatakit_2.0.3-190620
FROM alpine3.9-tomcat8.5_8.5.41-190620
IMAGE opendatakit_2.0.5-200313
FROM alpine3.11-tomcat8.5_8.5.51-200313
RUN EOF
# Download OpenDataKit
wget https://github.com/opendatakit/aggregate/releases/download/v2.0.3/ODK-Aggregate-v2.0.3.war -O /tmp/odk.war
wget https://github.com/opendatakit/aggregate/releases/download/v2.0.5/ODK-Aggregate-v2.0.5.war -O /tmp/odk.war
mkdir /srv/tomcat/webapps/ROOT
unzip /tmp/odk.war -d /srv/tomcat/webapps/ROOT
@ -18,6 +18,6 @@ RUN EOF
rm /tmp/odk.war
EOF
USER 8080 8080
USER tomcat
WORKDIR /srv/tomcat
CMD /usr/bin/catalina.sh run

View File

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