Skip to content

Commit

Permalink
code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Dan Levitas committed Feb 6, 2024
1 parent 09ff81b commit b141fad
Show file tree
Hide file tree
Showing 4 changed files with 102 additions and 113 deletions.
10 changes: 4 additions & 6 deletions Singularity
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@ From: node:16
Stage: spython-base

%environment
MONGO_CONNECTION_STRING=mongodb://mongodb:27017/ezbids
BRAINLIFE_AUTHENTICATION=false
SINGULARITY_PWD=/app/api # Not sure this is being properly set (or at least adhered to)
PORT=8082
export MONGO_CONNECTION_STRING BRAINLIFE_AUTHENTICATION PORT SINGULARITY_PWD

export MONGO_CONNECTION_STRING=mongodb://mongodb:27017/ezbids
export BRAINLIFE_AUTHENTICATION=false
export SINGULARITY_PWD=/app/api # Not sure this is being properly set (or at least adhered to)
export PORT=8082

%post
mkdir -p /app
Expand Down
57 changes: 37 additions & 20 deletions dev.sh
Original file line number Diff line number Diff line change
Expand Up @@ -39,35 +39,52 @@ npm run prepare-husky
export SINGULARITY_DISABLE_CACHE=true
export SINGULARITY_CACHEDIR=/tmp

# Approach #1: singularity (individual .sif files)
# # Approach #1: singularity (individual .sif files)

# # Helpful commentary on mongodb container build with Singularity: https://stackoverflow.com/questions/70746228/singularity-mongodb-container-in-background-mode
# if [ ! -d $PWD/mongodb/data/db ]; then
# mkdir -p $PWD/mongodb/data/db
# chmod -R 770 $PWD/mongodb/data/db
# # if [ ! -d $PWD/mongodb/data/db ]; then
# # mkdir -p $PWD/mongodb/data/db
# # chmod -R 770 $PWD/mongodb/data/db
# # fi

# if [ ! -d $PWD/mongodb/data ]; then
# mkdir -p $PWD/mongodb/data
# chmod -R 770 $PWD/mongodb/data
# fi


# if [ ! -f $PWD/mongodb/mongodb.sif ]; then # Will eventually be redundant and can remove
# echo "building mongodb"
# # build image
# singularity build \
# singularity build \
# --arch "amd64" \
# --fakeroot \
# --disable-cache \
# $PWD/mongodb/mongodb.sif \
# $PWD/mongodb/Singularity

# # start the container instance
# singularity instance start \
# --fakeroot \
# --bind $PWD/mongodb/data/db:/data/db \
# $PWD/mongodb/mongodb.sif \
# brainlife_ezbids-mongodb
# # # start the container instance
# # singularity instance start \
# # --fakeroot \
# # --bind $PWD/mongodb/data:/data/db \
# # --net \
# # --network-args "portmap=27417:27017/tcp" \
# # --network-args "IP=0.0.0.0" \
# # $PWD/mongodb/mongodb.sif \
# # brainlife_ezbids-mongodb

# # run the container instance
# singularity run \
# --fakeroot \
# --bind $PWD/mongodb/data:/data/db \
# --net \
# --network-args "portmap=27417:27017/tcp" \
# $PWD/mongodb/mongodb.sif

# # --network-args "IP=127.0.0.1" \
# # --hostname brainlife_ezbids-mongodb \

# # DEBUG singularity instance start --bind /home/ubuntu/dlevitas/brainlife/ezbids/mongodb/data:/data/db --net --network-args "portmap=27417:27017/tcp" --network-args "IP=10.22.0.2" --hostname mongodb1 --writable-tmpfs /home/ubuntu/dlevitas/brainlife/ezbids/mongodb/mongodb.sif mongodb1


# # --net \
# # --network-args "portmap=27417:27017/tcp" \
# # --bind $PWD/data/db:/data/db \ # Might not need this if mongodb/Singularity contains a %files section
# # singularity run instance://brainlife_ezbids-mongodb # This seems to run mongodb in the foreground, meaning can't move on to building other containers.
# fi

Expand Down Expand Up @@ -95,9 +112,9 @@ export SINGULARITY_CACHEDIR=/tmp

# Approach #2: singularity-compose

if [ ! -d $PWD/mongodb/data/db ]; then
mkdir -p $PWD/mongodb/data/db
chmod -R 770 $PWD/mongodb/data/db
fi
# if [ ! -d $PWD/mongodb/data/db ]; then
# mkdir -p $PWD/mongodb/data/db
# chmod -R 770 $PWD/mongodb/data/db
# fi
singularity-compose down
singularity-compose --debug up --no-resolv
12 changes: 11 additions & 1 deletion mongodb/Singularity
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,21 @@ Bootstrap: docker
From: mongo:4.4.15

