diff --git a/Taskfile.docker.yaml b/Taskfile.docker.yaml index d1befce99..c11778cc3 100644 --- a/Taskfile.docker.yaml +++ b/Taskfile.docker.yaml @@ -10,7 +10,6 @@ tasks: aliases: [ default ] cmds: - task: build - - task: admin - task: watch build: @@ -39,13 +38,7 @@ tasks: cli: desc: Start shell in cli container - cmds: - - $COMPOSE_CMD run cli - - admin: - desc: Create an admin user - cmds: - - $COMPOSE_CMD run cli node cli/dist/server createSiteAdmin {{ .ADMIN_MAIL }} {{ .ADMIN_ORG }} {{ .ADMIN_PASS }} + cmds: [ $COMPOSE_CMD run cli ] clean: desc: Stop the application and remove data diff --git a/bin/api b/bin/api index 6d495de21..e9f2d3e94 100755 --- a/bin/api +++ b/bin/api @@ -1,4 +1,5 @@ #!/usr/bin/env sh +set -eu echo "Starting API ..." exec node api/dist/server diff --git a/bin/cli b/bin/cli index a0dc1faea..5dfc5c8b4 100755 --- a/bin/cli +++ b/bin/cli @@ -1,4 +1,5 @@ #!/usr/bin/env sh +set -eu echo "Starting CLI ..." exec node cli/dist/server diff --git a/bin/entrypoint b/bin/entrypoint index ecb515bc1..81d1682fc 100755 --- a/bin/entrypoint +++ b/bin/entrypoint @@ -1,4 +1,5 @@ #!/usr/bin/env sh +set -eu MONGO_HOST="${MONGO_HOST:-localhost}" MONGO_PORT="${MONGO_PORT:-27017}" diff --git a/bin/migrations b/bin/migrations new file mode 100755 index 000000000..b38c75b35 --- /dev/null +++ b/bin/migrations @@ -0,0 +1,5 @@ +#!/usr/bin/env sh +set -eu + +echo "Executing database migrations ..." +node cli/dist/server migrateMongo --up diff --git a/bin/seeds b/bin/seeds new file mode 100755 index 000000000..f73655e38 --- /dev/null +++ b/bin/seeds @@ -0,0 +1,5 @@ +#!/usr/bin/env sh +set -eu + +echo "Setting up seed data ..." +node cli/dist/server createSiteAdmin "${LL_ADMIN_EMAIL:?}" "${LL_ADMIN_ORG:?}" "${LL_ADMIN_PASSWORD:?}" diff --git a/bin/ui b/bin/ui index 773384d4e..56429b09d 100755 --- a/bin/ui +++ b/bin/ui @@ -1,4 +1,5 @@ #!/usr/bin/env sh +set -eu echo "Starting UI ..." exec node ui/dist/server diff --git a/bin/worker b/bin/worker index 597936ba3..03c31c69f 100755 --- a/bin/worker +++ b/bin/worker @@ -1,4 +1,5 @@ #!/usr/bin/env sh +set -eu echo "Starting worker ..." exec node worker/dist/server diff --git a/compose.yaml b/compose.yaml index 9c7eb2388..b90eadb41 100644 --- a/compose.yaml +++ b/compose.yaml @@ -3,11 +3,6 @@ name: learninglocker x-common: &common build: . image: ${IMAGE_NAME_PREFIX:-ghcr.io/ude-soco/}learninglocker:${IMAGE_TAG:-latest} - depends_on: - mongo: - condition: service_healthy - redis: - condition: service_healthy develop: watch: - path: package.json @@ -33,33 +28,55 @@ x-common: &common # SMTP_USER # SMTP_PASS APP_SECRET: "i-am-not-secure-please-change-me" + LL_ADMIN_EMAIL: "admin@mail.com" + LL_ADMIN_ORG: "soco" + LL_ADMIN_PASSWORD: "1234qweR" services: - api: + ui: <<: *common - command: api - ports: [ "8080:8080" ] + command: ui + ports: ["3000:3000"] depends_on: - - mongo + api: + condition: service_healthy develop: watch: - - path: /api + - path: /ui action: rebuild - ui: + api: <<: *common - command: ui - ports: [ "3000:3000" ] + command: api + ports: ["8080:8080"] + healthcheck: + test: [CMD, node, -e, "'fetch(`http://localhost:8080/`).then(x=>x.status==200?process.exit(0):process.exit(1)).catch(()=>process.exit(1))'"] + start_period: 10s + interval: 10s + depends_on: + mongo: + condition: service_healthy + restart: true + seeds: + condition: service_completed_successfully + redis: + condition: service_healthy + restart: true develop: watch: - - path: /ui + - path: /api action: rebuild worker: <<: *common command: worker depends_on: - - mongo + mongo: + condition: service_healthy + restart: true + redis: + condition: service_healthy + restart: true develop: watch: - path: /worker @@ -67,23 +84,39 @@ services: cli: <<: *common - profiles: [ halted ] - command: bash - depends_on: - - mongo + profiles: [halted] + command: cli + tty: true develop: watch: - path: /cli action: rebuild + seeds: + <<: *common + command: seeds + depends_on: + migrations: + condition: service_completed_successfully + restart: on-failure + + migrations: + <<: *common + command: migrations + depends_on: + mongo: + condition: service_healthy + restart: true + restart: on-failure + mongo: - image: mongo:6.0 + image: mongo:4.4 command: mongod --wiredTigerCacheSizeGB 0.25 --quiet --logpath /dev/null - ports: [ "27017:27017" ] + ports: ["27017:27017"] volumes: - mongo:/data/db healthcheck: - test: "mongosh --nodb --eval 'disableTelemetry()'; echo 'db.runCommand({ping: 1}).ok' | mongosh localhost:27017/test --quiet" + test: "mongo --nodb --eval 'disableTelemetry()'; echo 'db.runCommand({ping: 1}).ok' | mongo localhost:27017/test --quiet" start_period: 2s interval: 10s @@ -92,16 +125,16 @@ services: command: --loglevel warning volumes: - redis:/data - ports: [ "6379:6379" ] + ports: ["6379:6379"] healthcheck: - test: ["CMD", "redis-cli","ping"] + test: ["CMD", "redis-cli", "ping"] start_period: 2s interval: 10s xapi-service: image: learninglocker/xapi-service platform: linux/amd64 - ports: [ "8081:8081" ] + ports: ["8081:8081"] depends_on: mongo: condition: service_healthy