Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
ce8b95f
Added .gitignore and README
Feb 3, 2025
8d5e8b2
Updated README for formatting
Feb 3, 2025
bfaddbc
Adding apptainer scripts
Feb 3, 2025
d30fdf3
Added fix to issue where project files wasnt mounted to containers an…
Mar 5, 2025
030363d
Merge branch 'bendhouseart:master' into apptainer
kiwimarc Mar 5, 2025
82113ef
Updated .gitignore
Mar 11, 2025
99ff232
Updated .gitignore
Mar 11, 2025
cfeb0cf
Removed need for overlay and added so run sources env
Mar 11, 2025
57214e2
Update dev_apptainer.sh
kiwimarc Mar 11, 2025
94e2900
Update dev_apptainer.sh
kiwimarc Mar 11, 2025
51e4d13
Update dev_apptainer.sh
kiwimarc Apr 8, 2025
d4cef35
Update dev_apptainer.sh
kiwimarc Apr 8, 2025
0dd0c51
Update README.md
kiwimarc Apr 8, 2025
5bd7c40
Update run_apptainer.sh
kiwimarc Apr 8, 2025
bbdffa7
Revert "Update run_apptainer.sh"
Apr 8, 2025
938d88a
Revert "Update README.md"
Apr 8, 2025
ff2415b
Revert "Update dev_apptainer.sh"
Apr 8, 2025
0183588
Revert "Update dev_apptainer.sh"
Apr 8, 2025
2340f16
Update run_apptainer.sh
kiwimarc Apr 23, 2025
2532987
Update dev_apptainer.sh
kiwimarc Apr 23, 2025
6b90ccb
Update dev_apptainer.sh
kiwimarc Apr 23, 2025
22beaab
Update dev_apptainer.sh
kiwimarc Apr 23, 2025
ecf25a7
Update run_apptainer.sh
kiwimarc Apr 28, 2025
ff4ed85
Update dev_apptainer.sh
kiwimarc Apr 28, 2025
68f0918
Update start_handler.sh
kiwimarc Apr 28, 2025
380dd11
Update dev_apptainer.sh
kiwimarc Apr 28, 2025
7160b96
Update README.md
kiwimarc May 5, 2025
4be6ca4
Add changes from testing, excluding tar and sif files
mnoergaard May 12, 2025
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
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,8 @@ api/*.js.map

# ssl certs we ignore the content of the folder but keep the folder around.
nginx/ssl/*
!nginx/ssl/.gitkeep
!nginx/ssl/.gitkeep

# apptainer tmp dir
tmp/

Empty file modified api/.gitignore
100644 → 100755
Empty file.
Empty file modified api/auth.ts
100644 → 100755
Empty file.
Empty file added api/cat
Empty file.
Empty file modified api/config.ts
100644 → 100755
Empty file.
Empty file modified api/controllers.ts
100644 → 100755
Empty file.
Empty file modified api/controllers.utils.ts
100644 → 100755
Empty file.
Empty file modified api/ezbids.ts
100644 → 100755
Empty file.
Empty file added api/ezbids@1.1.0
Empty file.
Empty file modified api/models.ts
100644 → 100755
Empty file.
Empty file added api/npm
Empty file.
6,306 changes: 6,302 additions & 4 deletions api/package-lock.json

Large diffs are not rendered by default.

58 changes: 58 additions & 0 deletions api/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
{
"name": "ezbids",
"version": "1.1.0",
"description": "",
"main": "index.js",
"scripts": {
"uidev": "cd ui && lite-server",
"tsc": "tsc",
"dev": "ts-node-dev --respawn ./ezbids.ts",
"prod": "tsc && node ./build/ezbids.js",
"deploy": "ssh -t hayashis@test.brainlife.io \"sudo su - -c 'cd /root/docker/ezbids && ./update.sh'\"",
"deploy-prod": "ssh -t -J hayashis@brainlife.io ubuntu@ezbids \"sudo su - -c 'cd /root/docker/ezbids && ./update.sh'\"",
"style-check": "prettier --config .prettierrc.json --check",
"lint-check": "eslint --ext .ts,.vue,.js",
"lint-staged": "lint-staged --config .lintstagedrc.json",
"prepare-husky": "husky install"
},
"author": "",
"license": "MIT",
"dependencies": {
"@types/express": "^4.17.13",
"@types/jsonwebtoken": "^9.0.4",
"archiver": "^5.3.0",
"async": "^3.2.3",
"body-parser": "^1.19.2",
"compression": "^1.7.4",
"cors": "^2.8.5",
"express": "^4.17.3",
"express-fileupload": "^1.3.1",
"express-jwt": "^8.4.1",
"jsonwebtoken": "^9.0.2",
"mkdirp": "^1.0.4",
"mongoose": "^6.2.7",
"multer": "1.4.4-lts.1",
"nan": "^2.17.0",
"nocache": "^2.1.0",
"node-pty": "^0.10.1",
"range-stream": "^1.1.0",
"send-seekable": "^1.0.4",
"swagger-jsdoc": "^6.2.8",
"swagger-ui-express": "^5.0.0"
},
"devDependencies": {
"@types/async": "^3.2.12",
"@types/cors": "^2.8.12",
"@types/node": "^20.17.46",
"@typescript-eslint/eslint-plugin": "^6.9.1",
"@typescript-eslint/parser": "^6.9.1",
"eslint": "^8.52.0",
"eslint-config-prettier": "^9.0.0",
"eslint-plugin-prettier": "^5.0.1",
"lint-staged": "^15.0.2",
"prettier": "^3.3.3",
"ts-node-dev": "^2.0.0",
"tsc-watch": "^6.0.4",
"typescript": "^4.9.5"
}
}
Empty file modified api/tsconfig.json
100644 → 100755
Empty file.
2 changes: 2 additions & 0 deletions apptainer/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*.sif
.env
49 changes: 49 additions & 0 deletions apptainer/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# Apptainer for ezBIDS

This guide provides steps to convert Docker containers into Apptainer images and run them.

## Converting Docker to Apptainer

### Step 1: Build and Stop Docker Containers
Run the following command to build and start the Docker containers:
```sh
docker-compose up --build
```

If the containers are running, stop them with:
```sh
docker-compose down
```

### Step 2: Export Docker Images
Save the running images to `.tar` files:
```sh
docker save -o api_image.tar ezbids-api
docker save -o handler_image.tar ezbids-handler
docker save -o ui_image.tar ezbids-ui
docker save -o telemetry_image.tar ezbids-telemetry
```
For more information, refer to the Docker documentation: [Docker Save Command](https://docs.docker.com/reference/cli/docker/image/save/)

### Step 3: Convert Docker Images to Apptainer Images
Use the following commands to convert each exported Docker image to an Apptainer `.sif` image:
```sh
apptainer build api.sif docker-archive:api_image.tar
apptainer build handler.sif docker-archive:handler_image.tar
apptainer build ui.sif docker-archive:ui_image.tar
apptainer build telemetry.sif docker-archive:telemetry_image.tar
```

## Usage

### Starting the Containers
Run the following command to start the Apptainer containers:
```sh
./run_apptainer.sh
```

### Stopping the Containers
To stop the Apptainer containers, execute:
```sh
./stop_apptainer.sh
```
62 changes: 62 additions & 0 deletions apptainer/dev_apptainer.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#!/usr/bin/env bash

cd "$(dirname "$0")/.."

set -ex

# Explicitly check if a .env file exists in the correct location explicitly:
ENV_PATH="apptainer/.env"
if [ -f "$ENV_PATH" ]; then
echo ".env file exists at $ENV_PATH, loading environment variables."
else
echo ".env file does not exist at $ENV_PATH. Creating it explicitly now."
cat << EOF > "$ENV_PATH"
SERVER_NAME=localhost
BRAINLIFE_PRODUCTION=false
SSL_CERT_PATH=./nginx/ssl/sslcert.cert
SSL_KEY_PATH=./nginx/ssl/sslcert.key
SSL_PASSWORD_PATH=./nginx/ssl/sslpassword
BRAINLIFE_AUTHENTICATION=false
BRAINLIFE_DEVELOPMENT=false
COMPOSE_PROFILES=
VITE_APIHOST=http://localhost:8082
EOF
echo "Explicitly created .env file at $ENV_PATH explicitly."
fi

# Ensure SERVER_NAME=localhost exists in .env explicitly
if ! grep -q "^SERVER_NAME=" "$ENV_PATH"; then
echo "SERVER_NAME=localhost" >> "$ENV_PATH"
echo "Added SERVER_NAME=localhost to $ENV_PATH explicitly."
fi

# Explicitly create required directories explicitly:
required_dirs=("tmp" "tmp/data" "tmp/ezbids-workdir" "tmp/upload" "tmp/workdir")

for dir in "${required_dirs[@]}"; do
[ ! -d "$dir" ] && mkdir -p "$dir"
done

# Parse arguments explicitly for authentication flag explicitly
BRAINLIFE_AUTHENTICATION=true
while getopts "d" flag; do
case $flag in
d) BRAINLIFE_AUTHENTICATION=false ;;
esac
done
export BRAINLIFE_AUTHENTICATION

# Check Node.js version explicitly
REQUIRED_NODE_VERSION="18"
CURRENT_NODE_VERSION=$(node -v | cut -d '.' -f 1 | sed 's/v//')

if [ "$CURRENT_NODE_VERSION" -ne "$REQUIRED_NODE_VERSION" ]; then
echo "Warning: You are explicitly using Node.js version $CURRENT_NODE_VERSION. Explicitly recommended version is $REQUIRED_NODE_VERSION."
fi

# Update git submodules and explicitly install dependencies explicitly:
git submodule update --init --recursive
(cd api && npm install)
(cd ui && npm install)

./generate_keys.sh
1 change: 1 addition & 0 deletions apptainer/mongo_host
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
127.0.0.1 localhost mongodb
6 changes: 6 additions & 0 deletions apptainer/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

74 changes: 74 additions & 0 deletions apptainer/run_apptainer.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
#!/usr/bin/env bash

EZBIDS_DIR=/home/martinnorgaard/Documents/GitHub/ezbids
cd "$EZBIDS_DIR"

# Load environment variables explicitly from the .env file
source "$EZBIDS_DIR/apptainer/.env"

"$EZBIDS_DIR/apptainer/dev_apptainer.sh"

if [ ! -e "$EZBIDS_DIR/apptainer/mongodb.sif" ]; then
apptainer build "$EZBIDS_DIR/apptainer/mongodb.sif" docker://mongo:4.4.15
fi

# Stop previously running instances explicitly
apptainer instance stop mongodb api handler ui >/dev/null 2>&1

# Explicitly start MongoDB container (port 27017 explicitly exposed)
echo "Starting MongoDB container..."
apptainer instance run \
--fakeroot --writable-tmpfs \
--bind "$EZBIDS_DIR/tmp":/tmp \
--bind "$EZBIDS_DIR/tmp/data":/data/db \
--bind "$EZBIDS_DIR/apptainer":/app \
--hostname mongodb \
"$EZBIDS_DIR/apptainer/mongodb.sif" mongodb bash -c "cd /app && ./start_mongodb.sh --bind_ip_all" &

sleep 5

# Explicitly start API container (port 8082 explicitly exposed)
echo "Starting API container..."
apptainer instance run \
--fakeroot \
--writable-tmpfs \
--bind "$EZBIDS_DIR/api":/app/api \
--bind "$EZBIDS_DIR/apptainer":/app/apptainer \
--bind "$EZBIDS_DIR/tmp":/tmp \
"$EZBIDS_DIR/apptainer/api.sif" api bash -c "cd /app/api && npm install && npm install --save-dev ts-node-dev typescript @types/node && npm run dev" &

sleep 5

# Explicitly start Handler container explicitly
echo "Starting Handler container..."
apptainer instance run \
--fakeroot \
--writable-tmpfs \
--env "PRESORT=$PRESORT" \
--bind "$EZBIDS_DIR/handler":/app/handler \
--bind "$EZBIDS_DIR/apptainer":/app/apptainer \
--bind "$EZBIDS_DIR/tmp":/tmp \
"$EZBIDS_DIR/apptainer/handler.sif" handler bash -c "cd /app/handler && chmod +x ./start.sh && ./start.sh" &

sleep 5

# Explicitly start UI container explicitly (port 3000 explicitly exposed)
echo "Starting UI container explicitly..."
apptainer instance run \
--bind "$EZBIDS_DIR/ui":/ui \
--bind "$EZBIDS_DIR/tmp":/tmp \
--env "VITE_APIHOST=http://localhost:8082" \
--env "BRAINLIFE_PRODUCTION=false" \
"$EZBIDS_DIR/apptainer/ui.sif" ui bash -c "cd /ui && ./entrypoint.sh"

sleep 5

if [ "$PROFILE" == "development" ]; then
echo "Starting Telemetry container..."
apptainer instance run \
--bind "$EZBIDS_DIR":/app \
"$EZBIDS_DIR/apptainer/telemetry.sif" telemetry bash -c "cd /app/apptainer && ./start_telemetry.sh" &
fi

echo "All containers are running explicitly"

5 changes: 5 additions & 0 deletions apptainer/start_api.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env bash

cd ..
cd api/
./dev.sh
4 changes: 4 additions & 0 deletions apptainer/start_handler.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env bash
cd ..
cd handler/
./start.sh
3 changes: 3 additions & 0 deletions apptainer/start_mongodb.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env bash

mongod --bind_ip_all --dbpath /data/db
5 changes: 5 additions & 0 deletions apptainer/start_telementry.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env bash

cd ..
cd telementry/
npm start
5 changes: 5 additions & 0 deletions apptainer/start_ui.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env bash

cd ../ui
npm install
npm run dev -- --host 0.0.0.0
10 changes: 10 additions & 0 deletions apptainer/stop_apptainer.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/usr/bin/env bash

echo "Stopping containers..."
apptainer instance stop api
apptainer instance stop handler
apptainer instance stop mongodb
apptainer instance stop ui
if [ "$PROFILE" == "development" ]; then
apptainer instance stop telementry
fi
5 changes: 5 additions & 0 deletions apptainer/ui_container.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
INFO: squashfuse not found, will not be able to mount SIF or other squashfs files
INFO: fuse2fs not found, will not be able to mount EXT3 filesystems
INFO: gocryptfs not found, will not be able to use gocryptfs
INFO: Converting SIF file to temporary sandbox...
INFO: instance started successfully
3 changes: 3 additions & 0 deletions docker-compose-production.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ services:

api:
container_name: brainlife_ezbids-api
image: ezbids-api # <-- explicitly set this
build: .
platform: linux/amd64
volumes:
Expand All @@ -41,6 +42,7 @@ services:

handler:
container_name: brainlife_ezbids-handler
image: ezbids-handler # <-- explicitly set this
build: ./handler
platform: linux/amd64
volumes:
Expand Down Expand Up @@ -73,6 +75,7 @@ services:
# by default this is not enabled, add COMPOSE_PROFILES=telemetry to your .env
telemetry:
container_name: brainlife_ezbids-telemetry
image: ezbids-telemetry # <-- explicitly set this
build: ./telemetry
platform: linux/amd64
depends_on:
Expand Down
Loading