From 4c391ebee8841f685bafab3244c6250b59859c47 Mon Sep 17 00:00:00 2001 From: sudip-khanal Date: Thu, 8 Oct 2026 12:08:58 +0545 Subject: [PATCH 1/4] feat(scripts): add scripts to sync submodule - Add bash scripts to sync the submodule - Add bash scripts to fetch latest commit hash --- scripts/get-commit-hash.sh | 30 ++++++++++++++++++++++++++++++ scripts/run_ollama.sh | 0 scripts/sub-module-sync.sh | 3 +++ 3 files changed, 33 insertions(+) create mode 100755 scripts/get-commit-hash.sh mode change 100644 => 100755 scripts/run_ollama.sh create mode 100755 scripts/sub-module-sync.sh diff --git a/scripts/get-commit-hash.sh b/scripts/get-commit-hash.sh new file mode 100755 index 0000000..476f936 --- /dev/null +++ b/scripts/get-commit-hash.sh @@ -0,0 +1,30 @@ +#!/bin/bash + +# Set the base Git directory (default to current .git directory) +BASE_DIR="${1:-.git}" +HEAD_PATH="$BASE_DIR/HEAD" + +# Function to get the current commit SHA +if [[ ! -f "$HEAD_PATH" ]]; then + echo "HEAD file not found: $HEAD_PATH" >&2 + exit 1 +fi + +# Read the content of HEAD +ref=$(<"$HEAD_PATH") +ref=$(echo "$ref" | tr -d '\n') + +if [[ "$ref" == ref:\ * ]]; then + # It's a symbolic ref + ref_path="$BASE_DIR/${ref#ref: }" + if [[ -f "$ref_path" ]]; then + commit_hash=$(<"$ref_path") + echo "$commit_hash" + else + echo "Ref file not found: $ref_path" >&2 + exit 1 + fi +else + # Detached HEAD + echo "$ref" +fi diff --git a/scripts/run_ollama.sh b/scripts/run_ollama.sh old mode 100644 new mode 100755 diff --git a/scripts/sub-module-sync.sh b/scripts/sub-module-sync.sh new file mode 100755 index 0000000..ff0cda4 --- /dev/null +++ b/scripts/sub-module-sync.sh @@ -0,0 +1,3 @@ +#!/bin/bash -x +git submodule foreach 'git fetch' +git submodule foreach 'git checkout $(git config -f $toplevel/.gitmodules submodule.$name.branch || echo main)' From b9ed0dfb86f0da6fa29418cb1554a8af64872fcd Mon Sep 17 00:00:00 2001 From: sudip-khanal Date: Thu, 8 Oct 2026 12:11:41 +0545 Subject: [PATCH 2/4] feat: add taskfile - Add Taskfile to run the web-build command --- Taskfile.yml | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 Taskfile.yml diff --git a/Taskfile.yml b/Taskfile.yml new file mode 100644 index 0000000..69989ae --- /dev/null +++ b/Taskfile.yml @@ -0,0 +1,22 @@ +# yaml-language-server: $schema=https://taskfile.dev/schema.json + +version: '3' +env: + FRONTEND_COMMIT_HASH: + sh: ./scripts/get-commit-hash.sh .git/modules/frontend + CMS_COMMIT_HASH: + sh: ./scripts/get-commit-hash.sh .git/modules/cms + + +tasks: + web-build-frontend: + cmds: + - docker compose --profile web-builds up --build + web-build-cms: + cmds: + - docker compose --profile web-builds up --build + web-builds: + cmds: + - task: web-build-frontend + - task: web-build-cms + - echo "Success" From 5c0d3faf942ddacfedb23e565566f7b842ba5e5d Mon Sep 17 00:00:00 2001 From: sudip-khanal Date: Thu, 8 Oct 2026 12:14:07 +0545 Subject: [PATCH 3/4] feat(docker-compose): add app commit hash env --- docker-compose.yaml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docker-compose.yaml b/docker-compose.yaml index 96ec16a..a059935 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -169,6 +169,7 @@ services: APP_ENVIRONMENT: ${WEB_APP_ENVIRONMENT?error} APP_GRAPHQL_ENDPOINT: https://${BACKEND_HOST?error}/graphql/ APP_GRAPHQL_CODEGEN_ENDPOINT: ./backend/schema.graphql + APP_COMMIT_HASH: ${FRONTEND_COMMIT_HASH} command: sh -c 'pnpm generate:type && pnpm build' volumes: - ./data/web-builds/frontend:/code/build @@ -186,6 +187,7 @@ services: APP_ENVIRONMENT: ${WEB_APP_ENVIRONMENT?error} APP_GRAPHQL_ENDPOINT: https://${BACKEND_HOST?error}/graphql/ APP_GRAPHQL_CODEGEN_ENDPOINT: ./backend/schema.graphql + APP_COMMIT_HASH: ${CMS_COMMIT_HASH} command: sh -c 'pnpm generate:type && pnpm build' volumes: - ./data/web-builds/cms:/code/build From 77201637171880ac390ac762445aa374b02f0f94 Mon Sep 17 00:00:00 2001 From: sudip-khanal Date: Thu, 8 Oct 2026 12:16:45 +0545 Subject: [PATCH 4/4] feat(docs): update README --- README.md | 47 +++++++++++++++++++++++++---------------------- 1 file changed, 25 insertions(+), 22 deletions(-) diff --git a/README.md b/README.md index 21594c6..b9d82ea 100644 --- a/README.md +++ b/README.md @@ -1,20 +1,18 @@ # ERCS Deploy -Docker Compose setup for deploying ERCS, including the `backend`, `frontend`, and `cms` applications. The web applications are served through nginx, with Traefik handling the external routing. +Docker Compose setup for deploying ERCS, including the `backend`, `frontend`, and `cms` applications. The web applications are served by nginx, with Traefik handling external routing. ## Setup Before starting the services, initialize the Git submodules and create the required environment files: ```bash -git submodule update --init --recursive +./scripts/sub-module-sync cp .env.sample .env cp env/backend.env.sample env/backend.env - cp env/frontend.env.sample env/frontend.env - cp env/cms.env.sample env/cms.env ``` @@ -24,29 +22,26 @@ Fill in the required values in the environment files before starting the deploym ## Profiles -The Compose setup is divided into profiles: +The Compose setup is divided into two independent profiles: -| Profile | Services | -| ------------ | ------------------------------------------------------------------- | -| `core` | postgres, redis, ollama, web, worker, worker-beat, nginx | -| `web-builds` | frontend, cms (one-shot builds that output to `./data/web-builds/`) | +| Profile | Services | +| ------------ | ------------------------------------------------------------------------- | +| `core` | postgres, redis, ollama, web, worker, worker-beat, nginx | +| `web-builds` | frontend, cms (one-shot builds that output files to `./data/web-builds/`) | +The profiles do not depend on each other and can be run independently. ## Running the Deployment -The two profiles are independent and do not depend on each other. - ### 1. Build the web applications -Run the frontend and CMS builds: +Build the frontend and CMS applications: ```bash -docker compose run --rm --build frontend - -docker compose run --rm --build cms +task web-builds ``` -These commands build the applications and place the generated files under `./data/web-builds/`. +The generated files are placed under `./data/web-builds/` and are served by nginx. ### 2. Start the core services @@ -56,7 +51,15 @@ Once the web applications have been built, start the core services: docker compose --profile core up -d ``` -nginx serves the contents of `./data/web-builds/` directly. Therefore, whenever the frontend or CMS needs to be redeployed, simply repeat step 1 to rebuild the relevant application. +nginx serves the generated files from `./data/web-builds/` directly. + +Whenever the frontend or CMS needs to be redeployed, rebuild the relevant application by running: + +```bash +task web-builds +``` + +There is no need to restart nginx unless its configuration has changed. ## Running Migrations @@ -68,13 +71,13 @@ docker compose exec web ./manage.py migrate ## Creating a Superuser -To create a new superuser: +Create a new Django superuser with: ```bash docker compose exec web ./manage.py createsuperuser ``` -## Loading Seed Data +## Loading Seed Data (Optional) The `seed_data/db.json` fixture contains initial data for ERCS, including: @@ -89,13 +92,13 @@ docker compose exec web ./manage.py loaddata seed_data/db.json > **Note:** The fixture includes a pre-created admin account: `admin@togglecorp.com`. > -> If a superuser with the same email already exists in the database, loading the fixture will fail with a conflict. In that case, either delete the existing user first or skip the user fixture when loading the seed data. +> If a superuser with the same email already exists in the database, loading the fixture may fail due to a conflict. In that case, either delete the existing user first or skip the user fixture when loading the seed data. ## Syncing Geographic Data Administrative areas such as countries, regions, and zones are sourced from the IFRC GO API. -To synchronize the geographic data with the database, run: +To synchronize geographic data with the database, run: ```bash docker compose exec web ./manage.py sync_geo @@ -117,7 +120,7 @@ To synchronize all forms: docker compose exec web ./manage.py sync_kobo ``` -To synchronize only a specific form, for example the Emergency Alert form: +To synchronize a specific form, for example, the Emergency Alert form: ```bash docker compose exec web ./manage.py sync_kobo --form alert