Skip to content

Commit 2612100

Browse files
bendhouseartTim BudrasAnthony Galassiaebuti1021
authored
Updating bendhouseart/ezbids:master from buti1021/ezbids:add-nginx-forwarding (#1)
* updating docker compose to use nginx for forwarding * added nginx config and updated docker file works on mac * added folder for certs * had to bodge npm installs, husky, and vite to get healthy containers on osx * updated docker compose, health checks all pass. CORS still an issue * add nginx config * ssl works with the addition of a cert, key, and the password for it * create standalone production config * consolidating variables and options into 1 launch script and 1 .env file * updated lint check to use prettier instead of npm 'style-check' and 'lint-check' * update package-lock.json * bringing more in line with buti1021's PR, while 'stream-lining' env and entrypoints * update docker ignore and build * Update example.env * certs and keys path as environment * enable telemetry via build in compose_profile env var * revert vite config changes * remove old files --------- Co-authored-by: Tim Budras <[email protected]> Co-authored-by: Anthony Galassiae <[email protected]> Co-authored-by: buti1021 <[email protected]>
1 parent e57c93d commit 2612100

16 files changed

+2586
-1996
lines changed

.dockerignore

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
ui
2-
handler
31
workdir
42
test
53
bids-specification

.gitignore

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ node_modules
44
# local env files
55
.env.local
66
.env.*.local
7+
.env
78

89
# Log files
910
npm-debug.log*
@@ -33,4 +34,8 @@ api/*.pub
3334
api/*.key
3435
api/ezbids.key
3536
api/*.js
36-
api/*.js.map
37+
api/*.js.map
38+
39+
# ssl certs we ignore the content of the folder but keep the folder around.
40+
nginx/ssl/*
41+
!nginx/ssl/.gitkeep

.lintstagedrc.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
{
2-
"**/*.{js,json,ts,vue}": ["npm run style-check", "npm run lint-check"]
2+
"**/*.{js,json,ts,vue}": ["prettier --write"]
33
}

Dockerfile

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ COPY . /app
44

55
WORKDIR /app
66

7-
RUN npm install -g [email protected]
7+
RUN npm install -g [email protected] pm2 typescript tsc-watch
88

9-
RUN npm install -g pm2 typescript tsc-watch
9+
# build the api and the ui
10+
RUN cd /app/api && npm install
11+
RUN cd /app/ui && npm install

dev.sh

Lines changed: 0 additions & 37 deletions
This file was deleted.

docker-compose-production.yml

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
version: "3"
2+
networks:
3+
ezbids:
4+
5+
services:
6+
mongodb:
7+
container_name: brainlife_ezbids-mongodb
8+
image: mongo:4.4.15
9+
platform: linux/amd64
10+
volumes:
11+
- /data/db
12+
healthcheck:
13+
test: echo 'db.runCommand("ping").ok' | mongo localhost:27017/test --quiet
14+
interval: 10s
15+
timeout: 10s
16+
retries:
17+
5
18+
networks:
19+
- ezbids
20+
21+
api:
22+
container_name: brainlife_ezbids-api
23+
build: .
24+
platform: linux/amd64
25+
volumes:
26+
- ./api:/app/api
27+
- /tmp:/tmp
28+
depends_on:
29+
mongodb:
30+
condition: service_healthy
31+
healthcheck:
32+
test: ["CMD", "curl", "-f", "http://localhost:8082/health"]
33+
working_dir: /app/api
34+
command:
35+
./dev.sh
36+
environment:
37+
MONGO_CONNECTION_STRING: mongodb://mongodb:27017/ezbids
38+
BRAINLIFE_AUTHENTICATION: ${BRAINLIFE_AUTHENTICATION}
39+
networks:
40+
- ezbids
41+
42+
handler:
43+
container_name: brainlife_ezbids-handler
44+
build: ./handler
45+
platform: linux/amd64
46+
volumes:
47+
- .:/app
48+
- /tmp:/tmp
49+
depends_on:
50+
mongodb:
51+
condition: service_healthy
52+
api:
53+
condition: service_healthy
54+
environment:
55+
MONGO_CONNECTION_STRING: mongodb://mongodb:27017/ezbids
56+
networks:
57+
- ezbids
58+
tty: true #turn on color for bids-validator output
59+
command: pm2 start handler.js --attach
60+
61+
ui:
62+
container_name: brainlife_ezbids-ui-builder
63+
env_file:
64+
- .env
65+
build: ./ui
66+
platform: linux/amd64
67+
volumes:
68+
- ./ui/dist:/ui/dist
69+
environment:
70+
VITE_APIHOST: https://${SERVER_NAME}/api
71+
VITE_BRAINLIFE_AUTHENTICATION: ${BRAINLIFE_AUTHENTICATION}
72+
73+
# by default this is not enabled, add COMPOSE_PROFILES=telemetry to your .env
74+
telemetry:
75+
container_name: brainlife_ezbids-telemetry
76+
build: ./telemetry
77+
platform: linux/amd64
78+
depends_on:
79+
- mongodb
80+
profiles: ["telemetry"]
81+
networks:
82+
- ezbids
83+
84+
nginx:
85+
env_file:
86+
- .env
87+
container_name: brainlife_ezbids-nginx
88+
depends_on:
89+
- ui
90+
- api
91+
image: nginx:latest
92+
platform: linux/amd64
93+
ports:
94+
- 443:443
95+
networks:
96+
- ezbids
97+
volumes:
98+
- ${SSL_CERT_PATH}:/etc/nginx/conf.d/ssl/sslcert.cert
99+
- ${SSL_KEY_PATH}:/etc/nginx/conf.d/ssl/sslcert.key
100+
- ${SSL_PASSWORD_PATH}:/etc/nginx/conf.d/ssl/sslpassword
101+
- ./nginx/production_nginx.conf:/etc/nginx/conf.d/default.conf
102+
- ./ui/dist:/usr/share/nginx/html/ezbids:ro

