Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Standalone Production config #134

Open
wants to merge 30 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
cc76413
updating docker compose to use nginx for forwarding
bendhouseart Sep 11, 2024
1f26bd8
added nginx config and updated docker file works on mac
bendhouseart Sep 11, 2024
0573c33
added folder for certs
bendhouseart Sep 11, 2024
516a8d8
had to bodge npm installs, husky, and vite to get healthy containers …
bendhouseart Sep 17, 2024
7b941a6
Merge branch 'add-nginx-forwarding' of github.com:bendhouseart/ezbids…
bendhouseart Sep 17, 2024
b685a18
updated docker compose, health checks all pass. CORS still an issue
bendhouseart Sep 17, 2024
2fa88f2
add nginx config
bendhouseart Sep 17, 2024
13989f7
incremental progress is progress
bendhouseart Sep 17, 2024
35770d6
redirects all work when running locally
bendhouseart Sep 18, 2024
1056b85
Merge branch 'add-nginx-forwarding' of github.com:bendhouseart/ezbids…
bendhouseart Sep 24, 2024
8b1b26c
ssl works with the addition of a cert, key, and the password for it
bendhouseart Sep 24, 2024
d4e70aa
create standalone production config
Sep 30, 2024
8f60d88
consolidating variables and options into 1 launch script and 1 .env file
bendhouseart Sep 30, 2024
abbfd08
updated lint check to use prettier instead of npm 'style-check' and '…
bendhouseart Sep 30, 2024
660cff6
update package-lock.json
bendhouseart Oct 1, 2024
39ca320
bringing more in line with buti1021's PR, while 'stream-lining' env a…
bendhouseart Oct 2, 2024
17a0d24
update docker ignore and build
bendhouseart Oct 8, 2024
5885939
works well enough in production, 'dev' could still use some tweaks
Oct 9, 2024
85ccc7d
what changes?
bendhouseart Oct 9, 2024
20c3b6f
Apply suggestions from code review
bendhouseart Oct 10, 2024
9186819
got local running again by ditching nginx
bendhouseart Oct 16, 2024
8b7d6bf
remove nginx_var
buti1021 Oct 22, 2024
4f77d58
Update example.env
buti1021 Oct 22, 2024
9c4b1e1
remove last dev nginx bits
buti1021 Oct 22, 2024
62017d8
certs and keys path as environment
buti1021 Oct 22, 2024
96a5aa4
Merge branch 'add-nginx-forwarding' into add-nginx-forwarding
buti1021 Oct 22, 2024
42c16be
enable telemetry via build in compose_profile env var
buti1021 Oct 22, 2024
86ecee5
revert vite config changes
buti1021 Oct 22, 2024
a6020b8
Merge pull request #1 from bendhouseart/add-nginx-forwarding
buti1021 Oct 30, 2024
32f33a5
remove old files
buti1021 Oct 30, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
ui
handler
workdir
test
bids-specification
7 changes: 6 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ node_modules
# local env files
.env.local
.env.*.local
.env

# Log files
npm-debug.log*
Expand Down Expand Up @@ -33,4 +34,8 @@ api/*.pub
api/*.key
api/ezbids.key
api/*.js
api/*.js.map
api/*.js.map

# ssl certs we ignore the content of the folder but keep the folder around.
nginx/ssl/*
!nginx/ssl/.gitkeep
2 changes: 1 addition & 1 deletion .lintstagedrc.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"**/*.{js,json,ts,vue}": ["npm run style-check", "npm run lint-check"]
"**/*.{js,json,ts,vue}": ["prettier --write"]
}
6 changes: 4 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ COPY . /app

WORKDIR /app

RUN npm install -g npm@9.5.1
RUN npm install -g npm@9.5.1 pm2 typescript tsc-watch

RUN npm install -g pm2 typescript tsc-watch
# build the api and the ui
RUN cd /app/api && npm install
RUN cd /app/ui && npm install
37 changes: 0 additions & 37 deletions dev.sh

This file was deleted.

102 changes: 102 additions & 0 deletions docker-compose-production.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
version: "3"
networks:
ezbids:

services:
mongodb:
container_name: brainlife_ezbids-mongodb
image: mongo:4.4.15
platform: linux/amd64
volumes:
- /data/db
healthcheck:
test: echo 'db.runCommand("ping").ok' | mongo localhost:27017/test --quiet
interval: 10s
timeout: 10s
retries:
5
networks:
- ezbids

