From 6709ee478ae4895e16e8d2d26e609499a4f6fe7a Mon Sep 17 00:00:00 2001 From: Disassembler Date: Fri, 29 Dec 2017 16:31:48 +0100 Subject: [PATCH] Alpinize + Dockerize GNU Health --- README.md | 1 + gnuhealth.sh | 79 +++++-------------- gnuhealth/Dockerfile | 52 ++++++++++++ .../gnuhealth-createdb.sql => createdb.sql} | 0 gnuhealth/etc/init.d/gnuhealth | 17 ++++ gnuhealth/etc/nginx/apps/gnuhealth | 9 +++ gnuhealth/etc/nginx/conf.d/gnuhealth.conf | 11 +++ gnuhealth/etc/nginx/sites-available/gnuhealth | 17 ---- gnuhealth/gnuhealth-sao-dependencies.patch | 16 ---- .../lib/systemd/system/gnuhealth.service | 16 ---- .../server/config => conf}/trytond.conf | 4 +- 11 files changed, 111 insertions(+), 111 deletions(-) create mode 100644 gnuhealth/Dockerfile rename gnuhealth/{tmp/gnuhealth-createdb.sql => createdb.sql} (100%) create mode 100755 gnuhealth/etc/init.d/gnuhealth create mode 100644 gnuhealth/etc/nginx/apps/gnuhealth create mode 100644 gnuhealth/etc/nginx/conf.d/gnuhealth.conf delete mode 100644 gnuhealth/etc/nginx/sites-available/gnuhealth delete mode 100644 gnuhealth/gnuhealth-sao-dependencies.patch delete mode 100644 gnuhealth/lib/systemd/system/gnuhealth.service rename gnuhealth/srv/gnuhealth/{gnuhealth/tryton/server/config => conf}/trytond.conf (66%) diff --git a/README.md b/README.md index 7580446..96c5109 100644 --- a/README.md +++ b/README.md @@ -68,3 +68,4 @@ vi 00-install.sh | Crisis Cleanup | 8005 | 8405 | | CTS | 8006 | 8406 | | OpenMapKit | 8007 | 8407 | +| GNU Health | 8008 | 8408 | diff --git a/gnuhealth.sh b/gnuhealth.sh index 6dd6d41..e7723d3 100755 --- a/gnuhealth.sh +++ b/gnuhealth.sh @@ -2,79 +2,38 @@ SOURCE_DIR=$(realpath $(dirname "${0}"))/gnuhealth -# Install dependencies for GNU Health -apt-get -y --no-install-recommends install python3 python3-virtualenv virtualenv - -# Add NodeJS repository for Sao (Tryton web client) -wget https://deb.nodesource.com/gpgkey/nodesource.gpg.key -O - | apt-key add - -echo 'deb https://deb.nodesource.com/node_8.x stretch main' > /etc/apt/sources.list.d/nodejs.list -apt-get -y update - -# Install dependencies for Sao (Tryton web client) -apt-get -y --no-install-recommends install nodejs - -# Download GNU Health -wget http://ftp.gnu.org/gnu/health/gnuhealth-3.2.8.tar.gz -O /tmp/gnuhealth.tgz -tar xzf /tmp/gnuhealth.tgz -C /srv -mv /srv/gnuhealth-3.2.8 /srv/gnuhealth -rm -f /tmp/gnuhealth.tgz - -# Clone Sao (Tryton web client) repository -git clone -b 4.2 --single-branch --depth 1 https://github.com/tryton/sao /srv/gnuhealth/sao - -# Apply Sao (Tryton web client) dependencies patch -patch -d /srv/gnuhealth/sao -p0 <${SOURCE_DIR}/gnuhealth-sao-dependencies.patch - -# Create Python virtualenv -virtualenv --system-site-packages -p /usr/bin/python3 /srv/gnuhealth -echo '. /srv/gnuhealth/bin/activate' >/srv/gnuhealth/.bash_profile +# Build Docker container +docker build -t gnuhealth ${SOURCE_DIR} # Create databases export GNUHEALTH_PWD=$(head -c 18 /dev/urandom | base64 | tr -d '/+=') -envsubst <${SOURCE_DIR}/tmp/gnuhealth-createdb.sql >/tmp/gnuhealth-createdb.sql -sudo -u postgres psql -f /tmp/gnuhealth-createdb.sql -rm -f /tmp/gnuhealth-createdb.sql - -# Create GNU Health OS user -adduser --system --group --home /srv/gnuhealth --shell /bin/bash gnuhealth -chown -R gnuhealth:gnuhealth /srv/gnuhealth - -# Install GNU Health -sudo -u gnuhealth -i /srv/gnuhealth/gnuhealth-setup install - -# Install Sao (Tryton web client) -sudo -u gnuhealth npm install --production --prefix /srv/gnuhealth/sao -sudo -u gnuhealth bash -c 'cd /srv/gnuhealth/sao && /srv/gnuhealth/sao/node_modules/grunt-cli/bin/grunt' +envsubst <${SOURCE_DIR}/createdb.sql | docker exec -i postgres psql # Configure GNU Health -envsubst <${SOURCE_DIR}/srv/gnuhealth/gnuhealth/tryton/server/config/trytond.conf >/srv/gnuhealth/gnuhealth/tryton/server/config/trytond.conf +mkdir -p /srv/gnuhealth/conf/ +envsubst <${SOURCE_DIR}/srv/gnuhealth/conf/trytond.conf >/srv/gnuhealth/conf/trytond.conf # Populate database export GNUHEALTH_ADMIN_PWD=$(head -c 12 /dev/urandom | base64) -echo ${GNUHEALTH_ADMIN_PWD} >/srv/gnuhealth/.adminpwd -sudo -u gnuhealth -i TRYTONPASSFILE=/srv/gnuhealth/.adminpwd /srv/gnuhealth/gnuhealth/tryton/server/trytond-4.2.8/bin/trytond-admin -d gnuhealth --all -v -rm -f /srv/gnuhealth/.adminpwd +echo ${GNUHEALTH_ADMIN_PWD} >/tmp/.adminpwd +docker run --rm --link=postgres -v /srv/gnuhealth/conf:/srv/gnuhealth/gnuhealth/tryton/server/config -v /tmp/.adminpwd:/tmp/.adminpwd -e TRYTONPASSFILE=/tmp/.adminpwd gnuhealth /srv/gnuhealth/gnuhealth/tryton/server/trytond-4.2.8/bin/trytond-admin -d gnuhealth --all -v +rm -f /tmp/.adminpwd # Populate demo database wget http://health.gnu.org/downloads/postgres_dumps/gnuhealth-3.2rc1.sql.gz -O /tmp/gnuhealth_demo.sql.gz -export PGPASSWORD=${GNUHEALTH_PWD} -zcat /tmp/gnuhealth_demo.sql.gz | psql gnuhealth_demo gnuhealth -unset PGPASSWORD +zcat /tmp/gnuhealth_demo.sql.gz | docker exec -i -e PGPASSWORD=${GNUHEALTH_PWD} postgres psql gnuhealth_demo gnuhealth rm -f /tmp/gnuhealth_demo.sql.gz -# Configure GNU Health service -cp ${SOURCE_DIR}/lib/systemd/system/gnuhealth.service /lib/systemd/system/gnuhealth.service -systemctl daemon-reload -systemctl enable gnuhealth -systemctl start gnuhealth +# Create GNU Health service +cp ${SOURCE_DIR}/etc/init.d/gnuhealth /etc/init.d/gnuhealth +rc-update add gnuhealth boot +service gnuhealth start -# Create nginx site definition -cp ${SOURCE_DIR}/etc/nginx/sites-available/gnuhealth /etc/nginx/sites-available/gnuhealth -ln -s /etc/nginx/sites-available/gnuhealth /etc/nginx/sites-enabled/gnuhealth - -# Restart nginx -systemctl restart nginx +# Create nginx app definition +cp ${SOURCE_DIR}/etc/nginx/apps/gnuhealth /etc/nginx/apps/gnuhealth +cp ${SOURCE_DIR}/etc/nginx/conf.d/gnuhealth.conf /etc/nginx/conf.d/gnuhealth.conf +service nginx reload # Add portal application definition -portal-app-manager gnuhealth "https://{host}:8006/index.html" admin "${GNUHEALTH_ADMIN_PWD}" -portal-app-manager gnuhealth-clients -p clienturl "{host}:8006" +portal-app-manager gnuhealth "https://{host}:8408/index.html" admin "${GNUHEALTH_ADMIN_PWD}" +portal-app-manager gnuhealth-clients -p clienturl "{host}:8008" diff --git a/gnuhealth/Dockerfile b/gnuhealth/Dockerfile new file mode 100644 index 0000000..b75e85c --- /dev/null +++ b/gnuhealth/Dockerfile @@ -0,0 +1,52 @@ +FROM alpine:3.7 +MAINTAINER Disassembler + +RUN \ + # Install Python3 runtime + apk --no-cache add python3 + +RUN \ + # Install runtime XML dependencies + apk --no-cache add libxml2 libxslt + +RUN \ + # Install runtime dependencies + apk --no-cache add bash coreutils libffi libjpeg-turbo libpq nodejs \ + # Install build dependencies + && apk --no-cache add --virtual .deps build-base git libffi-dev libjpeg-turbo-dev libxml2-dev libxslt-dev ncurses patch postgresql-dev python3-dev sudo \ + # Download GNU Health + && wget http://ftp.gnu.org/gnu/health/gnuhealth-3.2.8.tar.gz -O /tmp/gnuhealth.tgz \ + && tar xzf /tmp/gnuhealth.tgz -C /srv \ + && mv /srv/gnuhealth-3.2.8 /srv/gnuhealth \ + && rm -f /tmp/gnuhealth.tgz \ + # Clone Sao (Tryton web client) repository + && git clone -b 4.2 --single-branch --depth 1 https://github.com/tryton/sao /srv/gnuhealth/sao \ + # Symlink python binary + && ln -s /usr/bin/python3 /usr/bin/python \ +# Create OS user + && addgroup -S -g 8008 gnuhealth \ + && adduser -S -u 8008 -h /srv/gnuhealth -s /bin/bash -g gnuhealth -G gnuhealth gnuhealth \ + && chown -R gnuhealth:gnuhealth /srv/gnuhealth \ + # Install GNU Health + && cd /srv/gnuhealth \ + && sudo -u gnuhealth ./gnuhealth-setup install \ + # Install Sao (Tryton web client) dependencies + && cd /srv/gnuhealth/sao \ + && sudo -u gnuhealth npm install grunt grunt-cli grunt-contrib-concat grunt-contrib-jshint grunt-contrib-uglify grunt-contrib-less grunt-po2json \ + && sudo -u gnuhealth npm install --production \ + && sudo -u gnuhealth ./node_modules/.bin/grunt \ + # Cleanup + && apk del .deps \ + && find /srv/gnuhealth -name '.git*' -exec rm -rf {} + \ + && rm -rf /usr/local/share/.cache \ + && rm -rf /root \ + && mkdir /root + +VOLUME ["/srv/gnuhealth/gnuhealth/tryton/server/config"] +EXPOSE 8008 + +USER gnuhealth +ENV PATH=/srv/gnuhealth/gnuhealth/tryton/server/trytond-4.2.8/bin:${PATH} \ + TRYTOND_CONFIG=/srv/gnuhealth/gnuhealth/tryton/server/config/trytond.conf \ + PYTHONPATH=/srv/gnuhealth/gnuhealth/tryton/server/trytond-4.2.8:/srv/gnuhealth/gnuhealth/tryton/server/config +CMD ["trytond", "--verbose"] diff --git a/gnuhealth/tmp/gnuhealth-createdb.sql b/gnuhealth/createdb.sql similarity index 100% rename from gnuhealth/tmp/gnuhealth-createdb.sql rename to gnuhealth/createdb.sql diff --git a/gnuhealth/etc/init.d/gnuhealth b/gnuhealth/etc/init.d/gnuhealth new file mode 100755 index 0000000..9415005 --- /dev/null +++ b/gnuhealth/etc/init.d/gnuhealth @@ -0,0 +1,17 @@ +#!/sbin/openrc-run + +description="GNU Health docker container" + +depend() { + need docker net + use dns logger netmount + after postgres +} + +start() { + /usr/bin/docker run -d --rm --name gnuhealth --link=postgres -p 127.0.0.1:9008:8008 -v /srv/gnuhealth/conf:/srv/gnuhealth/gnuhealth/tryton/server/config gnuhealth +} + +stop() { + /usr/bin/docker stop gnuhealth +} diff --git a/gnuhealth/etc/nginx/apps/gnuhealth b/gnuhealth/etc/nginx/apps/gnuhealth new file mode 100644 index 0000000..c6aa86b --- /dev/null +++ b/gnuhealth/etc/nginx/apps/gnuhealth @@ -0,0 +1,9 @@ +access_log /var/log/nginx/gnuhealth.access.log; +error_log /var/log/nginx/gnuhealth.error.log; + +location / { + proxy_set_header X-Forwarded-For $remote_addr; + proxy_set_header X-Forwarded-Host $host:$server_port; + proxy_set_header X-Forwarded-Proto $scheme; + proxy_pass http://127.0.0.1:9008; +} diff --git a/gnuhealth/etc/nginx/conf.d/gnuhealth.conf b/gnuhealth/etc/nginx/conf.d/gnuhealth.conf new file mode 100644 index 0000000..f3c292f --- /dev/null +++ b/gnuhealth/etc/nginx/conf.d/gnuhealth.conf @@ -0,0 +1,11 @@ +server { + listen 8008; + listen [::]:8008; + include apps/gnuhealth; +} + +server { + listen 8408 ssl http2; + listen [::]:8408 ssl http2; + include apps/gnuhealth; +} diff --git a/gnuhealth/etc/nginx/sites-available/gnuhealth b/gnuhealth/etc/nginx/sites-available/gnuhealth deleted file mode 100644 index 5e0b065..0000000 --- a/gnuhealth/etc/nginx/sites-available/gnuhealth +++ /dev/null @@ -1,17 +0,0 @@ -server { - listen 8006 ssl http2; - listen [::]:8006 ssl http2; - - access_log /var/log/nginx/gnuhealth.access.log; - error_log /var/log/nginx/gnuhealth.error.log; - - root /srv/gnuhealth/sao; - try_files $uri @gnuhealth; - - location @gnuhealth { - proxy_set_header X-Forwarded-For $remote_addr; - proxy_set_header X-Forwarded-Host $host:$server_port; - proxy_set_header X-Forwarded-Proto https; - proxy_pass http://127.0.0.1:8097; - } -} diff --git a/gnuhealth/gnuhealth-sao-dependencies.patch b/gnuhealth/gnuhealth-sao-dependencies.patch deleted file mode 100644 index 592ea0b..0000000 --- a/gnuhealth/gnuhealth-sao-dependencies.patch +++ /dev/null @@ -1,16 +0,0 @@ ---- package.bak 2017-12-03 23:27:54.280162096 +0100 -+++ package.json 2017-12-03 23:29:24.384721720 +0100 -@@ -54,6 +54,13 @@ - "tryton" - ], - "dependencies": { -+ "grunt": "^0.4", -+ "grunt-cli": "^0.1", -+ "grunt-contrib-concat": "^0.5", -+ "grunt-contrib-jshint": "^0.11", -+ "grunt-contrib-uglify": "^0.9", -+ "grunt-contrib-less": "^1.2", -+ "grunt-po2json": "^0.3", - "bower": "^1.7" - } - } diff --git a/gnuhealth/lib/systemd/system/gnuhealth.service b/gnuhealth/lib/systemd/system/gnuhealth.service deleted file mode 100644 index 12fb32c..0000000 --- a/gnuhealth/lib/systemd/system/gnuhealth.service +++ /dev/null @@ -1,16 +0,0 @@ -[Unit] -Description=GNU Health Server -After=network.target - -[Service] -Type=simple -User=gnuhealth -Environment=TRYTOND_CONFIG=/srv/gnuhealth/gnuhealth/tryton/server/config/trytond.conf -Environment=VIRTUAL_ENV=/srv/gnuhealth -Environment=PYTHONPATH=/srv/gnuhealth/gnuhealth/tryton/server/trytond-4.2.8:/srv/gnuhealth/gnuhealth/tryton/server/config -Environment=PATH=/srv/gnuhealth/bin:/usr/local/bin:/usr/bin:/bin -WorkingDirectory=/srv/gnuhealth -ExecStart=/srv/gnuhealth/gnuhealth/tryton/server/trytond-4.2.8/bin/trytond - -[Install] -WantedBy=multi-user.target diff --git a/gnuhealth/srv/gnuhealth/gnuhealth/tryton/server/config/trytond.conf b/gnuhealth/srv/gnuhealth/conf/trytond.conf similarity index 66% rename from gnuhealth/srv/gnuhealth/gnuhealth/tryton/server/config/trytond.conf rename to gnuhealth/srv/gnuhealth/conf/trytond.conf index f1f3f9c..c3ecf43 100644 --- a/gnuhealth/srv/gnuhealth/gnuhealth/tryton/server/config/trytond.conf +++ b/gnuhealth/srv/gnuhealth/conf/trytond.conf @@ -1,9 +1,9 @@ [database] -uri = postgresql://gnuhealth:${GNUHEALTH_PWD}@localhost +uri = postgresql://gnuhealth:${GNUHEALTH_PWD}@postgres path = /srv/gnuhealth/attach [web] -listen = 127.0.0.1:8097 +listen = 0.0.0.0:8008 root = /srv/gnuhealth/sao [webdav]