docker-compose.yml

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
# version: "3"
1+
version: "3"
2+
networks:
3+
ezbids:
24

35
services:
46
mongodb:
@@ -15,6 +17,8 @@ services:
1517
5
1618
ports:
1719
- 27417:27017 #for local debugging
20+
networks:
21+
- ezbids
1822

1923
api:
2024
container_name: brainlife_ezbids-api
@@ -36,6 +40,8 @@ services:
3640
BRAINLIFE_AUTHENTICATION: ${BRAINLIFE_AUTHENTICATION}
3741
ports:
3842
- 8082:8082 #localhost runs on local browser to it needs to access api via host port
43+
networks:
44+
- ezbids
3945

4046
handler:
4147
container_name: brainlife_ezbids-handler
@@ -51,11 +57,15 @@ services:
5157
condition: service_healthy
5258
environment:
5359
MONGO_CONNECTION_STRING: mongodb://mongodb:27017/ezbids
60+
networks:
61+
- ezbids
5462
tty: true #turn on color for bids-validator output
5563
command: pm2 start handler.js --attach --watch --ignore-watch "ui **/node_modules"
5664

5765
ui:
5866
container_name: brainlife_ezbids-ui
67+
env_file:
68+
- .env
5969
build: ./ui
6070
platform: linux/amd64
6171
volumes:
@@ -67,14 +77,20 @@ services:
6777
test: ["CMD", "curl", "-f", "http://localhost:3000"]
6878
ports:
6979
- 3000:3000 #vite wants to be exposed on the host for HMR?
70-
80+
networks:
81+
- ezbids
82+
7183
# by default this is not enabled, need to run docker compose with --profile development to enable this service
7284
telemetry:
7385
container_name: brainlife_ezbids-telemetry
7486
build: ./telemetry
7587
platform: linux/amd64
7688
depends_on:
7789
- mongodb
78-
profiles: ["development"]
90+
profiles: ["telemetry"]
7991
ports:
80-
- 8000:8000 #for local debugging
92+
- 8000:8000 #for local debugging
93+
networks:
94+
- ezbids
95+
96+