%setup
mkdir -p /data/db
# mkdir -p /data/db
if [ ! -d $PWD/data ]; then
mkdir -p $PWD/data
fi
echo "Setup working directory: $PWD"

%environment
export HOME=/data/db
export SINGULARITY_PWD=/

%post
echo "Current working directory: $PWD"

%runscript # Unsure if this section is necessary (doesn't seem like it)
exec /usr/bin/mongod "$@"
%startscript # Unsure if this section is necessary (doesn't seem like it)
exec /usr/bin/mongod "$@"
136 changes: 50 additions & 86 deletions singularity-compose.yml
Original file line number Diff line number Diff line change
@@ -1,109 +1,73 @@
version: "2.0"

instances:
# mongodb: # ORIGINAL
# container_name: brainlife_ezbids-mongodb
# image: docker://mongo:4.4.15
# platform: linux/amd64
# volumes:
# - /tmp:/tmp
# ports:
# - 27417:27017 #for local debugging
# post:
# command:
# - "mongod --dbpath /tmp"

# mongodb: # NEW BUT STILL BAD
# container_name: brainlife_ezbids-mongodb
# build:
# context: ./mongodb
# options:
# - fakeroot
# platform: linux/amd64
# # volumes:
# # - ./data/db:/data/db
# post:
# command: [ "/bin/bash", "./mongodb/mongodb_setup.sh"]
# ports:
# - 27417:27017 #for local debugging

# mongodb: # THIRD ATTEMPT
# container_name: brainlife_ezbids-mongodb
# image: docker://mongo:4.4.15
# platform: linux/amd64
# volumes:
# - ./data/db:/data/db
# ports:
# - 27417:27017 #for local debugging
# # run:
# # background: true # Does this actually run things in the background? Doesn't seem to

mongodb: # FOURTH ATTEMPT
mongodb:
container_name: brainlife_ezbids-mongodb
build:
context: ./mongodb
options:
- fakeroot
platform: linux/amd64
volumes:
- ./mongodb/data/db:/data/db
- ./mongodb/data:/data/db
network:
options:
- fakeroot
# enable: true
# allocate_ip: true
enable: true
allocate_ip: true
args:
- portmap=27417:27017/tcp
- IP=127.0.0.1
ports:
- 27417:27017 #for local debugging
- 27417:27017 # for local debugging
run: # start results in errors
background: true
options:
- fakeroot
command: mongod --dbpath /data/db
command: mongod --dbpath /data/db --port=27017 # command: mongod --dbpath /data/db --bind_ip_all --logpath /data/db/mongod.log --fork

# api: # This seemss good, just needs mongodb up and running properly
# container_name: brainlife_ezbids-api
# build:
# context: .
# options:
# - fakeroot
# platform: linux/amd64
# volumes:
# - ./api:/app/api
# - /tmp:/tmp
# ports:
# - 8082:8082 #localhost runs on local browser to it needs to access api via host port
api: # This seemss good, just needs mongodb up and running properly
container_name: brainlife_ezbids-api
build:
context: .
options:
- fakeroot
platform: linux/amd64
volumes:
- ./api:/app/api
- /tmp:/tmp
ports:
- 8082:8082 #localhost runs on local browser to it needs to access api via host port

# handler:
# container_name: brainlife_ezbids-handler
# build:
# context: ./handler
# options:
# - fakeroot
# platform: linux/amd64
# volumes:
# - .:/app
# - /tmp:/tmp
# # depends_on:
# # mongodb:
# # condition: service_healthy
# # api:
# # condition: service_healthy
# # tty: true #turn on color for bids-validator output
# run:
# options:
# - fakeroot
# command: pm2 start handler.js --attach --watch --ignore-watch "ui **/node_modules"
handler:
container_name: brainlife_ezbids-handler
build:
context: ./handler
options:
- fakeroot
platform: linux/amd64
volumes:
- .:/app
- /tmp:/tmp
# depends_on:
# mongodb:
# condition: service_healthy
# api:
# condition: service_healthy
# tty: true # don't think this works with Singularity
run:
options:
- fakeroot
command: pm2 start handler.js --attach --watch --ignore-watch "ui **/node_modules"

# ui:
# container_name: brainlife_ezbids-ui
# build:
# context: ./ui
# options:
# - fakeroot
# platform: linux/amd64
# volumes:
# - ./ui/src:/ui/src #don't copy node_modules which might be compiled for mac (vite won't work)
# ports:
# - 3000:3000 #vite wants to be exposed on the host for HMR?
ui:
container_name: brainlife_ezbids-ui
build:
context: ./ui
options:
- fakeroot
platform: linux/amd64
volumes:
- ./ui/src:/ui/src # don't copy node_modules which might be compiled for mac (vite won't work)
ports:
- 3000:3000 # vite wants to be exposed on the host for HMR?

0 comments on commit b141fad

Please sign in to comment.