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 12 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: 2 additions & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# insert your host name here, it should match the name/domain of your ssl certificate
SERVER_NAME=localhost
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,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
6 changes: 3 additions & 3 deletions dev.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ export BRAINLIFE_AUTHENTICATION

git submodule update --init --recursive

(cd api && npm install -g npm@9.5.1)
(cd ui && npm install -g npm@9.5.1)
(cd api && npm install)
(cd ui && npm install)

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

npm run prepare-husky
#npm run prepare-husky

./generate_keys.sh

Expand Down
101 changes: 101 additions & 0 deletions docker-compose-production.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
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/Dockerfile-production
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, 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"]
networks:
- ezbids

nginx:
env_file:
- .env
container_name: brainlife_ezbids-nginx
depends_on:
- ui
- api
image: nginx:latest
platform: linux/amd64
ports:
- 80:80
- 443:443
networks:
- ezbids
volumes:
- ./nginx/ssl:/etc/nginx/conf.d/ssl/
- ./nginx/production_nginx.conf:/etc/nginx/conf.d/default.conf
- ./ui/dist:/usr/share/nginx/html/ezbids:ro
49 changes: 43 additions & 6 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 @@ -27,7 +31,7 @@ services:
mongodb:
condition: service_healthy
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:8082/health"]
test: ["CMD", "curl", "-f", "http://api:8082/health"]
working_dir: /app/api
command:
./dev.sh
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,23 +57,29 @@ 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:
- ./ui/src:/ui/src #don't copy node_modules which might be compiled for mac (vite won't work)
environment:
VITE_APIHOST: http://localhost:8082
VITE_APIHOST: https://${SERVER_NAME}/api
VITE_BRAINLIFE_AUTHENTICATION: ${BRAINLIFE_AUTHENTICATION}
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:3000"]
test: ["CMD", "curl", "-f", "http://ui: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
Expand All @@ -77,4 +89,29 @@ services:
- mongodb
profiles: ["development"]
ports:
- 8000:8000 #for local debugging
- 8000:8000 #for local debugging
networks:
- ezbids

nginx:
env_file:
- .env
container_name: brainlife_ezbids-nginx
depends_on:
- ui
- api
image: nginx:latest
platform: linux/amd64
profiles: ["development"]
ports:
- 80:80
- 443:443
networks:
- ezbids
volumes:
- ./nginx/ssl:/etc/nginx/conf.d/ssl/
# replace production/development depending on whether you want ssl or not
- ./nginx/production_nginx.conf:/etc/nginx/conf.d/default.conf



2 changes: 1 addition & 1 deletion handler/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ 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
34 changes: 34 additions & 0 deletions nginx/development_nginx.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
server {
listen 80;
listen [::]:80;
# use the enviroment variable SERVER_NAME to set the server_name
server_name $SERVER_NAME;
client_max_body_size 1200M;

#access_log /var/log/nginx/host.access.log main;

location / {
root /usr/share/nginx/html;
index index.html index.htm;
}

location /ezbids {
proxy_pass http://ui:3000;
}

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;
}
}
37 changes: 37 additions & 0 deletions nginx/production_nginx.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
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;

#access_log /var/log/nginx/host.access.log main;

index index.html;

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