OpenMapKit concept

This commit is contained in:
Disassembler 2017-12-12 13:29:33 +01:00
parent 71da796259
commit 145b73c3ce
3 changed files with 34 additions and 31 deletions

View File

@ -2,36 +2,17 @@
SOURCE_DIR=$(realpath $(dirname "${0}"))/openmapkit
# Add NodeJS repository
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 OpenMapKit dependencies
apt-get install --no-install-recommends -y build-essential nodejs python-dev python-virtualenv virtualenv
# Clone repositories
git clone --depth 1 https://github.com/AmericanRedCross/OpenMapKitServer /srv/omk
git -C /srv/omk submodule update --init
# Install OpenMapKit python virtual environment
virtualenv --no-site-packages --python=/usr/bin/python2.7 /srv/omk
/srv/omk/bin/pip install -r /srv/omk/requirements.txt
# Create OpenMapKit OS user
adduser --system --group --home /srv/omk --shell /bin/bash omk
chown -R omk:omk /srv/omk
# Install NodeJS dependencies
sudo -u omk -i npm install yarn
sudo -u omk -i npm install libxmljs
sudo -u omk -i /srv/omk/node_modules/yarn/bin/yarn
# Prepare Docker mount structure
mkdir -p /srv/omk/data/{deployments,submissions}
# Configure OpenMapKit
export OMK_ADMIN_USER="admin"
export OMK_ADMIN_PWD=$(head -c 12 /dev/urandom | base64)
envsubst <${SOURCE_DIR}/srv/omk/settings.js >/srv/omk/settings.js
# Build Docker container
docker build -t openmapkit ${SOURCE_DIR}
# Configure OpenMapKit service
cp ${SOURCE_DIR}/lib/systemd/system/openmapkit.service /lib/systemd/system/openmapkit.service
systemctl daemon-reload

26
openmapkit/Dockerfile Normal file
View File

@ -0,0 +1,26 @@
FROM alpine:3.7
MAINTAINER Disassembler <disassembler@dasm.cz>
RUN apk --no-cache add python2
RUN apk --no-cache add nodejs git build-base openjdk8-jre-base py-setuptools py2-pip \
&& git clone --depth 1 https://github.com/AmericanRedCross/OpenMapKitServer /srv/omk \
&& cd /srv/omk \
&& git submodule update --init \
&& pip install -r requirements.txt \
&& npm install -g yarn \
&& npm install libxmljs \
&& yarn \
&& addgroup -S omk \
&& adduser -S -h /srv/omk -H -s /bin/sh -g omk -G omk omk \
&& chown -R omk:omk /srv/omk/data/deployments /srv/omk/data/submissions \
&& apk --no-cache del git build-base py-setuptools py2-pip \
&& rm -rf /srv/omk/.git* /srv/omk/api/odk/pyxform/.git* \
&& rm -rf /root/* || true
VOLUME ["/srv/omk/data"]
EXPOSE 3210
USER omk
ENV NODE_ENV production
CMD ["node", "/srv/omk/server.js"]

View File

@ -1,15 +1,11 @@
[Unit]
Description=OpenMapKit Server
Description=OpenMapKit Docker container
After=network.target
[Service]
Type=simple
User=omk
Environment=NODE_ENV=production
Environment=VIRTUAL_ENV=/srv/omk
Environment=PATH=/srv/omk/bin:/usr/local/bin:/usr/bin:/bin
WorkingDirectory=/srv/omk
ExecStart=/usr/bin/node server.js
ExecStart=/usr/bin/docker run --rm --tmpfs /tmp --name openmapkit -v /srv/omk/settings.js:/srv/omk/settings.js -v /srv/omk/data:/srv/omk/data openmapkit
ExecStop=/usr/bin/docker stop openmapkit
[Install]
WantedBy=multi-user.target