From 1a4756fda040b2a655df4de74448df33116e034a Mon Sep 17 00:00:00 2001 From: Alec Turner Date: Thu, 29 Feb 2024 16:37:12 -0800 Subject: [PATCH] correct entry script bug and allow config from env file - A bug in `entry` caused the script to not change into the directory correctly. This was corrected by marking the script as bash rather than sh. - `install.sh` now stops a running service before updating - `docker-compose.yml` now assigns a consistent container name for the app - `docker-compose.yml` now uses environment variables or a `.env` file to assign container name and port mappings if available - updated readme file with better instructions --- README.md | 38 ++++++++++++++++--- install.sh | 14 +++++-- .../streamline-emr/docker-compose.yml | 5 ++- .../streamline/streamline-emr/entry | 18 +++++++-- template.env | 2 + 5 files changed, 63 insertions(+), 14 deletions(-) create mode 100644 template.env diff --git a/README.md b/README.md index 6216614d..0ba3ba46 100644 --- a/README.md +++ b/README.md @@ -2,13 +2,39 @@ Packaging and installation tools for Streamline's "Streamline EMR" application. -## Usage +## Building 1. ensure you have docker access to this project's container registry on GitLab 2. run `package.sh` to generate a new application package 3. package will be stored to `build-packages/` -## Notes -- Example of running the app directly -```bash -docker run --rm -d --name streamline -p 3000:80 -p 6607:3306 -v ./data:/var/lib/mysql registry.gitlab.com/signalytic/client-external/streamline/streamline-emr:2.0 -``` \ No newline at end of file +## Installing +1. extract the generated archive file in a temporary folder on the target system +2. run `install.sh` + +## Running +### Production (systemd) +On a production system, `systemd` will manage the lifecycle of the application, e.g. +``` +# enable and start the the application service +systemctl daemon-reload +systemctl enable streamline-emr +systemctl start streamline-emr + +# stop the application service +systemctl stop streamline-emr + +# restart the application service +systemctl restart streamline-emr +``` + +### Docker +In a docker environment, the application must be started manually. This is done by running the `entry` script, for example: +``` +/var/signalytic/clientapps/streamline/streamline-emr/entry +``` + +## Configuration +Certain configuration options can be adjusted by setting environment variables or by defining these variables in a `.env` file stored in the same directory as the `docker-compose.yml` file. These variables are: +`APP_PORTS`: port mapping for the web app server (default: `3000:80`) +`DB_PORTS`: port mapping for the database server (default: `6607:3306`) +`CONTAINER_NAME`: name of the application container (default: `streamline-emr`) \ No newline at end of file diff --git a/install.sh b/install.sh index 2f9c9820..7d74ccd2 100755 --- a/install.sh +++ b/install.sh @@ -21,6 +21,15 @@ if [ "$EUID" -ne 0 ] exit 1 fi + +# stop any running systemd service if not running in a docker environment +if [ -f /.dockerenv ]; then + echo "Docker environment detected - skipping systemd installation" +else + echo "stopping system service" + systemctl stop streamline-emr +fi + set -e # copy root files @@ -33,9 +42,8 @@ for f in $(find $LOCATION/images -name "*.img");do docker load -i $f done -if [ -f /.dockerenv ]; then - echo "Docker environment detected - skipping systemd installation" -else +# install systemd service unless running in a docker environment +if [ ! -f /.dockerenv ]; then echo "installing system service" systemctl daemon-reload systemctl enable streamline-emr diff --git a/root/var/signalytic/clientapps/streamline/streamline-emr/docker-compose.yml b/root/var/signalytic/clientapps/streamline/streamline-emr/docker-compose.yml index 22699a71..9dec5dc0 100644 --- a/root/var/signalytic/clientapps/streamline/streamline-emr/docker-compose.yml +++ b/root/var/signalytic/clientapps/streamline/streamline-emr/docker-compose.yml @@ -2,8 +2,9 @@ version: '3.9' services: streamline-emr: image: registry.gitlab.com/signalytic/client-external/streamline/streamline-emr:2.0 + container_name: ${CONTAINER_NAME:-streamline-emr} volumes: - '/var/signalytic/clientapps/streamline/streamline-emr/data:/var/lib/mysql' ports: - - '3000:80' - - '6607:3306' \ No newline at end of file + - ${APP_PORTS:-3000:80} + - ${DB_PORTS:-6607:3306} \ No newline at end of file diff --git a/root/var/signalytic/clientapps/streamline/streamline-emr/entry b/root/var/signalytic/clientapps/streamline/streamline-emr/entry index 2a10d597..0eeb9dac 100755 --- a/root/var/signalytic/clientapps/streamline/streamline-emr/entry +++ b/root/var/signalytic/clientapps/streamline/streamline-emr/entry @@ -1,5 +1,17 @@ -#!/bin/sh -cd "$(dirname "${BASH_SOURCE[0]}")" +#!/bin/bash + +APPROOT="$(dirname "${BASH_SOURCE[0]}")" + +echo "entering app root: $APPROOT" +cd $APPROOT + +echo "creating data folder (if necessary)" mkdir -p data -docker compose up --force-recreate + +echo "starting app" +docker compose up + +echo "cleaning up" docker compose down + +echo "done." diff --git a/template.env b/template.env new file mode 100644 index 00000000..e0828c84 --- /dev/null +++ b/template.env @@ -0,0 +1,2 @@ +APP_PORTS="3001:80" +DB_PORTS="6607:3306" \ No newline at end of file