From ca3d2f5540decdeda30ad2499c9e517553b2a28f Mon Sep 17 00:00:00 2001 From: Alec Turner Date: Wed, 28 Feb 2024 15:50:45 -0800 Subject: [PATCH 01/11] Implement basic packaging/install/entry scripts The packaging script will create a new tar.bz2 archive containing an install script, a set of docker images, and a root folder with files to be installed. The root folder includes a systemd service, a docker compose file, an entry script, and a template config file. On installation docker images are loaded onto the target system, install files are copied, then systemd services are installed. --- .gitignore | 1 + README.md | 99 ++----------------- install.sh | 43 ++++++++ package.sh | 92 +++++++++++++++++ .../etc/systemd/system/streamline-emr.service | 14 +++ .../streamline-emr/docker-compose.yml | 9 ++ .../streamline/streamline-emr/entry | 5 + .../streamline-emr/template.app.conf | 22 +++++ 8 files changed, 196 insertions(+), 89 deletions(-) create mode 100644 .gitignore create mode 100755 install.sh create mode 100755 package.sh create mode 100644 root/etc/systemd/system/streamline-emr.service create mode 100644 root/var/signalytic/clientapps/streamline/streamline-emr/docker-compose.yml create mode 100755 root/var/signalytic/clientapps/streamline/streamline-emr/entry create mode 100644 root/var/signalytic/clientapps/streamline/streamline-emr/template.app.conf diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..d980930a --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +build-packages diff --git a/README.md b/README.md index c1d96e03..6216614d 100644 --- a/README.md +++ b/README.md @@ -1,93 +1,14 @@ -# Streamline Emr +# Streamline EMR - - -## Getting started - -To make it easy for you to get started with GitLab, here's a list of recommended next steps. - -Already a pro? Just edit this README.md and make it your own. Want to make it easy? [Use the template at the bottom](#editing-this-readme)! - -## Add your files - -- [ ] [Create](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#create-a-file) or [upload](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#upload-a-file) files -- [ ] [Add files using the command line](https://docs.gitlab.com/ee/gitlab-basics/add-file.html#add-a-file-using-the-command-line) or push an existing Git repository with the following command: - -``` -cd existing_repo -git remote add origin https://gitlab.com/signalytic/client-external/streamline/streamline-emr.git -git branch -M main -git push -uf origin main -``` - -## Integrate with your tools - -- [ ] [Set up project integrations](https://gitlab.com/signalytic/client-external/streamline/streamline-emr/-/settings/integrations) - -## Collaborate with your team - -- [ ] [Invite team members and collaborators](https://docs.gitlab.com/ee/user/project/members/) -- [ ] [Create a new merge request](https://docs.gitlab.com/ee/user/project/merge_requests/creating_merge_requests.html) -- [ ] [Automatically close issues from merge requests](https://docs.gitlab.com/ee/user/project/issues/managing_issues.html#closing-issues-automatically) -- [ ] [Enable merge request approvals](https://docs.gitlab.com/ee/user/project/merge_requests/approvals/) -- [ ] [Set auto-merge](https://docs.gitlab.com/ee/user/project/merge_requests/merge_when_pipeline_succeeds.html) - -## Test and Deploy - -Use the built-in continuous integration in GitLab. - -- [ ] [Get started with GitLab CI/CD](https://docs.gitlab.com/ee/ci/quick_start/index.html) -- [ ] [Analyze your code for known vulnerabilities with Static Application Security Testing (SAST)](https://docs.gitlab.com/ee/user/application_security/sast/) -- [ ] [Deploy to Kubernetes, Amazon EC2, or Amazon ECS using Auto Deploy](https://docs.gitlab.com/ee/topics/autodevops/requirements.html) -- [ ] [Use pull-based deployments for improved Kubernetes management](https://docs.gitlab.com/ee/user/clusters/agent/) -- [ ] [Set up protected environments](https://docs.gitlab.com/ee/ci/environments/protected_environments.html) - -*** - -# Editing this README - -When you're ready to make this README your own, just edit this file and use the handy template below (or feel free to structure it however you want - this is just a starting point!). Thanks to [makeareadme.com](https://www.makeareadme.com/) for this template. - -## Suggestions for a good README - -Every project is different, so consider which of these sections apply to yours. The sections used in the template are suggestions for most open source projects. Also keep in mind that while a README can be too long and detailed, too long is better than too short. If you think your README is too long, consider utilizing another form of documentation rather than cutting out information. - -## Name -Choose a self-explaining name for your project. - -## Description -Let people know what your project can do specifically. Provide context and add a link to any reference visitors might be unfamiliar with. A list of Features or a Background subsection can also be added here. If there are alternatives to your project, this is a good place to list differentiating factors. - -## Badges -On some READMEs, you may see small images that convey metadata, such as whether or not all the tests are passing for the project. You can use Shields to add some to your README. Many services also have instructions for adding a badge. - -## Visuals -Depending on what you are making, it can be a good idea to include screenshots or even a video (you'll frequently see GIFs rather than actual videos). Tools like ttygif can help, but check out Asciinema for a more sophisticated method. - -## Installation -Within a particular ecosystem, there may be a common way of installing things, such as using Yarn, NuGet, or Homebrew. However, consider the possibility that whoever is reading your README is a novice and would like more guidance. Listing specific steps helps remove ambiguity and gets people to using your project as quickly as possible. If it only runs in a specific context like a particular programming language version or operating system or has dependencies that have to be installed manually, also add a Requirements subsection. +Packaging and installation tools for Streamline's "Streamline EMR" application. ## Usage -Use examples liberally, and show the expected output if you can. It's helpful to have inline the smallest example of usage that you can demonstrate, while providing links to more sophisticated examples if they are too long to reasonably include in the README. +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/` -## Support -Tell people where they can go to for help. It can be any combination of an issue tracker, a chat room, an email address, etc. - -## Roadmap -If you have ideas for releases in the future, it is a good idea to list them in the README. - -## Contributing -State if you are open to contributions and what your requirements are for accepting them. - -For people who want to make changes to your project, it's helpful to have some documentation on how to get started. Perhaps there is a script that they should run or some environment variables that they need to set. Make these steps explicit. These instructions could also be useful to your future self. - -You can also document commands to lint the code or run tests. These steps help to ensure high code quality and reduce the likelihood that the changes inadvertently break something. Having instructions for running tests is especially helpful if it requires external setup, such as starting a Selenium server for testing in a browser. - -## Authors and acknowledgment -Show your appreciation to those who have contributed to the project. - -## License -For open source projects, say how it is licensed. - -## Project status -If you have run out of energy or time for your project, put a note at the top of the README saying that development has slowed down or stopped completely. Someone may choose to fork your project or volunteer to step in as a maintainer or owner, allowing your project to keep going. You can also make an explicit request for maintainers. +## 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 diff --git a/install.sh b/install.sh new file mode 100755 index 00000000..2f9c9820 --- /dev/null +++ b/install.sh @@ -0,0 +1,43 @@ +#!/bin/bash +# +# Copyright (C) Wendepunkt Medical Innovations, Inc - All Rights Reserved. +# Unauthorized copying of this file, via any medium is strictly prohibited. +# Proprietary and confidential +# +# For information: dev@signalytic.ca +# + +# +# Install the Streamline "Streamline EMR" application and services +# +# The caller of this script must check the exit value and possibly do a +# roll-back if it is non-zero. If the exit value is non-zero services have not +# been restarted. + +LOCATION="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" + +if [ "$EUID" -ne 0 ] + then echo "Please run as root" + exit 1 +fi + +set -e + +# copy root files +echo "importing root files" +cp -rfv $LOCATION/root/* / + +# import docker images +for f in $(find $LOCATION/images -name "*.img");do + echo "importing docker image: $f" + docker load -i $f +done + +if [ -f /.dockerenv ]; then + echo "Docker environment detected - skipping systemd installation" +else + echo "installing system service" + systemctl daemon-reload + systemctl enable streamline-emr + systemctl start streamline-emr +fi diff --git a/package.sh b/package.sh new file mode 100755 index 00000000..58c2e462 --- /dev/null +++ b/package.sh @@ -0,0 +1,92 @@ +#!/bin/bash + +# +# Copyright (C) Wendepunkt Medical Innovations, Inc - All Rights Reserved. +# Unauthorized copying of this file, via any medium is strictly prohibited. +# Proprietary and confidential +# +# For information: dev@signalytic.ca +# + +# basic path info +LOCATION="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" +PROJECT_ROOT="$(realpath $LOCATION)" +PACKAGE_NAME="streamline-emr" +OUTPUT_DIR="$PROJECT_ROOT/build-packages" + +# work from the project root +pushd $PROJECT_ROOT > /dev/null + +# Exit on error: +set -e +trap 'echo "Error: Last command failed with exit code $?."' ERR + +# generate version name +# use ci tag name if available (e.g. "v1.2") +if [ $CI_COMMIT_TAG ]; then + VERSION_NAME="$CI_COMMIT_TAG" + +# otherwise if ci, use BRANCH-COMMIT +# Note: commit count is harder to get to from CI - can't reproduce the git +# describe functionality as easily +elif [ $CI_COMMIT_BRANCH ]; then + VERSION_NAME="$CI_COMMIT_REF_SLUG-$CI_COMMIT_SHORT_SHA" + +# if not ci, try to use git +elif command -v git &> /dev/null; then + VERSION_NAME=$(git describe --always --tags --dirty) + +# fallback +else + VERSION_NAME="unknown" +fi + +OUTPUT_NAME="$PACKAGE_NAME-$VERSION_NAME-$(arch)" +OUTPUT_FILE="$OUTPUT_NAME.tar.bz2" +OUTPUT_PATH="$OUTPUT_DIR/$OUTPUT_FILE" + +# create a new temp directory to stage files +for i in {1..9999};do + STAGING_DIR="tmp-staging-$i" + if [ ! -d $STAGING_DIR ]; then + break + fi +done +if [ -d $STAGING_DIR ]; then + echo "Failed to generate temp staging dir" + exit 1 +fi + +# add files +mkdir ${STAGING_DIR} +cp ${PROJECT_ROOT}/install.sh ${STAGING_DIR}/ +cp -a ${PROJECT_ROOT}/root ${STAGING_DIR}/ + +# add images +IMAGES_DIR=${STAGING_DIR}/images +mkdir -p ${IMAGES_DIR} +i=0 +for image in $(find root/ -name docker-compose.yml | xargs grep 'image:.*' | awk '{print $2}');do + i=$((i+1)) + name="image${i}.img" + echo "addding '$name' -> '$image'" + docker pull $image + docker save -o ${IMAGES_DIR}/$name $image +done + +# setup output directory and cleanup old files if necessary +mkdir -p $OUTPUT_DIR +rm -rf $OUTPUT_PATH + +pushd $STAGING_DIR > /dev/null +tar -cjf $OUTPUT_PATH * +popd > /dev/null + +# cleanup staging files +rm -r $STAGING_DIR + +echo "output: $OUTPUT_PATH" + +popd > /dev/null + +exit 0 diff --git a/root/etc/systemd/system/streamline-emr.service b/root/etc/systemd/system/streamline-emr.service new file mode 100644 index 00000000..d882702c --- /dev/null +++ b/root/etc/systemd/system/streamline-emr.service @@ -0,0 +1,14 @@ +[Unit] +Description=Run Streamline EMR +After=network.target +StartLimitIntervalSec=0 + +[Service] +Type=simple +Restart=always +RestartSec=10 +User=root +ExecStart=/var/signalytic/clientapps/streamline/streamline-emr/entry + +[Install] +WantedBy=multi-user.target \ No newline at end of file diff --git a/root/var/signalytic/clientapps/streamline/streamline-emr/docker-compose.yml b/root/var/signalytic/clientapps/streamline/streamline-emr/docker-compose.yml new file mode 100644 index 00000000..22699a71 --- /dev/null +++ b/root/var/signalytic/clientapps/streamline/streamline-emr/docker-compose.yml @@ -0,0 +1,9 @@ +version: '3.9' +services: + streamline-emr: + image: registry.gitlab.com/signalytic/client-external/streamline/streamline-emr:2.0 + volumes: + - '/var/signalytic/clientapps/streamline/streamline-emr/data:/var/lib/mysql' + ports: + - '3000:80' + - '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 new file mode 100755 index 00000000..2a10d597 --- /dev/null +++ b/root/var/signalytic/clientapps/streamline/streamline-emr/entry @@ -0,0 +1,5 @@ +#!/bin/sh +cd "$(dirname "${BASH_SOURCE[0]}")" +mkdir -p data +docker compose up --force-recreate +docker compose down diff --git a/root/var/signalytic/clientapps/streamline/streamline-emr/template.app.conf b/root/var/signalytic/clientapps/streamline/streamline-emr/template.app.conf new file mode 100644 index 00000000..5be3965c --- /dev/null +++ b/root/var/signalytic/clientapps/streamline/streamline-emr/template.app.conf @@ -0,0 +1,22 @@ +{ + "name": "Streamline EMR", + "database": { + "type": "mysql", + "version": "mariadb:15.1", + "name": "streamline", + "source": "streamline-emr", + "username": "", + "password": "", + "db_path": "/var/lib/mysql", + "logs_path": "/var/lib/mysql/logs", + "log_pattern": "bin.[0-9]*" + }, + "blockgraph": { + "district": "", + "name": "", + "node": "", + "location": "", + "username": "", + "password": "" + } +} From 1a4756fda040b2a655df4de74448df33116e034a Mon Sep 17 00:00:00 2001 From: Alec Turner Date: Thu, 29 Feb 2024 16:37:12 -0800 Subject: [PATCH 02/11] 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 From 7c528766b0a163054f21833e8a37731a8bce550c Mon Sep 17 00:00:00 2001 From: Alec Turner Date: Fri, 1 Mar 2024 11:05:50 -0800 Subject: [PATCH 03/11] updates to docker-compose.yml and documentation to allow runtime configuration Further configuration options are made available to support running multiple instances of the app on the same machine, including the use of docker sibling containers. `README.md` and `template.env` are updated accordingly. The database port is no longer exposed as this is not required to access and manage the app at this time. --- README.md | 11 ++++++++--- .../streamline/streamline-emr/docker-compose.yml | 5 ++--- template.env | 6 ++++-- 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 0ba3ba46..07a7fd50 100644 --- a/README.md +++ b/README.md @@ -33,8 +33,13 @@ In a docker environment, the application must be started manually. This is done /var/signalytic/clientapps/streamline/streamline-emr/entry ``` +If multiple instances are run from the same machine, additional configuration may be required to differentiate the instances. This is generally the case when using the "sibling container" method for running docker from within a docker container. See the `Configuration` section for more details. + ## 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 +`APP_PORT`: port mapping for the web app server (default: `3000`) +`CONTAINER_NAME`: name of the application container (default: `streamline-emr`) +`DATA_DIR`: directory to be mounted for peristent data (default: `/var/signalytic/clientapps/streamline/streamline-emr/data`) +`COMPOSE_PROJECT_NAME`: assign the project name associate with the compose file - this avoids conflicts when the "same" compose file is used to manage multiple instances (e.g. when using docker sibling containers) + +Important note when using "sibling containers": the sibling container method uses the host docker socket to provide containers with access to docker. As a result, port mappings and volumne mount points all refer to the host system rather than the container from which the docker command originates. \ No newline at end of file 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 9dec5dc0..beced585 100644 --- a/root/var/signalytic/clientapps/streamline/streamline-emr/docker-compose.yml +++ b/root/var/signalytic/clientapps/streamline/streamline-emr/docker-compose.yml @@ -4,7 +4,6 @@ services: 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' + - "${DATA_DIR:-/var/signalytic/clientapps/streamline/streamline-emr/data}:/var/lib/mysql" ports: - - ${APP_PORTS:-3000:80} - - ${DB_PORTS:-6607:3306} \ No newline at end of file + - "${APP_PORT:-3000}:80" \ No newline at end of file diff --git a/template.env b/template.env index e0828c84..23e8a83b 100644 --- a/template.env +++ b/template.env @@ -1,2 +1,4 @@ -APP_PORTS="3001:80" -DB_PORTS="6607:3306" \ No newline at end of file +APP_PORT=3000 +CONTAINER_NAME=streamline-emr-1 +COMPOSE_PROJECT_NAME=streamline-emr-1 +DATA_DIR=/path/to/volume/mount/dir \ No newline at end of file From 3c3af113603d624a48542e1412e0fbcabd2ac223 Mon Sep 17 00:00:00 2001 From: Alec Turner Date: Tue, 5 Mar 2024 15:12:55 -0800 Subject: [PATCH 04/11] build separate x86_64/aarch64 packages and explicitly define images --- images-aarch64 | 1 + images-x86_64 | 1 + package.sh | 95 +++++++++++-------- .../streamline-emr/docker-compose.yml | 2 +- 4 files changed, 60 insertions(+), 39 deletions(-) create mode 100644 images-aarch64 create mode 100644 images-x86_64 diff --git a/images-aarch64 b/images-aarch64 new file mode 100644 index 00000000..85c8f99f --- /dev/null +++ b/images-aarch64 @@ -0,0 +1 @@ +streamline-emr:2.0=registry.gitlab.com/signalytic/client-external/streamline/streamline-emr/arm64:2.0 \ No newline at end of file diff --git a/images-x86_64 b/images-x86_64 new file mode 100644 index 00000000..700ea70f --- /dev/null +++ b/images-x86_64 @@ -0,0 +1 @@ +streamline-emr:2.0=registry.gitlab.com/signalytic/client-external/streamline/streamline-emr/amd64:2.0 \ No newline at end of file diff --git a/package.sh b/package.sh index 58c2e462..00dd8c3d 100755 --- a/package.sh +++ b/package.sh @@ -41,51 +41,70 @@ else VERSION_NAME="unknown" fi -OUTPUT_NAME="$PACKAGE_NAME-$VERSION_NAME-$(arch)" -OUTPUT_FILE="$OUTPUT_NAME.tar.bz2" -OUTPUT_PATH="$OUTPUT_DIR/$OUTPUT_FILE" - -# create a new temp directory to stage files -for i in {1..9999};do - STAGING_DIR="tmp-staging-$i" - if [ ! -d $STAGING_DIR ]; then - break +# build for each relevant platform +for platform in "linux/amd64" "linux/arm64"; do + echo "preparing package for platform $platform" + if [ "$platform" == "linux/amd64" ];then + pkg_arch="x86_64" + elif [ "$platform" == "linux/arm64" ];then + pkg_arch="aarch64" + else + echo "unexpected platform '$platform'" + exit 1 fi -done -if [ -d $STAGING_DIR ]; then - echo "Failed to generate temp staging dir" - exit 1 -fi + OUTPUT_NAME="$PACKAGE_NAME-$VERSION_NAME-${pkg_arch}" + OUTPUT_FILE="$OUTPUT_NAME.tar.bz2" + OUTPUT_PATH="$OUTPUT_DIR/$OUTPUT_FILE" -# add files -mkdir ${STAGING_DIR} -cp ${PROJECT_ROOT}/install.sh ${STAGING_DIR}/ -cp -a ${PROJECT_ROOT}/root ${STAGING_DIR}/ + # create a new temp directory to stage files + for i in {1..9999};do + STAGING_DIR="tmp-staging-$i" + if [ ! -d $STAGING_DIR ]; then + break + fi + done + if [ -d $STAGING_DIR ]; then + echo "Failed to generate temp staging dir" + exit 1 + fi -# add images -IMAGES_DIR=${STAGING_DIR}/images -mkdir -p ${IMAGES_DIR} -i=0 -for image in $(find root/ -name docker-compose.yml | xargs grep 'image:.*' | awk '{print $2}');do - i=$((i+1)) - name="image${i}.img" - echo "addding '$name' -> '$image'" - docker pull $image - docker save -o ${IMAGES_DIR}/$name $image -done + # add files + mkdir ${STAGING_DIR} + cp ${PROJECT_ROOT}/install.sh ${STAGING_DIR}/ + cp -a ${PROJECT_ROOT}/root ${STAGING_DIR}/ -# setup output directory and cleanup old files if necessary -mkdir -p $OUTPUT_DIR -rm -rf $OUTPUT_PATH + # add images + IMAGES_DIR=${STAGING_DIR}/images + mkdir -p ${IMAGES_DIR} + i=0 + # read image list from file (e.g. 'images-aarch64') + # images are listed as SAVED_TAG=SOURCE_IMAGE + for image in $(cat ${PROJECT_ROOT}/images-${pkg_arch});do + i=$((i+1)) + name="image${i}.img" + path="${IMAGES_DIR}/${name}" + IFS=\= read -r dest source <<< "${image}" + echo "pulling image '${source}' (${platform})" + docker pull --platform ${platform} ${source} + echo "tagging image as '${dest}'" + docker tag ${source} ${dest} + echo "saving to '${path}'" + docker save -o ${path} $dest + done -pushd $STAGING_DIR > /dev/null -tar -cjf $OUTPUT_PATH * -popd > /dev/null + # setup output directory and cleanup old files if necessary + mkdir -p $OUTPUT_DIR + rm -rf $OUTPUT_PATH -# cleanup staging files -rm -r $STAGING_DIR + pushd $STAGING_DIR > /dev/null + tar -cjf $OUTPUT_PATH * + popd > /dev/null -echo "output: $OUTPUT_PATH" + # cleanup staging files + rm -r $STAGING_DIR + + echo "output: $OUTPUT_PATH" +done popd > /dev/null 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 beced585..1ad963a5 100644 --- a/root/var/signalytic/clientapps/streamline/streamline-emr/docker-compose.yml +++ b/root/var/signalytic/clientapps/streamline/streamline-emr/docker-compose.yml @@ -1,7 +1,7 @@ version: '3.9' services: streamline-emr: - image: registry.gitlab.com/signalytic/client-external/streamline/streamline-emr:2.0 + image: streamline-emr:2.0 container_name: ${CONTAINER_NAME:-streamline-emr} volumes: - "${DATA_DIR:-/var/signalytic/clientapps/streamline/streamline-emr/data}:/var/lib/mysql" From 407baf972793f838c77d8312d8dbba6cfb7e1fe1 Mon Sep 17 00:00:00 2001 From: Alec Turner Date: Wed, 6 Mar 2024 09:03:03 -0800 Subject: [PATCH 05/11] correction to package format the package format was slightly off - there should have been a folder in the root of the archive wrapping the package contents. This is now implemented. --- package.sh | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/package.sh b/package.sh index 00dd8c3d..8b4b2b1c 100755 --- a/package.sh +++ b/package.sh @@ -69,13 +69,13 @@ for platform in "linux/amd64" "linux/arm64"; do fi # add files - mkdir ${STAGING_DIR} - cp ${PROJECT_ROOT}/install.sh ${STAGING_DIR}/ - cp -a ${PROJECT_ROOT}/root ${STAGING_DIR}/ + PACKAGE_ROOT=${STAGING_DIR}/${OUTPUT_NAME} + IMAGES_DIR=${PACKAGE_ROOT}/images + mkdir -p ${IMAGES_DIR} + cp ${PROJECT_ROOT}/install.sh ${PACKAGE_ROOT}/ + cp -a ${PROJECT_ROOT}/root ${PACKAGE_ROOT}/ # add images - IMAGES_DIR=${STAGING_DIR}/images - mkdir -p ${IMAGES_DIR} i=0 # read image list from file (e.g. 'images-aarch64') # images are listed as SAVED_TAG=SOURCE_IMAGE @@ -97,7 +97,7 @@ for platform in "linux/amd64" "linux/arm64"; do rm -rf $OUTPUT_PATH pushd $STAGING_DIR > /dev/null - tar -cjf $OUTPUT_PATH * + tar -cjf $OUTPUT_PATH ${OUTPUT_NAME} popd > /dev/null # cleanup staging files From 04cbf6b1af51142940e994918807bb2b99d7d62d Mon Sep 17 00:00:00 2001 From: Alec Turner Date: Fri, 8 Mar 2024 11:42:17 -0800 Subject: [PATCH 06/11] Reimplement scripts to support multiple app instances An additional config file `instances.conf` is added to define instance names and port numbers. The existing `app.conf` was also modified to include an `instances` field and to move node id and location under this new object. A `.env` file is used to manage configuration for each instance. Additional scripts are added: `start`, `stop`, `monitor` - see docs for description. The main entry script is also modified such that it will run until any service stops, then brings down the remaining services and exits. --- README.md | 24 +++++++++-- .../streamline-emr/docker-compose.yml | 8 ++-- .../streamline/streamline-emr/entry | 27 ++++++------ .../streamline/streamline-emr/monitor | 19 +++++++++ .../streamline/streamline-emr/start | 41 +++++++++++++++++++ .../clientapps/streamline/streamline-emr/stop | 11 +++++ .../streamline-emr/template.app.conf | 38 ++++++++--------- .../streamline/streamline-emr/template.env | 5 +++ .../streamline-emr/template.instances.conf | 2 + template.env | 4 -- 10 files changed, 136 insertions(+), 43 deletions(-) create mode 100755 root/var/signalytic/clientapps/streamline/streamline-emr/monitor create mode 100755 root/var/signalytic/clientapps/streamline/streamline-emr/start create mode 100755 root/var/signalytic/clientapps/streamline/streamline-emr/stop create mode 100644 root/var/signalytic/clientapps/streamline/streamline-emr/template.env create mode 100644 root/var/signalytic/clientapps/streamline/streamline-emr/template.instances.conf delete mode 100644 template.env diff --git a/README.md b/README.md index 07a7fd50..8917c08e 100644 --- a/README.md +++ b/README.md @@ -32,14 +32,30 @@ In a docker environment, the application must be started manually. This is done ``` /var/signalytic/clientapps/streamline/streamline-emr/entry ``` +Note that the entry script will block until the first service stops or until interrupted. If multiple instances are run from the same machine, additional configuration may be required to differentiate the instances. This is generally the case when using the "sibling container" method for running docker from within a docker container. See the `Configuration` section for more details. ## 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_PORT`: port mapping for the web app server (default: `3000`) -`CONTAINER_NAME`: name of the application container (default: `streamline-emr`) -`DATA_DIR`: directory to be mounted for peristent data (default: `/var/signalytic/clientapps/streamline/streamline-emr/data`) +`APP_PORT`: port mapping for the web app server +`CONTAINER_NAME`: name of the application container +`DATA_DIR`: directory to be mounted for peristent data `COMPOSE_PROJECT_NAME`: assign the project name associate with the compose file - this avoids conflicts when the "same" compose file is used to manage multiple instances (e.g. when using docker sibling containers) +`IMAGE`: optional, overrides the default `streamline-emr:2.0` image -Important note when using "sibling containers": the sibling container method uses the host docker socket to provide containers with access to docker. As a result, port mappings and volumne mount points all refer to the host system rather than the container from which the docker command originates. \ No newline at end of file +Each instance of the app uses its own `.env` file to specify its configuration. This is automated through the `start` script using information stored in a file `instances.conf`. This file defines two lists: +`INSTANCES`: a list of unique instance names +`APP_PORTS`: a corresponding list of port numbers to map to the local host + +Important note when using "sibling containers": the sibling container method uses the host docker socket to provide containers with access to docker. As a result, port mappings and volumne mount points all refer to the host system rather than the container from which the docker command originates. + +### App Configuration +An `app.conf` file is required for integration with other Signalytic services. A template is provided which demonstrates integration with the `dbsync` service. + +## Scripts +Several scripts are used to manage app instances, including: +`entry`: main entry script used to start all configured instances - does not return until a service stops or the process is interrupted. +`start`: loads configuration details from `instances.conf`, then configures and starts each application instance in a dedicated subfolder +`stop`: locates and stops all instances, even if no longer defined in `instances.conf` +`monitor`: checks the status of each instance service and sends data to `bgsystemlog` if possible (loc: `streamline_emr`) \ No newline at end of file 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 1ad963a5..d6153312 100644 --- a/root/var/signalytic/clientapps/streamline/streamline-emr/docker-compose.yml +++ b/root/var/signalytic/clientapps/streamline/streamline-emr/docker-compose.yml @@ -1,9 +1,9 @@ version: '3.9' services: streamline-emr: - image: streamline-emr:2.0 - container_name: ${CONTAINER_NAME:-streamline-emr} + image: ${IMAGE:-streamline-emr:2.0} + container_name: ${CONTAINER_NAME} volumes: - - "${DATA_DIR:-/var/signalytic/clientapps/streamline/streamline-emr/data}:/var/lib/mysql" + - "${DATA_DIR}:/var/lib/mysql" ports: - - "${APP_PORT:-3000}:80" \ No newline at end of file + - "${APP_PORT}:80" \ 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 0eeb9dac..86f2f95e 100755 --- a/root/var/signalytic/clientapps/streamline/streamline-emr/entry +++ b/root/var/signalytic/clientapps/streamline/streamline-emr/entry @@ -1,17 +1,20 @@ #!/bin/bash -APPROOT="$(dirname "${BASH_SOURCE[0]}")" +LOCATION="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" -echo "entering app root: $APPROOT" -cd $APPROOT +# start all instances +${LOCATION}/start -echo "creating data folder (if necessary)" -mkdir -p data +# wait for any service to stop +pids=() +for f in $(find ${LOCATION} -mindepth 2 -maxdepth 3 -name docker-compose.yml); do + pushd $(dirname $f) > /dev/null + docker compose wait streamline-emr & + pids+=($!) + popd > /dev/null +done +echo "waiting on processes: ${pids[@]}" +wait -n ${pids[@]} > /dev/null -echo "starting app" -docker compose up - -echo "cleaning up" -docker compose down - -echo "done." +# cleanup +${LOCATION}/stop diff --git a/root/var/signalytic/clientapps/streamline/streamline-emr/monitor b/root/var/signalytic/clientapps/streamline/streamline-emr/monitor new file mode 100755 index 00000000..e9a6f6cd --- /dev/null +++ b/root/var/signalytic/clientapps/streamline/streamline-emr/monitor @@ -0,0 +1,19 @@ +#!/bin/bash + +LOCATION="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" + +for f in $(find ${LOCATION} -mindepth 2 -maxdepth 3 -name docker-compose.yml); do + pushd $(dirname $f) > /dev/null + status=$(docker compose ps --format '{"name":"{{.Names}}","created":"{{.CreatedAt}}","elapsed":"{{.RunningFor}}","state":"{{.State}}","status":"{{.Status}}"}') + popd > /dev/null + if [ "${status}" ]; then + echo $status + if command -v bgsystemlog &> /dev/null + then + bgsystemlog -j streamline_emr -m "'${status}'" + fi + else + echo "no services found" + fi +done +echo "done." \ No newline at end of file diff --git a/root/var/signalytic/clientapps/streamline/streamline-emr/start b/root/var/signalytic/clientapps/streamline/streamline-emr/start new file mode 100755 index 00000000..3f147d0e --- /dev/null +++ b/root/var/signalytic/clientapps/streamline/streamline-emr/start @@ -0,0 +1,41 @@ +#!/bin/bash + +LOCATION="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" + +CONF_FILE=${LOCATION}/instances.conf +INSTANCES_DIR=${LOCATION}/instances +COMPOSE_FILE=${LOCATION}/docker-compose.yml +ENV_TEMPLATE=${LOCATION}/template.env + +echo "starting all instances" + +if [ ! -f "${CONF_FILE}" ]; then + echo "missing conf file: ${CONF_FILE}" + exit 1 +fi + +echo "processing config file: ${CONF_FILE}" + +# load instance names and port numbers from conf file +instances=($(sed -n "s/INSTANCES=//p" ${CONF_FILE})) +ports=($(sed -n "s/APP_PORTS=//p" ${CONF_FILE})) +for ((i=0;i<${#instances[@]};i++)); do + + # prepare directory and config files for instance + instance=$(echo ${instances[$i]} | tr -d '"') + port=$(echo ${ports[$i]} | tr -d '"') + echo + echo "configuring instance $((i+1)) / ${#instances[@]}" + echo " name: ${instance}" + echo " port: ${port}" + mkdir -p ${INSTANCES_DIR}/${instance}/data + sed -e "s/{{INSTANCE_NAME}}/${instance}/g" -e "s/{{INSTANCE_PORT}}/${port}/g" ${ENV_TEMPLATE} > ${INSTANCES_DIR}/${instance}/.env + cp ${COMPOSE_FILE} ${INSTANCES_DIR}/${instance}/ + + # start app + pushd ${INSTANCES_DIR}/${instance} > /dev/null + docker compose up -d --force-recreate + popd > /dev/null +done + +echo "done." \ No newline at end of file diff --git a/root/var/signalytic/clientapps/streamline/streamline-emr/stop b/root/var/signalytic/clientapps/streamline/streamline-emr/stop new file mode 100755 index 00000000..a4540aa6 --- /dev/null +++ b/root/var/signalytic/clientapps/streamline/streamline-emr/stop @@ -0,0 +1,11 @@ +#!/bin/bash + +LOCATION="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" + +echo "stopping all instances" +for f in $(find ${LOCATION} -mindepth 2 -maxdepth 3 -name docker-compose.yml); do + pushd $(dirname $f) > /dev/null + docker compose down + popd > /dev/null +done +echo "done." \ No newline at end of file diff --git a/root/var/signalytic/clientapps/streamline/streamline-emr/template.app.conf b/root/var/signalytic/clientapps/streamline/streamline-emr/template.app.conf index 5be3965c..a99d451c 100644 --- a/root/var/signalytic/clientapps/streamline/streamline-emr/template.app.conf +++ b/root/var/signalytic/clientapps/streamline/streamline-emr/template.app.conf @@ -1,22 +1,22 @@ { "name": "Streamline EMR", - "database": { - "type": "mysql", - "version": "mariadb:15.1", - "name": "streamline", - "source": "streamline-emr", - "username": "", - "password": "", - "db_path": "/var/lib/mysql", - "logs_path": "/var/lib/mysql/logs", - "log_pattern": "bin.[0-9]*" - }, - "blockgraph": { - "district": "", - "name": "", - "node": "", - "location": "", - "username": "", - "password": "" + "dbsync": { + "database": { + "type": "mysql", + "version": "8.0.23", + "name": "main", + "username": "", + "password": "", + "db_path": "/var/lib/mysql", + "logs_path": "/var/lib/mysql/logs", + "log_pattern": "binlog.[0-9]*" + }, + "blockgraph": { + "district": "", + "name": "", + "username": "", + "password": "" + }, + "instances": {} } -} +} \ No newline at end of file diff --git a/root/var/signalytic/clientapps/streamline/streamline-emr/template.env b/root/var/signalytic/clientapps/streamline/streamline-emr/template.env new file mode 100644 index 00000000..cb2ad4be --- /dev/null +++ b/root/var/signalytic/clientapps/streamline/streamline-emr/template.env @@ -0,0 +1,5 @@ +COMPOSE_PROJECT_NAME={{INSTANCE_NAME}} +CONTAINER_NAME=streamline-emr-{{INSTANCE_NAME}} +DATA_DIR=/var/signalytic/clientapps/streamline/streamline-emr/instances/{{INSTANCE_NAME}}/data +APP_PORT={{INSTANCE_PORT}} +#IMAGE=streamline-emr:2.0 \ No newline at end of file diff --git a/root/var/signalytic/clientapps/streamline/streamline-emr/template.instances.conf b/root/var/signalytic/clientapps/streamline/streamline-emr/template.instances.conf new file mode 100644 index 00000000..1451e354 --- /dev/null +++ b/root/var/signalytic/clientapps/streamline/streamline-emr/template.instances.conf @@ -0,0 +1,2 @@ +INSTANCES= +APP_PORTS= \ No newline at end of file diff --git a/template.env b/template.env deleted file mode 100644 index 23e8a83b..00000000 --- a/template.env +++ /dev/null @@ -1,4 +0,0 @@ -APP_PORT=3000 -CONTAINER_NAME=streamline-emr-1 -COMPOSE_PROJECT_NAME=streamline-emr-1 -DATA_DIR=/path/to/volume/mount/dir \ No newline at end of file From a2a9395e3970cc852b58658bc677efe58c8dd926 Mon Sep 17 00:00:00 2001 From: Alec Turner Date: Fri, 8 Mar 2024 12:02:53 -0800 Subject: [PATCH 07/11] Make image packaging and installation optional Eventually, images should not be transferred as part of the application package, using a more efficient mechanism instead. Other cases may already exist where packaging without the image is preferrable. When the `PACKAGE_IMAGES` variable is not set to 1 (default: 1), images will not be included in the package. The installation script now handles the case where the `images` folder is missing altogether. --- install.sh | 2 +- package.sh | 47 +++++++++++++++++++++++++++++------------------ 2 files changed, 30 insertions(+), 19 deletions(-) diff --git a/install.sh b/install.sh index 7d74ccd2..a6fddf34 100755 --- a/install.sh +++ b/install.sh @@ -37,7 +37,7 @@ echo "importing root files" cp -rfv $LOCATION/root/* / # import docker images -for f in $(find $LOCATION/images -name "*.img");do +for f in $(find $LOCATION/images -name "*.img" 2>/dev/null);do echo "importing docker image: $f" docker load -i $f done diff --git a/package.sh b/package.sh index 8b4b2b1c..fce0c844 100755 --- a/package.sh +++ b/package.sh @@ -11,8 +11,15 @@ # basic path info LOCATION="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" PROJECT_ROOT="$(realpath $LOCATION)" -PACKAGE_NAME="streamline-emr" -OUTPUT_DIR="$PROJECT_ROOT/build-packages" + +# configurable options (override with env vars as needed) +PACKAGE_NAME=${PACKAGE_NAME-"streamline-emr"} +OUTPUT_DIR=${OUTPUT_DIR-"$PROJECT_ROOT/build-packages"} +PACKAGE_IMAGES=${PACKAGE_IMAGES:-1} + +echo "packaging $PACKAGE_NAME" +echo " output dir: $OUTPUT_DIR" +echo " package images: $PACKAGE_IMAGES" # work from the project root pushd $PROJECT_ROOT > /dev/null @@ -75,22 +82,26 @@ for platform in "linux/amd64" "linux/arm64"; do cp ${PROJECT_ROOT}/install.sh ${PACKAGE_ROOT}/ cp -a ${PROJECT_ROOT}/root ${PACKAGE_ROOT}/ - # add images - i=0 - # read image list from file (e.g. 'images-aarch64') - # images are listed as SAVED_TAG=SOURCE_IMAGE - for image in $(cat ${PROJECT_ROOT}/images-${pkg_arch});do - i=$((i+1)) - name="image${i}.img" - path="${IMAGES_DIR}/${name}" - IFS=\= read -r dest source <<< "${image}" - echo "pulling image '${source}' (${platform})" - docker pull --platform ${platform} ${source} - echo "tagging image as '${dest}'" - docker tag ${source} ${dest} - echo "saving to '${path}'" - docker save -o ${path} $dest - done + if [ "${PACKAGE_IMAGES}" = "1" ]; then + # add images + i=0 + # read image list from file (e.g. 'images-aarch64') + # images are listed as SAVED_TAG=SOURCE_IMAGE + for image in $(cat ${PROJECT_ROOT}/images-${pkg_arch});do + i=$((i+1)) + name="image${i}.img" + path="${IMAGES_DIR}/${name}" + IFS=\= read -r dest source <<< "${image}" + echo "pulling image '${source}' (${platform})" + docker pull --platform ${platform} ${source} + echo "tagging image as '${dest}'" + docker tag ${source} ${dest} + echo "saving to '${path}'" + docker save -o ${path} $dest + done + else + echo "skipping image packaging as requested" + fi # setup output directory and cleanup old files if necessary mkdir -p $OUTPUT_DIR From 0ef5029931de82e9ac216cf121b2d9f33546b31d Mon Sep 17 00:00:00 2001 From: Alec Turner Date: Fri, 8 Mar 2024 12:39:18 -0800 Subject: [PATCH 08/11] add version file to package and print version on start --- package.sh | 1 + .../signalytic/clientapps/streamline/streamline-emr/start | 7 ++++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/package.sh b/package.sh index fce0c844..b89d8024 100755 --- a/package.sh +++ b/package.sh @@ -81,6 +81,7 @@ for platform in "linux/amd64" "linux/arm64"; do mkdir -p ${IMAGES_DIR} cp ${PROJECT_ROOT}/install.sh ${PACKAGE_ROOT}/ cp -a ${PROJECT_ROOT}/root ${PACKAGE_ROOT}/ + echo "${VERSION_NAME}" > ${PACKAGE_ROOT}/root/var/signalytic/clientapps/streamline/streamline-emr/version if [ "${PACKAGE_IMAGES}" = "1" ]; then # add images diff --git a/root/var/signalytic/clientapps/streamline/streamline-emr/start b/root/var/signalytic/clientapps/streamline/streamline-emr/start index 3f147d0e..2234c699 100755 --- a/root/var/signalytic/clientapps/streamline/streamline-emr/start +++ b/root/var/signalytic/clientapps/streamline/streamline-emr/start @@ -6,8 +6,13 @@ CONF_FILE=${LOCATION}/instances.conf INSTANCES_DIR=${LOCATION}/instances COMPOSE_FILE=${LOCATION}/docker-compose.yml ENV_TEMPLATE=${LOCATION}/template.env +VERSION_FILE=${LOCATION}/version -echo "starting all instances" +version=$(head -n 1 ${VERSION_FILE} 2>/dev/null) +if [ $? -ne 0 ];then + version="unknown version" +fi +echo "Starting Streamline EMR: $version" if [ ! -f "${CONF_FILE}" ]; then echo "missing conf file: ${CONF_FILE}" From 41a04e5b2d1d9324a1c26a3c5a6c44240fb1da7d Mon Sep 17 00:00:00 2001 From: Alec Turner Date: Fri, 8 Mar 2024 12:53:35 -0800 Subject: [PATCH 09/11] ensure stop is always called at the end of entry script interrupts were not properly handled by the entry script, and could leave containers active. This is fixed by running stop in a cleanup function, called on exit. --- .../clientapps/streamline/streamline-emr/entry | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/root/var/signalytic/clientapps/streamline/streamline-emr/entry b/root/var/signalytic/clientapps/streamline/streamline-emr/entry index 86f2f95e..66237eb5 100755 --- a/root/var/signalytic/clientapps/streamline/streamline-emr/entry +++ b/root/var/signalytic/clientapps/streamline/streamline-emr/entry @@ -2,6 +2,13 @@ LOCATION="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" +function cleanup { + ${LOCATION}/stop + echo "done." +} + +trap cleanup EXIT + # start all instances ${LOCATION}/start @@ -15,6 +22,3 @@ for f in $(find ${LOCATION} -mindepth 2 -maxdepth 3 -name docker-compose.yml); d done echo "waiting on processes: ${pids[@]}" wait -n ${pids[@]} > /dev/null - -# cleanup -${LOCATION}/stop From 5072872bdb005e57a714f489be306fce9e04dfae Mon Sep 17 00:00:00 2001 From: Alec Turner Date: Fri, 8 Mar 2024 15:32:19 -0800 Subject: [PATCH 10/11] update readme file to clarify installation, configuration process --- README.md | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 8917c08e..213954a3 100644 --- a/README.md +++ b/README.md @@ -7,9 +7,20 @@ Packaging and installation tools for Streamline's "Streamline EMR" application. 2. run `package.sh` to generate a new application package 3. package will be stored to `build-packages/` +### Alternative Builds +Some variables can be overridden to support alternative builds. For example, an option exists to package the application WITHOUT docker images. This can be done by setting the appropriate environment variables (e.g. `VAR=VALUE ./package.sh`). + +Options that can be overridden are: +- `PACKAGE_NAME`: base name of the output package. (default: `streamline-emr`) +- `OUTPUT_DIR`: directory where packages will be stored. (default: `$PROJECT_ROOT/build-packages`) +- `PACKAGE_IMAGES`: if set to a value other than 1, do NOT package images. (default: `1`) + ## Installing 1. extract the generated archive file in a temporary folder on the target system -2. run `install.sh` +2. run `/install.sh` +3. add a `instance.conf` file at the root of the install directory (see notes below) +4. (optional) restart the systemd service if running on a system with systemd installed: `systemctl restart streamline-emr` +5. (optional) configure an `app.conf` file for integration with Signalytic services (e.g. dbsync) ## Running ### Production (systemd) @@ -27,6 +38,9 @@ systemctl stop streamline-emr systemctl restart streamline-emr ``` +## Monitoring +The script `monitor` can be used at any time to query the current status of all instances. If the `bgsystemlog` program is found, status data will be written to the Signalytic system log under the `streamline_emr` location (json format). + ### Docker In a docker environment, the application must be started manually. This is done by running the `entry` script, for example: ``` @@ -50,6 +64,13 @@ Each instance of the app uses its own `.env` file to specify its configuration. Important note when using "sibling containers": the sibling container method uses the host docker socket to provide containers with access to docker. As a result, port mappings and volumne mount points all refer to the host system rather than the container from which the docker command originates. +### Example Configuration Files +The following snippet shows an `instances.conf` file with 3 instances defined. Instance `test0001-_default` will use port `3001`, `test0002-_default` will use `3002`, etc. +``` +INSTANCES="test0001-_default" "test0002-_default" "test0003-_default" +APP_PORTS=3001 3002 3003 +``` + ### App Configuration An `app.conf` file is required for integration with other Signalytic services. A template is provided which demonstrates integration with the `dbsync` service. From 6a4ab995064627253306ea1563637d0c7f757729 Mon Sep 17 00:00:00 2001 From: Alec Turner Date: Fri, 8 Mar 2024 15:38:53 -0800 Subject: [PATCH 11/11] fix minor typos in readme --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 213954a3..621d1f08 100644 --- a/README.md +++ b/README.md @@ -54,7 +54,7 @@ If multiple instances are run from the same machine, additional configuration ma 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_PORT`: port mapping for the web app server `CONTAINER_NAME`: name of the application container -`DATA_DIR`: directory to be mounted for peristent data +`DATA_DIR`: directory to be mounted for peristant data `COMPOSE_PROJECT_NAME`: assign the project name associate with the compose file - this avoids conflicts when the "same" compose file is used to manage multiple instances (e.g. when using docker sibling containers) `IMAGE`: optional, overrides the default `streamline-emr:2.0` image @@ -62,7 +62,7 @@ Each instance of the app uses its own `.env` file to specify its configuration. `INSTANCES`: a list of unique instance names `APP_PORTS`: a corresponding list of port numbers to map to the local host -Important note when using "sibling containers": the sibling container method uses the host docker socket to provide containers with access to docker. As a result, port mappings and volumne mount points all refer to the host system rather than the container from which the docker command originates. +Important note when using "sibling containers": the sibling container method uses the host docker socket to provide containers with access to docker. As a result, port mappings and volume mount points all refer to the host system rather than the container from which the docker command originates. ### Example Configuration Files The following snippet shows an `instances.conf` file with 3 instances defined. Instance `test0001-_default` will use port `3001`, `test0002-_default` will use `3002`, etc.