example.env

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Create/Copy this file as .env in the root of the project to set default environment variables
2+
3+
# insert your host name here, it should match your ssl certificate and/or the output
4+
# of echo $HOSTNAME
5+
SERVER_NAME=localhost
6+
7+
# Set the BRAINLIFE_PRODUCTION environment variable to true to use https"
8+
# (this will launch the services on port 443) and run with nginx/production_nginx.conf"
9+
# this will require providing the correct paths for the SSL_CERT_PATH, SSL_KEY_PATH and SSL_PASSWORD_PATH
10+
# with false the UI will run on 3000"
11+
BRAINLIFE_PRODUCTION=false
12+
13+
SSL_CERT_PATH=./nginx/ssl/sslcert.cert
14+
SSL_KEY_PATH=./nginx/ssl/sslcert.key
15+
SSL_PASSWORD_PATH=./nginx/ssl/sslpassword #if your key is not encrypted use an arbitrary path here
16+
17+
# Set the BRAINLIFE_AUTHENTICATION environment variable to true, if you're not running"
18+
# this with brainlife don't use."
19+
BRAINLIFE_AUTHENTICATION=false
20+
21+
# Set the BRAINLIFE_DEVELOPMENT enables additional debugging output and mounts
22+
# the ezbids repo/folder into the various containers default is false"
23+
BRAINLIFE_DEVELOPMENT=false
24+
25+
# Define which profiles to use, e.g. set to COMPOSE_PROFILES=telemetry to enable telemetry
26+
COMPOSE_PROFILES=

handler/Dockerfile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
FROM neurodebian:nd20.04-non-free
22

3+
COPY . /app
4+
35
SHELL ["/bin/bash", "-c"]
46

57
ENV DEBIAN_FRONTEND noninteractive
68

79
RUN apt update && \
810
apt-get update && apt-get upgrade -y
911

10-
RUN apt install -y parallel python3 python3-pip tree curl unzip git jq python libgl-dev python-numpy bc
12+
RUN apt update && apt install -y parallel python3 python3-pip tree curl unzip git jq python libgl-dev python-numpy bc
1113

1214
RUN pip3 install numpy==1.23.0 nibabel==4.0.0 pandas matplotlib pyyaml==5.4.1 pydicom==2.3.1 natsort pydeface && \
1315
pip3 install quickshear mne mne-bids

launch.sh

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
#!/usr/bin/env bash
2+
3+
# check to see if a .env file exists
4+
if [ -f .env ]; then
5+
echo ".env file exists, loading environment variables from .env file"
6+
else
7+
echo ".env file does not exist, copying example.env to .env"
8+
cp example.env .env
9+
fi
10+
11+
# load the environment variables from the .env file
12+
source .env
13+
14+
echo "Setting Environment Variables from .env file:"
15+
# display the environment variables read in from .env, could be a gotcha if
16+
# the user is unclear about if the .env variables are being used. The .env variables
17+
# will override environment variables set in the shell as they're set once this script
18+
# is run.
19+
while read line
20+
do
21+
# if line does not start with # then echo the line
22+
if [[ $line != \#* ]]; then
23+
if [[ $line != "" ]]; then
24+
echo " ${line}"
25+
fi
26+
fi
27+
done < .env
28+
29+
if [ $BRAINLIFE_DEVELOPMENT == true ]; then
30+
# enable or disable debugging output
31+
set -ex
32+
else
33+
set -e
34+
fi
35+
36+
# build local changes and mount them directly into the containers
37+
# api/ and ui/ are mounted as volumes at /app within the docker-compose.yml
38+
(cd api && npm install)
39+
(cd ui && npm install)
40+
41+
# update the bids submodule
42+
git submodule update --init --recursive
43+
44+
# The main differences between the production and development docker-compose files are that the production
45+
# files uses https via nginx and the development file uses http.
46+
if [[ $BRAINLIFE_PRODUCTION == true ]]; then
47+
DOCKER_COMPOSE_FILE=docker-compose-production.yml
48+
else
49+
DOCKER_COMPOSE_FILE=docker-compose.yml
50+
fi
51+
52+
mkdir -p /tmp/upload
53+
mkdir -p /tmp/workdir
54+
55+
#npm run prepare-husky
56+
57+
./generate_keys.sh
58+
59+
# ok docker compose is now included in docker as an option for docker
60+
if [[ $(command -v docker-compose) ]]; then
61+
# if the older version is installed use the dash
62+
docker-compose --file ${DOCKER_COMPOSE_FILE} up
63+
else
64+
# if the newer version is installed don't use the dash
65+
docker compose --file ${DOCKER_COMPOSE_FILE} up
66+
fi

0 commit comments

Comments
 (0)