api:
container_name: brainlife_ezbids-api
build: .
platform: linux/amd64
volumes:
- ./api:/app/api
- /tmp:/tmp
depends_on:
mongodb:
condition: service_healthy
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:8082/health"]
working_dir: /app/api
command:
./dev.sh
environment:
MONGO_CONNECTION_STRING: mongodb://mongodb:27017/ezbids
BRAINLIFE_AUTHENTICATION: ${BRAINLIFE_AUTHENTICATION}
networks:
- ezbids

handler:
container_name: brainlife_ezbids-handler
build: ./handler
platform: linux/amd64
volumes:
- .:/app
- /tmp:/tmp
depends_on:
mongodb:
condition: service_healthy
api:
condition: service_healthy
environment:
MONGO_CONNECTION_STRING: mongodb://mongodb:27017/ezbids
networks:
- ezbids
tty: true #turn on color for bids-validator output
command: pm2 start handler.js --attach

ui:
container_name: brainlife_ezbids-ui-builder
env_file:
- .env
build: ./ui
platform: linux/amd64
volumes:
- ./ui/dist:/ui/dist
environment:
VITE_APIHOST: https://${SERVER_NAME}/api
VITE_BRAINLIFE_AUTHENTICATION: ${BRAINLIFE_AUTHENTICATION}

# by default this is not enabled, add COMPOSE_PROFILES=telemetry to your .env
telemetry:
container_name: brainlife_ezbids-telemetry
build: ./telemetry
platform: linux/amd64
depends_on:
- mongodb
profiles: ["telemetry"]
networks:
- ezbids

nginx:
env_file:
- .env
container_name: brainlife_ezbids-nginx
depends_on:
- ui
- api
image: nginx:latest
platform: linux/amd64
ports:
- 443:443
networks:
- ezbids
volumes:
- ${SSL_CERT_PATH}:/etc/nginx/conf.d/ssl/sslcert.cert
- ${SSL_KEY_PATH}:/etc/nginx/conf.d/ssl/sslcert.key
- ${SSL_PASSWORD_PATH}:/etc/nginx/conf.d/ssl/sslpassword
- ./nginx/production_nginx.conf:/etc/nginx/conf.d/default.conf
- ./ui/dist:/usr/share/nginx/html/ezbids:ro
24 changes: 20 additions & 4 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# version: "3"
version: "3"
networks:
ezbids:

services:
mongodb:
Expand All @@ -15,6 +17,8 @@ services:
5
ports:
- 27417:27017 #for local debugging
networks:
- ezbids

api:
container_name: brainlife_ezbids-api
Expand All @@ -36,6 +40,8 @@ services:
BRAINLIFE_AUTHENTICATION: ${BRAINLIFE_AUTHENTICATION}
ports:
- 8082:8082 #localhost runs on local browser to it needs to access api via host port
networks:
- ezbids

handler:
container_name: brainlife_ezbids-handler
Expand All @@ -51,11 +57,15 @@ services:
condition: service_healthy
environment:
MONGO_CONNECTION_STRING: mongodb://mongodb:27017/ezbids
networks:
- ezbids
tty: true #turn on color for bids-validator output
command: pm2 start handler.js --attach --watch --ignore-watch "ui **/node_modules"

ui:
container_name: brainlife_ezbids-ui
env_file:
- .env
build: ./ui
platform: linux/amd64
volumes:
Expand All @@ -67,14 +77,20 @@ services:
test: ["CMD", "curl", "-f", "http://localhost:3000"]
ports:
- 3000:3000 #vite wants to be exposed on the host for HMR?

networks:
- ezbids

# by default this is not enabled, need to run docker compose with --profile development to enable this service
telemetry:
container_name: brainlife_ezbids-telemetry
build: ./telemetry
platform: linux/amd64
depends_on:
- mongodb
profiles: ["development"]
profiles: ["telemetry"]
ports:
- 8000:8000 #for local debugging
- 8000:8000 #for local debugging
networks:
- ezbids


26 changes: 26 additions & 0 deletions example.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Create/Copy this file as .env in the root of the project to set default environment variables

# insert your host name here, it should match your ssl certificate and/or the output
# of echo $HOSTNAME
SERVER_NAME=localhost

