From 66f67718c6921dde971bf1485df3ee7da137f932 Mon Sep 17 00:00:00 2001 From: Shoeb Joarder Date: Thu, 10 Apr 2025 15:58:43 +0200 Subject: [PATCH 01/14] Create init-admin.js --- scripts/init-admin.js | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 scripts/init-admin.js diff --git a/scripts/init-admin.js b/scripts/init-admin.js new file mode 100644 index 000000000..f19fc5c40 --- /dev/null +++ b/scripts/init-admin.js @@ -0,0 +1,35 @@ +import { createSiteAdmin } from "../cli/src/commands/createSiteAdmin.js"; +import mongoose from "mongoose"; + +const email = process.env.LL_ADMIN_EMAIL; +const organisationName = process.env.LL_ADMIN_ORG; +const password = process.env.LL_ADMIN_PASSWORD; + +if (!email || !organisationName || !password) { + console.error( + "Missing required environment variables: SITE_ADMIN_EMAIL, SITE_ADMIN_ORG_NAME, SITE_ADMIN_PASSWORD" + ); + process.exit(1); +} + +const options = { + forceUpdatePassword: true, +}; + +const run = async () => { + try { + await mongoose.connect( + `mongodb://${process.env.MONGO_HOST}:27017/${process.env.MONGO_DATABASE}` + ); + await createSiteAdmin(email, organisationName, password, options); + console.log("Admin user created or already exists."); + } catch (err) { + console.error("Failed to create admin user:", err); + process.exit(1); + } finally { + await mongoose.disconnect(); + process.exit(0); + } +}; + +run(); From 3c49e62806189807fb3a724aaeeaef02a25fbaa9 Mon Sep 17 00:00:00 2001 From: Shoeb Joarder Date: Thu, 10 Apr 2025 16:05:22 +0200 Subject: [PATCH 02/14] Fix typo --- scripts/init-admin.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/init-admin.js b/scripts/init-admin.js index f19fc5c40..623596b3e 100644 --- a/scripts/init-admin.js +++ b/scripts/init-admin.js @@ -7,7 +7,7 @@ const password = process.env.LL_ADMIN_PASSWORD; if (!email || !organisationName || !password) { console.error( - "Missing required environment variables: SITE_ADMIN_EMAIL, SITE_ADMIN_ORG_NAME, SITE_ADMIN_PASSWORD" + "Missing required environment variables: LL_ADMIN_EMAIL, LL_ADMIN_ORG, LL_ADMIN_PASSWORD" ); process.exit(1); } From dd7a749412b205f16b08db25e6771cba7945a9ad Mon Sep 17 00:00:00 2001 From: Shoeb Joarder Date: Thu, 10 Apr 2025 16:29:38 +0200 Subject: [PATCH 03/14] Fix common js issue --- scripts/init-admin.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/init-admin.js b/scripts/init-admin.js index 623596b3e..66f477f51 100644 --- a/scripts/init-admin.js +++ b/scripts/init-admin.js @@ -1,5 +1,5 @@ -import { createSiteAdmin } from "../cli/src/commands/createSiteAdmin.js"; -import mongoose from "mongoose"; +const { createSiteAdmin } = require("../cli/src/commands/createSiteAdmin"); +const mongoose = require("mongoose"); const email = process.env.LL_ADMIN_EMAIL; const organisationName = process.env.LL_ADMIN_ORG; From b030ebe7c751b7045d15706135daaab22b3b633d Mon Sep 17 00:00:00 2001 From: Ralf Berger Date: Wed, 23 Apr 2025 15:32:54 +0200 Subject: [PATCH 04/14] WIP: Add init-admin.js --- Dockerfile | 1 + Taskfile.docker.yaml | 5 +++++ bin/api | 3 +++ scripts/init-admin.js | 10 +++++----- 4 files changed, 14 insertions(+), 5 deletions(-) diff --git a/Dockerfile b/Dockerfile index 8def7c460..a374a8cfa 100644 --- a/Dockerfile +++ b/Dockerfile @@ -33,5 +33,6 @@ COPY --from=build /opt/learninglocker/cli/dist ./cli/dist COPY --from=build /opt/learninglocker/ui/dist ./ui/dist COPY --from=build /opt/learninglocker/worker/dist ./worker/dist COPY lib/templates/emails ./lib/templates/emails +COPY scripts ./scripts COPY bin ./bin ENTRYPOINT [ "bin/entrypoint" ] diff --git a/Taskfile.docker.yaml b/Taskfile.docker.yaml index 5b6b1eaa3..a578fb124 100644 --- a/Taskfile.docker.yaml +++ b/Taskfile.docker.yaml @@ -25,6 +25,11 @@ tasks: aliases: [ dev ] cmds: [ docker compose up --watch ] + cli: + desc: Start shell in cli container + cmds: + - docker compose run cli + admin: desc: Create an admin user cmds: diff --git a/bin/api b/bin/api index 6d495de21..7032878fb 100755 --- a/bin/api +++ b/bin/api @@ -1,4 +1,7 @@ #!/usr/bin/env sh +echo "Configuring admin account ..." +node scripts/init-admin.js + echo "Starting API ..." exec node api/dist/server diff --git a/scripts/init-admin.js b/scripts/init-admin.js index 66f477f51..d764c21d1 100644 --- a/scripts/init-admin.js +++ b/scripts/init-admin.js @@ -1,5 +1,5 @@ -const { createSiteAdmin } = require("../cli/src/commands/createSiteAdmin"); -const mongoose = require("mongoose"); +import { createSiteAdmin } from "../cli/src/commands/createSiteAdmin"; +import { connect, disconnect } from "mongoose"; const email = process.env.LL_ADMIN_EMAIL; const organisationName = process.env.LL_ADMIN_ORG; @@ -18,8 +18,8 @@ const options = { const run = async () => { try { - await mongoose.connect( - `mongodb://${process.env.MONGO_HOST}:27017/${process.env.MONGO_DATABASE}` + await connect( + `mongodb://${process.env.MONGO_HOST}:${process.env.MONGO_PORT}/${process.env.MONGO_DATABASE}` ); await createSiteAdmin(email, organisationName, password, options); console.log("Admin user created or already exists."); @@ -27,7 +27,7 @@ const run = async () => { console.error("Failed to create admin user:", err); process.exit(1); } finally { - await mongoose.disconnect(); + await disconnect(); process.exit(0); } }; From 28353a780181cc7ecf6f29d9c1b191dfc3df9e69 Mon Sep 17 00:00:00 2001 From: Shoeb Joarder Date: Thu, 14 Aug 2025 15:45:53 +0200 Subject: [PATCH 05/14] Fix Init admin - Issues: The ADMIN_EMAIL, LL_ADMIN_ORG, and LL_ADMIN_PASSWORD needs to be read from environment --- compose.yaml | 7 +++++-- scripts/init-admin.js | 35 +++++++++++------------------------ 2 files changed, 16 insertions(+), 26 deletions(-) diff --git a/compose.yaml b/compose.yaml index 9c7eb2388..1aa968fdc 100644 --- a/compose.yaml +++ b/compose.yaml @@ -37,6 +37,7 @@ x-common: &common services: api: <<: *common + build: . command: api ports: [ "8080:8080" ] depends_on: @@ -67,8 +68,10 @@ services: cli: <<: *common - profiles: [ halted ] - command: bash + profiles: [halted] + command: > + bash -c "yarn migrate && + node cli/dist/server createSiteAdmin" depends_on: - mongo develop: diff --git a/scripts/init-admin.js b/scripts/init-admin.js index d764c21d1..22c346ac8 100644 --- a/scripts/init-admin.js +++ b/scripts/init-admin.js @@ -1,9 +1,8 @@ -import { createSiteAdmin } from "../cli/src/commands/createSiteAdmin"; -import { connect, disconnect } from "mongoose"; +const { spawn } = require("child_process"); -const email = process.env.LL_ADMIN_EMAIL; -const organisationName = process.env.LL_ADMIN_ORG; -const password = process.env.LL_ADMIN_PASSWORD; +const email = process.env.LL_ADMIN_EMAIL || "admin@mail.com"; +const organisationName = process.env.LL_ADMIN_ORG || "soco"; +const password = process.env.LL_ADMIN_PASSWORD || "1234qweR"; if (!email || !organisationName || !password) { console.error( @@ -12,24 +11,12 @@ if (!email || !organisationName || !password) { process.exit(1); } -const options = { - forceUpdatePassword: true, -}; +console.log("Configuring admin account ..."); -const run = async () => { - try { - await connect( - `mongodb://${process.env.MONGO_HOST}:${process.env.MONGO_PORT}/${process.env.MONGO_DATABASE}` - ); - await createSiteAdmin(email, organisationName, password, options); - console.log("Admin user created or already exists."); - } catch (err) { - console.error("Failed to create admin user:", err); - process.exit(1); - } finally { - await disconnect(); - process.exit(0); - } -}; +const child = spawn( + "node", + ["cli/dist/server", "createSiteAdmin", email, organisationName, password], + { stdio: "inherit" } +); -run(); +child.on("exit", (code) => process.exit(code)); From f1114f6b2c1a939b36ff5c54438c7d52aad4bad5 Mon Sep 17 00:00:00 2001 From: Ralf Berger Date: Fri, 15 Aug 2025 12:43:48 +0200 Subject: [PATCH 06/14] Refactor DB migration and fixture jobs # Conflicts: # compose.yaml --- Dockerfile | 1 - bin/api | 3 --- bin/fixtures | 4 ++++ compose.yaml | 50 +++++++++++++++++++++++++++++-------------- scripts/init-admin.js | 22 ------------------- 5 files changed, 38 insertions(+), 42 deletions(-) create mode 100755 bin/fixtures delete mode 100644 scripts/init-admin.js diff --git a/Dockerfile b/Dockerfile index a374a8cfa..8def7c460 100644 --- a/Dockerfile +++ b/Dockerfile @@ -33,6 +33,5 @@ COPY --from=build /opt/learninglocker/cli/dist ./cli/dist COPY --from=build /opt/learninglocker/ui/dist ./ui/dist COPY --from=build /opt/learninglocker/worker/dist ./worker/dist COPY lib/templates/emails ./lib/templates/emails -COPY scripts ./scripts COPY bin ./bin ENTRYPOINT [ "bin/entrypoint" ] diff --git a/bin/api b/bin/api index 7032878fb..6d495de21 100755 --- a/bin/api +++ b/bin/api @@ -1,7 +1,4 @@ #!/usr/bin/env sh -echo "Configuring admin account ..." -node scripts/init-admin.js - echo "Starting API ..." exec node api/dist/server diff --git a/bin/fixtures b/bin/fixtures new file mode 100755 index 000000000..968fc879e --- /dev/null +++ b/bin/fixtures @@ -0,0 +1,4 @@ +#!/usr/bin/env sh + +echo "Setting up admin account ..." +node cli/dist/server createSiteAdmin ${LL_ADMIN_EMAIL:?} ${LL_ADMIN_ORG:?} ${LL_ADMIN_PASSWORD:?} diff --git a/compose.yaml b/compose.yaml index 1aa968fdc..ee64d16e5 100644 --- a/compose.yaml +++ b/compose.yaml @@ -6,8 +6,10 @@ x-common: &common depends_on: mongo: condition: service_healthy + restart: true redis: condition: service_healthy + restart: true develop: watch: - path: package.json @@ -33,34 +35,38 @@ 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 - build: . - command: api - ports: [ "8080:8080" ] + command: ui + ports: + - "3000:3000" depends_on: - - mongo + - api develop: watch: - - path: /api + - path: /ui action: rebuild - ui: + api: <<: *common - command: ui - ports: [ "3000:3000" ] + command: api + ports: [ "8080:8080" ] + depends_on: + fixtures: + condition: service_completed_successfully develop: watch: - - path: /ui + - path: /api action: rebuild worker: <<: *common command: worker - depends_on: - - mongo develop: watch: - path: /worker @@ -69,16 +75,28 @@ services: cli: <<: *common profiles: [halted] - command: > - bash -c "yarn migrate && - node cli/dist/server createSiteAdmin" + command: bash depends_on: - - mongo + fixtures: + condition: service_completed_successfully develop: watch: - path: /cli action: rebuild + fixtures: + <<: *common + command: fixtures + depends_on: + migrations: + condition: service_completed_successfully + restart: on-failure + + migrations: + <<: *common + command: yarn migrate + restart: on-failure + mongo: image: mongo:6.0 command: mongod --wiredTigerCacheSizeGB 0.25 --quiet --logpath /dev/null diff --git a/scripts/init-admin.js b/scripts/init-admin.js deleted file mode 100644 index 22c346ac8..000000000 --- a/scripts/init-admin.js +++ /dev/null @@ -1,22 +0,0 @@ -const { spawn } = require("child_process"); - -const email = process.env.LL_ADMIN_EMAIL || "admin@mail.com"; -const organisationName = process.env.LL_ADMIN_ORG || "soco"; -const password = process.env.LL_ADMIN_PASSWORD || "1234qweR"; - -if (!email || !organisationName || !password) { - console.error( - "Missing required environment variables: LL_ADMIN_EMAIL, LL_ADMIN_ORG, LL_ADMIN_PASSWORD" - ); - process.exit(1); -} - -console.log("Configuring admin account ..."); - -const child = spawn( - "node", - ["cli/dist/server", "createSiteAdmin", email, organisationName, password], - { stdio: "inherit" } -); - -child.on("exit", (code) => process.exit(code)); From d06116f19bce736a2303888e3cfc4427df77fa11 Mon Sep 17 00:00:00 2001 From: Ralf Berger Date: Fri, 15 Aug 2025 16:14:45 +0200 Subject: [PATCH 07/14] Downgrade MongoDB from 6.0 to 4.4 Fixes #7 --- compose.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compose.yaml b/compose.yaml index ee64d16e5..88fa11cbb 100644 --- a/compose.yaml +++ b/compose.yaml @@ -98,7 +98,7 @@ services: restart: on-failure mongo: - image: mongo:6.0 + image: mongo:4.4 command: mongod --wiredTigerCacheSizeGB 0.25 --quiet --logpath /dev/null ports: [ "27017:27017" ] volumes: From 3ae101f92fa057df93342be286a67c15b2f7459d Mon Sep 17 00:00:00 2001 From: Shoeb Joarder Date: Sat, 16 Aug 2025 07:19:13 +0200 Subject: [PATCH 08/14] Replace mongosh with mongo Fixes #7 --- compose.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compose.yaml b/compose.yaml index 88fa11cbb..2f4582edd 100644 --- a/compose.yaml +++ b/compose.yaml @@ -104,7 +104,7 @@ services: 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 From c860440e20943f7d8c632ee5473875fd16154ce6 Mon Sep 17 00:00:00 2001 From: Ralf Berger Date: Sat, 16 Aug 2025 12:20:40 +0200 Subject: [PATCH 09/14] Rename fixtures service and executable to seeds Makes more sense outside of testing. --- bin/{fixtures => seeds} | 0 compose.yaml | 8 ++++---- 2 files changed, 4 insertions(+), 4 deletions(-) rename bin/{fixtures => seeds} (100%) diff --git a/bin/fixtures b/bin/seeds similarity index 100% rename from bin/fixtures rename to bin/seeds diff --git a/compose.yaml b/compose.yaml index 2f4582edd..1c1a00a5c 100644 --- a/compose.yaml +++ b/compose.yaml @@ -57,7 +57,7 @@ services: command: api ports: [ "8080:8080" ] depends_on: - fixtures: + seeds: condition: service_completed_successfully develop: watch: @@ -77,16 +77,16 @@ services: profiles: [halted] command: bash depends_on: - fixtures: + seeds: condition: service_completed_successfully develop: watch: - path: /cli action: rebuild - fixtures: + seeds: <<: *common - command: fixtures + command: seeds depends_on: migrations: condition: service_completed_successfully From 4f2c8201cbad1e72ea9c655a49ade50823206f6c Mon Sep 17 00:00:00 2001 From: Ralf Berger Date: Sat, 16 Aug 2025 20:13:19 +0200 Subject: [PATCH 10/14] Clean up service dependencies and tasks --- Taskfile.docker.yaml | 5 ----- Taskfile.yaml | 1 - bin/migrations | 4 ++++ bin/seeds | 2 +- compose.yaml | 32 ++++++++++++++++++++------------ 5 files changed, 25 insertions(+), 19 deletions(-) create mode 100755 bin/migrations diff --git a/Taskfile.docker.yaml b/Taskfile.docker.yaml index a578fb124..b0ac0bf44 100644 --- a/Taskfile.docker.yaml +++ b/Taskfile.docker.yaml @@ -30,11 +30,6 @@ tasks: cmds: - docker compose run cli - admin: - desc: Create an admin user - cmds: - - docker compose run cli node cli/dist/server createSiteAdmin {{ .ADMIN_MAIL }} {{ .ADMIN_ORG }} {{ .ADMIN_PASS }} - clean: desc: Stop the application and remove data cmds: [ docker compose down --volumes ] diff --git a/Taskfile.yaml b/Taskfile.yaml index e6b623868..c09a12ede 100644 --- a/Taskfile.yaml +++ b/Taskfile.yaml @@ -12,5 +12,4 @@ tasks: default: cmds: - task: docker:build - - task: docker:admin - task: docker:watch diff --git a/bin/migrations b/bin/migrations new file mode 100755 index 000000000..95991040c --- /dev/null +++ b/bin/migrations @@ -0,0 +1,4 @@ +#!/usr/bin/env sh + +echo "Executing database migrations ..." +node cli/dist/server migrateMongo --up diff --git a/bin/seeds b/bin/seeds index 968fc879e..da1b6b0fc 100755 --- a/bin/seeds +++ b/bin/seeds @@ -1,4 +1,4 @@ #!/usr/bin/env sh -echo "Setting up admin account ..." +echo "Setting up seed data ..." node cli/dist/server createSiteAdmin ${LL_ADMIN_EMAIL:?} ${LL_ADMIN_ORG:?} ${LL_ADMIN_PASSWORD:?} diff --git a/compose.yaml b/compose.yaml index 1c1a00a5c..8700bd52d 100644 --- a/compose.yaml +++ b/compose.yaml @@ -3,13 +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 - restart: true - redis: - condition: service_healthy - restart: true develop: watch: - path: package.json @@ -57,8 +50,14 @@ services: command: api ports: [ "8080:8080" ] depends_on: + mongo: + condition: service_healthy + restart: true seeds: condition: service_completed_successfully + redis: + condition: service_healthy + restart: true develop: watch: - path: /api @@ -67,6 +66,13 @@ services: worker: <<: *common command: worker + depends_on: + mongo: + condition: service_healthy + restart: true + redis: + condition: service_healthy + restart: true develop: watch: - path: /worker @@ -75,10 +81,8 @@ services: cli: <<: *common profiles: [halted] - command: bash - depends_on: - seeds: - condition: service_completed_successfully + command: cli + tty: true develop: watch: - path: /cli @@ -94,7 +98,11 @@ services: migrations: <<: *common - command: yarn migrate + command: migrations + depends_on: + mongo: + condition: service_healthy + restart: true restart: on-failure mongo: From 8bc99428487346051282b4349d04545943d24eae Mon Sep 17 00:00:00 2001 From: Ralf Berger Date: Sat, 16 Aug 2025 20:18:00 +0200 Subject: [PATCH 11/14] Remove outdated Task --- Taskfile.docker.yaml | 1 - 1 file changed, 1 deletion(-) diff --git a/Taskfile.docker.yaml b/Taskfile.docker.yaml index f8365a0c4..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: From 2d969b0fe9eb670603c4a0f7789534eae43cb830 Mon Sep 17 00:00:00 2001 From: Ralf Berger Date: Sun, 17 Aug 2025 11:07:29 +0200 Subject: [PATCH 12/14] Quote env expansions to prevent word-splitting/globbing --- bin/seeds | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/seeds b/bin/seeds index da1b6b0fc..07c91b7b8 100755 --- a/bin/seeds +++ b/bin/seeds @@ -1,4 +1,4 @@ #!/usr/bin/env sh echo "Setting up seed data ..." -node cli/dist/server createSiteAdmin ${LL_ADMIN_EMAIL:?} ${LL_ADMIN_ORG:?} ${LL_ADMIN_PASSWORD:?} +node cli/dist/server createSiteAdmin "${LL_ADMIN_EMAIL:?}" "${LL_ADMIN_ORG:?}" "${LL_ADMIN_PASSWORD:?}" From d0e5d0dcce593ece5765c6edd2cac42c51c07445 Mon Sep 17 00:00:00 2001 From: Ralf Berger Date: Sun, 17 Aug 2025 11:08:30 +0200 Subject: [PATCH 13/14] Fail fast --- bin/api | 1 + bin/cli | 1 + bin/entrypoint | 1 + bin/migrations | 1 + bin/seeds | 1 + bin/ui | 1 + bin/worker | 1 + 7 files changed, 7 insertions(+) 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 index 95991040c..b38c75b35 100755 --- a/bin/migrations +++ b/bin/migrations @@ -1,4 +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 index 07c91b7b8..f73655e38 100755 --- a/bin/seeds +++ b/bin/seeds @@ -1,4 +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 From fe829bb28fe1bd7ecd86ea511a8160959fde98b4 Mon Sep 17 00:00:00 2001 From: Ralf Berger Date: Sun, 17 Aug 2025 11:24:52 +0200 Subject: [PATCH 14/14] Add health check to api service + formatting --- compose.yaml | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/compose.yaml b/compose.yaml index 8700bd52d..b90eadb41 100644 --- a/compose.yaml +++ b/compose.yaml @@ -36,10 +36,10 @@ services: ui: <<: *common command: ui - ports: - - "3000:3000" + ports: ["3000:3000"] depends_on: - - api + api: + condition: service_healthy develop: watch: - path: /ui @@ -48,7 +48,11 @@ services: api: <<: *common command: api - ports: [ "8080:8080" ] + 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 @@ -108,7 +112,7 @@ services: mongo: image: mongo:4.4 command: mongod --wiredTigerCacheSizeGB 0.25 --quiet --logpath /dev/null - ports: [ "27017:27017" ] + ports: ["27017:27017"] volumes: - mongo:/data/db healthcheck: @@ -121,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