# Set the BRAINLIFE_PRODUCTION environment variable to true to use https"
# (this will launch the services on port 443) and run with nginx/production_nginx.conf"
# this will require providing the correct paths for the SSL_CERT_PATH, SSL_KEY_PATH and SSL_PASSWORD_PATH
# with false the UI will run on 3000"
BRAINLIFE_PRODUCTION=false

SSL_CERT_PATH=./nginx/ssl/sslcert.cert
SSL_KEY_PATH=./nginx/ssl/sslcert.key
SSL_PASSWORD_PATH=./nginx/ssl/sslpassword #if your key is not encrypted use an arbitrary path here

# Set the BRAINLIFE_AUTHENTICATION environment variable to true, if you're not running"
# this with brainlife don't use."
BRAINLIFE_AUTHENTICATION=false

# Set the BRAINLIFE_DEVELOPMENT enables additional debugging output and mounts
# the ezbids repo/folder into the various containers default is false"
BRAINLIFE_DEVELOPMENT=false

# Define which profiles to use, e.g. set to COMPOSE_PROFILES=telemetry to enable telemetry
COMPOSE_PROFILES=
4 changes: 3 additions & 1 deletion handler/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
FROM neurodebian:nd20.04-non-free

COPY . /app

SHELL ["/bin/bash", "-c"]

ENV DEBIAN_FRONTEND noninteractive

RUN apt update && \
apt-get update && apt-get upgrade -y

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

RUN pip3 install numpy==1.23.0 nibabel==4.0.0 pandas matplotlib pyyaml==5.4.1 pydicom==2.3.1 natsort pydeface && \
pip3 install quickshear mne mne-bids
Expand Down
66 changes: 66 additions & 0 deletions launch.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
#!/usr/bin/env bash

# check to see if a .env file exists
if [ -f .env ]; then
echo ".env file exists, loading environment variables from .env file"
else
echo ".env file does not exist, copying example.env to .env"
cp example.env .env
fi

# load the environment variables from the .env file
source .env

echo "Setting Environment Variables from .env file:"
# display the environment variables read in from .env, could be a gotcha if
# the user is unclear about if the .env variables are being used. The .env variables
# will override environment variables set in the shell as they're set once this script
# is run.
while read line
do
# if line does not start with # then echo the line
if [[ $line != \#* ]]; then
if [[ $line != "" ]]; then
echo " ${line}"
fi
fi
done < .env

if [ $BRAINLIFE_DEVELOPMENT == true ]; then
# enable or disable debugging output
set -ex
else
set -e
fi

# build local changes and mount them directly into the containers
# api/ and ui/ are mounted as volumes at /app within the docker-compose.yml
(cd api && npm install)
(cd ui && npm install)

# update the bids submodule
git submodule update --init --recursive

# The main differences between the production and development docker-compose files are that the production
# files uses https via nginx and the development file uses http.
if [[ $BRAINLIFE_PRODUCTION == true ]]; then
DOCKER_COMPOSE_FILE=docker-compose-production.yml
else
DOCKER_COMPOSE_FILE=docker-compose.yml
fi

mkdir -p /tmp/upload
mkdir -p /tmp/workdir

#npm run prepare-husky

./generate_keys.sh

# ok docker compose is now included in docker as an option for docker
if [[ $(command -v docker-compose) ]]; then
# if the older version is installed use the dash
docker-compose --file ${DOCKER_COMPOSE_FILE} up
else
# if the newer version is installed don't use the dash
docker compose --file ${DOCKER_COMPOSE_FILE} up
fi
33 changes: 33 additions & 0 deletions nginx/production_nginx.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
server {
listen 443 ssl;
ssl_certificate /etc/nginx/conf.d/ssl/sslcert.cert;
ssl_certificate_key /etc/nginx/conf.d/ssl/sslcert.key;
ssl_password_file /etc/nginx/conf.d/ssl/sslpassword;
server_name $SERVER_NAME;
client_max_body_size 1200M;

location / {
return 301 /ezbids/;
}

location /ezbids {
alias /usr/share/nginx/html/ezbids/;
try_files $uri $uri/ /ezbids/index.html;
}

location /api/ {
proxy_pass http://api:8082/;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}

error_page 404 /404.html;

# redirect server error pages to the static page /50x.html
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}
Empty file added nginx/ssl/.gitkeep
Empty file.
Loading