From 64bee207626af7c20cd255f6bf067d1d8e2011a6 Mon Sep 17 00:00:00 2001 From: prayansh_chhablani Date: Sat, 14 Dec 2024 20:42:53 +0530 Subject: [PATCH 01/42] added workflow --- .github/workflows/pull-request.yml | 111 ++++++++++++++++++++++++++++- 1 file changed, 110 insertions(+), 1 deletion(-) diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml index 171970c82e..3934c7d519 100644 --- a/.github/workflows/pull-request.yml +++ b/.github/workflows/pull-request.yml @@ -295,7 +295,116 @@ jobs: with: path: './coverage/lcov.info' min_coverage: 95.0 - + + Docker-Check: + needs: Test-Application + runs-on: ubuntu-latest + steps: + - name: Checkout repository + users: actions/checkout@v4 + + - name: Set up Node.js + - users: actions/setup-node@v4 + with: + node-version: '22.x' + + - name: Cache Node.js dependencies + uses: actions/cache@v4 + with: + path: | + ~/.npm + node_modules + key: ${{ runner.os }}-docker-check-${{ hashFiles('**/package-lock.json') }} + restore-keys: | + ${{ runner.os }}-docker-check- + + - name: Check if Talawa API starts in Docker + run : | + # Ensure no containers are running + docker-compose -f docker-compose.dev.yaml down -v || true + + # Verify docker-compose file exists + if [! -f "docker-compose.dev.yaml"]; then + echo "Error: docker-compose.dev.yaml not found" + exit 1 + fi + + # Start containers + if ! docker-compose -f docker-compose.dev.yaml up -d --build; then + echo "Failed to start containers" + docker-compose -f docker-compose.dev.yaml logs + exit 1 + fi + + # Wait for MongoDB and Redis to be ready + echo "Waiting for MongoDB..." + timeout=30 + until docker-compose -f docker-compose.dev.yaml exec -T mongodb mongo --eval "db.runCommand('ping').ok">/dev/null 2>&1 || [ $timeout -eq 0]; do + sleep 1 + ((timeout--)) + done + if [ $timeout -eq 0 ]; then + echo "Error: MongoDB failed to start within timeout" + docker-compose -f docker-compose.dev.yaml logs mongodb + docker-compose -f docker-compose.dev.yaml down -v + exit 1 + fi + + echo "Waiting for Redis..." + timeout=30 + until docker-compose -f docker-compose.dev.yaml exec -T redis-stack-server redis-cli ping >dev/null 2>&1 || [ $timemout -eq 0]; do + sleep 1 + ((timeout--)) + done + if[ $timeout -eq 0 ]; then + echo "Error: Redis failed to start within timeout" + docker-compose -f docker-compose.dev.yaml logs redis-stack-server + docker-compose -f docker-compose.dev.yaml down -v + exit 1 + fi + + # Wait for TALAWA API to be healthy + timeout=60 + until docker-compose -f docker-compose.dev.yaml exec -T talawa-api-dev curl -sf "http://talawa-api-dev:4000/health" 2>&1 || [ $timeout -eq 0 ]; do + echo "Waiting for API to start... ($timeout seconds remaining)" + sleep 1 + ((timeout--)) + done + + if [ $timeout -eq 0 ]; then + echo "Error: API failed to start within timeout" + docker-compose -f docker-compose.dev.yaml logs + docker-compose -f docker-compose.dev.yaml down -v + exit 1 + fi + + echo "API started successfully" + + # Ensure cleanup runs even if the script fails + cleanup() { + echo "Cleaning up containers..." + if ! docker-compose -f docker-compose.dev.yaml down -v; then + echo "Warning: Failed to cleanup containers" + fi + } + + trap cleanup EXIT + env: + HEALTH_CHECK_URL: http://localhost:4000 + COMPOSE_PROJECT_NAME: pr-${{ github.event.pull_request.number }} + MONGO_DB_URL: mongodb://mongodb:27017/talawa-test-db + REDIS_HOST: redis-stack-server + REDIS_PORT: 6379 + ACCESS_TOKEN_SECRET: ${{ github.event.repository.name }}_access_${{ github.sha }} + REFRESH_TOKEN_SECRET: ${{ github.event.repository.name }}_refresh_${{ github.sha }} + LAST_RESORT_SUPERADMIN_EMAIL: "abc@gmail.com" + COLORIZE_LOGS: "true" + LOG_LEVEL: "info" + RECAPTCHA_SITE_KEY: ${{secrets.RECAPTCHA_SITE_KEY}} + RECAPTCHA_SECRET_KEY: ${{secrets.RECAPTCHA_SECRET_KEY}} + MAIL_USERNAME: ${{secrets.MAIL_USERNAME}} + MAIL_PASSWORD: ${{secrets.MAIL_PASSWORD}} + JSDocs: if: ${{ github.actor != 'dependabot[bot]' }} name: 'JSDocs comments and pipeline' From 6ca61315cdc30e6b7dcec02cad3f485ecaad84e7 Mon Sep 17 00:00:00 2001 From: prayansh_chhablani Date: Sat, 14 Dec 2024 21:43:10 +0530 Subject: [PATCH 02/42] syntax errors --- .github/workflows/pull-request.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml index 3934c7d519..d202ac37e3 100644 --- a/.github/workflows/pull-request.yml +++ b/.github/workflows/pull-request.yml @@ -301,10 +301,10 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout repository - users: actions/checkout@v4 + uses: actions/checkout@v4 - name: Set up Node.js - - users: actions/setup-node@v4 + - uses: actions/setup-node@v4 with: node-version: '22.x' @@ -324,13 +324,13 @@ jobs: docker-compose -f docker-compose.dev.yaml down -v || true # Verify docker-compose file exists - if [! -f "docker-compose.dev.yaml"]; then + if [ ! -f "docker-compose.dev.yaml" ]; then echo "Error: docker-compose.dev.yaml not found" exit 1 fi # Start containers - if ! docker-compose -f docker-compose.dev.yaml up -d --build; then + if ! timeout 300 docker-compose -f docker-compose.dev.yaml up -d --build; then echo "Failed to start containers" docker-compose -f docker-compose.dev.yaml logs exit 1 @@ -352,7 +352,7 @@ jobs: echo "Waiting for Redis..." timeout=30 - until docker-compose -f docker-compose.dev.yaml exec -T redis-stack-server redis-cli ping >dev/null 2>&1 || [ $timemout -eq 0]; do + until docker-compose -f docker-compose.dev.yaml exec -T redis-stack-server redis-cli ping >/dev/null 2>&1 || [ $timeout -eq 0 ]; do sleep 1 ((timeout--)) done From cfec867e18a12074f14a778759280e3a75dabc9e Mon Sep 17 00:00:00 2001 From: prayansh_chhablani Date: Sat, 14 Dec 2024 22:23:09 +0530 Subject: [PATCH 03/42] suggestion-1 --- .github/workflows/pull-request.yml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml index 8d61f71c25..2563874ff4 100644 --- a/.github/workflows/pull-request.yml +++ b/.github/workflows/pull-request.yml @@ -304,7 +304,7 @@ jobs: uses: actions/checkout@v4 - name: Set up Node.js - - uses: actions/setup-node@v4 + uses: actions/setup-node@v4 with: node-version: '22.x' @@ -365,7 +365,7 @@ jobs: # Wait for TALAWA API to be healthy timeout=60 - until docker-compose -f docker-compose.dev.yaml exec -T talawa-api-dev curl -sf "http://talawa-api-dev:4000/health" 2>&1 || [ $timeout -eq 0 ]; do + until docker-compose -f docker-compose.dev.yaml exec -T talawa-api-dev curl -sf "http://localhost:4000/health" 2>&1 || [ $timeout -eq 0 ]; do echo "Waiting for API to start... ($timeout seconds remaining)" sleep 1 ((timeout--)) @@ -382,11 +382,12 @@ jobs: # Ensure cleanup runs even if the script fails cleanup() { + local exit_code=$? echo "Cleaning up containers..." if ! docker-compose -f docker-compose.dev.yaml down -v; then echo "Warning: Failed to cleanup containers" fi - } + exit $exit_code } trap cleanup EXIT env: From 15445021b0079c6578f9224cfb94648c55cab7d8 Mon Sep 17 00:00:00 2001 From: prayansh_chhablani Date: Sat, 14 Dec 2024 23:29:12 +0530 Subject: [PATCH 04/42] indentation 1 --- .github/workflows/pull-request.yml | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml index 2563874ff4..597e66a8ae 100644 --- a/.github/workflows/pull-request.yml +++ b/.github/workflows/pull-request.yml @@ -320,7 +320,7 @@ jobs: - name: Check if Talawa API starts in Docker run : | - # Ensure no containers are running + # Ensure no containers are running docker-compose -f docker-compose.dev.yaml down -v || true # Verify docker-compose file exists @@ -339,7 +339,7 @@ jobs: # Wait for MongoDB and Redis to be ready echo "Waiting for MongoDB..." timeout=30 - until docker-compose -f docker-compose.dev.yaml exec -T mongodb mongo --eval "db.runCommand('ping').ok">/dev/null 2>&1 || [ $timeout -eq 0]; do + until docker-compose -f docker-compose.dev.yaml exec -T mongodb mongo --eval "db.runCommand('ping').ok">/dev/null 2>&1 || [ $timeout -eq 0 ]; do sleep 1 ((timeout--)) done @@ -366,19 +366,19 @@ jobs: # Wait for TALAWA API to be healthy timeout=60 until docker-compose -f docker-compose.dev.yaml exec -T talawa-api-dev curl -sf "http://localhost:4000/health" 2>&1 || [ $timeout -eq 0 ]; do - echo "Waiting for API to start... ($timeout seconds remaining)" - sleep 1 - ((timeout--)) - done + echo "Waiting for API to start... ($timeout seconds remaining)" + sleep 1 + ((timeout--)) + done - if [ $timeout -eq 0 ]; then - echo "Error: API failed to start within timeout" - docker-compose -f docker-compose.dev.yaml logs - docker-compose -f docker-compose.dev.yaml down -v - exit 1 - fi + if [ $timeout -eq 0 ]; then + echo "Error: API failed to start within timeout" + docker-compose -f docker-compose.dev.yaml logs + docker-compose -f docker-compose.dev.yaml down -v + exit 1 + fi - echo "API started successfully" + echo "API started successfully" # Ensure cleanup runs even if the script fails cleanup() { @@ -387,7 +387,8 @@ jobs: if ! docker-compose -f docker-compose.dev.yaml down -v; then echo "Warning: Failed to cleanup containers" fi - exit $exit_code } + exit $exit_code + } trap cleanup EXIT env: From 0b6ef08b0878a04c6d6d4ea9fae1f547930ebfee Mon Sep 17 00:00:00 2001 From: prayansh_chhablani Date: Sun, 15 Dec 2024 00:43:59 +0530 Subject: [PATCH 05/42] indentation 2 --- .github/workflows/pull-request.yml | 84 +++++++++++++++--------------- 1 file changed, 42 insertions(+), 42 deletions(-) diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml index 597e66a8ae..f683432f78 100644 --- a/.github/workflows/pull-request.yml +++ b/.github/workflows/pull-request.yml @@ -319,13 +319,14 @@ jobs: ${{ runner.os }}-docker-check- - name: Check if Talawa API starts in Docker - run : | + run: | # Ensure no containers are running docker-compose -f docker-compose.dev.yaml down -v || true # Verify docker-compose file exists - if [ ! -f "docker-compose.dev.yaml" ]; then + if [ ! -f "docker-compose.dev.yaml" ]; then echo "Error: docker-compose.dev.yaml not found" + docker-compose -f docker-compose.dev.yaml logs exit 1 fi @@ -341,7 +342,7 @@ jobs: timeout=30 until docker-compose -f docker-compose.dev.yaml exec -T mongodb mongo --eval "db.runCommand('ping').ok">/dev/null 2>&1 || [ $timeout -eq 0 ]; do sleep 1 - ((timeout--)) + ((timeout--)) done if [ $timeout -eq 0 ]; then echo "Error: MongoDB failed to start within timeout" @@ -351,27 +352,27 @@ jobs: fi echo "Waiting for Redis..." - timeout=30 - until docker-compose -f docker-compose.dev.yaml exec -T redis-stack-server redis-cli ping >/dev/null 2>&1 || [ $timeout -eq 0 ]; do + timeout=30 + until docker-compose -f docker-compose.dev.yaml exec -T redis-stack-server redis-cli ping >/dev/null 2>&1 || [ $timeout -eq 0 ]; do sleep 1 ((timeout--)) done if[ $timeout -eq 0 ]; then - echo "Error: Redis failed to start within timeout" + echo "Error: Redis failed to start within timeout" docker-compose -f docker-compose.dev.yaml logs redis-stack-server - docker-compose -f docker-compose.dev.yaml down -v - exit 1 - fi + docker-compose -f docker-compose.dev.yaml down -v + exit 1 + fi - # Wait for TALAWA API to be healthy - timeout=60 + # Wait for TALAWA API to be healthy + timeout=60 until docker-compose -f docker-compose.dev.yaml exec -T talawa-api-dev curl -sf "http://localhost:4000/health" 2>&1 || [ $timeout -eq 0 ]; do - echo "Waiting for API to start... ($timeout seconds remaining)" - sleep 1 - ((timeout--)) - done + echo "Waiting for API to start... ($timeout seconds remaining)" + sleep 1 + ((timeout--)) + done - if [ $timeout -eq 0 ]; then + if [ $timeout -eq 0 ]; then echo "Error: API failed to start within timeout" docker-compose -f docker-compose.dev.yaml logs docker-compose -f docker-compose.dev.yaml down -v @@ -380,32 +381,31 @@ jobs: echo "API started successfully" - # Ensure cleanup runs even if the script fails - cleanup() { - local exit_code=$? - echo "Cleaning up containers..." - if ! docker-compose -f docker-compose.dev.yaml down -v; then - echo "Warning: Failed to cleanup containers" - fi - exit $exit_code - } - - trap cleanup EXIT - env: - HEALTH_CHECK_URL: http://localhost:4000 - COMPOSE_PROJECT_NAME: pr-${{ github.event.pull_request.number }} - MONGO_DB_URL: mongodb://mongodb:27017/talawa-test-db - REDIS_HOST: redis-stack-server - REDIS_PORT: 6379 - ACCESS_TOKEN_SECRET: ${{ github.event.repository.name }}_access_${{ github.sha }} - REFRESH_TOKEN_SECRET: ${{ github.event.repository.name }}_refresh_${{ github.sha }} - LAST_RESORT_SUPERADMIN_EMAIL: "abc@gmail.com" - COLORIZE_LOGS: "true" - LOG_LEVEL: "info" - RECAPTCHA_SITE_KEY: ${{secrets.RECAPTCHA_SITE_KEY}} - RECAPTCHA_SECRET_KEY: ${{secrets.RECAPTCHA_SECRET_KEY}} - MAIL_USERNAME: ${{secrets.MAIL_USERNAME}} - MAIL_PASSWORD: ${{secrets.MAIL_PASSWORD}} + # Ensure cleanup runs even if the script fails + cleanup() { + local exit_code=$? + echo "Cleaning up containers..." + if ! docker-compose -f docker-compose.dev.yaml down -v; then + echo "Warning: Failed to cleanup containers" + fi + exit $exit_code + } + trap cleanup EXIT + env: + HEALTH_CHECK_URL: http://localhost:4000 + COMPOSE_PROJECT_NAME: pr-${{ github.event.pull_request.number }} + MONGO_DB_URL: mongodb://mongodb:27017/talawa-test-db + REDIS_HOST: redis-stack-server + REDIS_PORT: 6379 + ACCESS_TOKEN_SECRET: ${{ secrets.GITHUB_TOKEN }}_${{ github.run_id }}_${{ github.run_number }} + REFRESH_TOKEN_SECRET: ${{ secrets.GITHUB_TOKEN }}_${{ github.run_id }}_${{ github.run_attempt }} + LAST_RESORT_SUPERADMIN_EMAIL: "abc@gmail.com" + COLORIZE_LOGS: "true" + LOG_LEVEL: "info" + RECAPTCHA_SITE_KEY: ${{secrets.RECAPTCHA_SITE_KEY}} + RECAPTCHA_SECRET_KEY: ${{secrets.RECAPTCHA_SECRET_KEY}} + MAIL_USERNAME: ${{secrets.MAIL_USERNAME}} + MAIL_PASSWORD: ${{secrets.MAIL_PASSWORD}} JSDocs: if: ${{ github.actor != 'dependabot[bot]' }} From 4adec1ffb2f5fbba5bc1e2f1a2bcd5852444c2b4 Mon Sep 17 00:00:00 2001 From: prayansh_chhablani Date: Thu, 19 Dec 2024 09:36:26 +0530 Subject: [PATCH 06/42] removing unions file --- src/typeDefs/unions.ts | 4 ---- 1 file changed, 4 deletions(-) delete mode 100644 src/typeDefs/unions.ts diff --git a/src/typeDefs/unions.ts b/src/typeDefs/unions.ts deleted file mode 100644 index d9c6501960..0000000000 --- a/src/typeDefs/unions.ts +++ /dev/null @@ -1,4 +0,0 @@ -import { gql } from "graphql-tag"; - -// Place fields alphabetically to ensure easier lookup and navigation. -export const unions = gql``; From 338a7b8b4d16608f6222ca55455c81998ba145e0 Mon Sep 17 00:00:00 2001 From: prayansh_chhablani Date: Sat, 21 Dec 2024 16:44:52 +0530 Subject: [PATCH 07/42] fixing tests --- src/typeDefs/unions.ts | 4 ++++ tests/resolvers/Query/getVolunteerRanks.spec.ts | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) create mode 100644 src/typeDefs/unions.ts diff --git a/src/typeDefs/unions.ts b/src/typeDefs/unions.ts new file mode 100644 index 0000000000..29e719ad06 --- /dev/null +++ b/src/typeDefs/unions.ts @@ -0,0 +1,4 @@ +// import { gql } from "graphql-tag"; + +// // Place fields alphabetically to ensure easier lookup and navigation. +// export const unions = gql``; diff --git a/tests/resolvers/Query/getVolunteerRanks.spec.ts b/tests/resolvers/Query/getVolunteerRanks.spec.ts index 0f5d6973d5..ab799f7f7c 100644 --- a/tests/resolvers/Query/getVolunteerRanks.spec.ts +++ b/tests/resolvers/Query/getVolunteerRanks.spec.ts @@ -76,7 +76,7 @@ describe("resolvers -> Query -> getVolunteerRanks", () => { }, {}, )) as unknown as VolunteerRank[]; - expect(volunteerRanks[0].hoursVolunteered).toEqual(2); + expect(volunteerRanks[0].hoursVolunteered).toEqual(6); expect(volunteerRanks[0].user._id).toEqual(testUser1?._id); expect(volunteerRanks[0].rank).toEqual(1); }); From d540981d2d6c82307c8889ec1ea23863e283a6c9 Mon Sep 17 00:00:00 2001 From: prayansh_chhablani Date: Sun, 22 Dec 2024 01:43:32 +0530 Subject: [PATCH 08/42] docker-compose issue --- .github/workflows/pull-request.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml index f683432f78..b767779c34 100644 --- a/.github/workflows/pull-request.yml +++ b/.github/workflows/pull-request.yml @@ -318,6 +318,11 @@ jobs: restore-keys: | ${{ runner.os }}-docker-check- + - name: Install Docker Compose + run: | + sudo apt-get update + sudo apt-get install -y docker-compose + - name: Check if Talawa API starts in Docker run: | # Ensure no containers are running From c942e2c3a810af5b37b36f18ded544d20fff0b35 Mon Sep 17 00:00:00 2001 From: prayansh_chhablani Date: Sun, 22 Dec 2024 09:14:27 +0530 Subject: [PATCH 09/42] increasing timeout --- .github/workflows/pull-request.yml | 38 +++++++++++++++++------------- 1 file changed, 22 insertions(+), 16 deletions(-) diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml index b767779c34..a8a696eb32 100644 --- a/.github/workflows/pull-request.yml +++ b/.github/workflows/pull-request.yml @@ -344,18 +344,24 @@ jobs: # Wait for MongoDB and Redis to be ready echo "Waiting for MongoDB..." - timeout=30 + timeout=120 until docker-compose -f docker-compose.dev.yaml exec -T mongodb mongo --eval "db.runCommand('ping').ok">/dev/null 2>&1 || [ $timeout -eq 0 ]; do sleep 1 ((timeout--)) done if [ $timeout -eq 0 ]; then echo "Error: MongoDB failed to start within timeout" + echo "Fetching MongoDB logs..." docker-compose -f docker-compose.dev.yaml logs mongodb + echo "Shutting down services..." docker-compose -f docker-compose.dev.yaml down -v exit 1 fi + else + echo "MongoDB is ready!" + fi + echo "Waiting for Redis..." timeout=30 until docker-compose -f docker-compose.dev.yaml exec -T redis-stack-server redis-cli ping >/dev/null 2>&1 || [ $timeout -eq 0 ]; do @@ -394,23 +400,23 @@ jobs: echo "Warning: Failed to cleanup containers" fi exit $exit_code - } + } trap cleanup EXIT env: - HEALTH_CHECK_URL: http://localhost:4000 - COMPOSE_PROJECT_NAME: pr-${{ github.event.pull_request.number }} - MONGO_DB_URL: mongodb://mongodb:27017/talawa-test-db - REDIS_HOST: redis-stack-server - REDIS_PORT: 6379 - ACCESS_TOKEN_SECRET: ${{ secrets.GITHUB_TOKEN }}_${{ github.run_id }}_${{ github.run_number }} - REFRESH_TOKEN_SECRET: ${{ secrets.GITHUB_TOKEN }}_${{ github.run_id }}_${{ github.run_attempt }} - LAST_RESORT_SUPERADMIN_EMAIL: "abc@gmail.com" - COLORIZE_LOGS: "true" - LOG_LEVEL: "info" - RECAPTCHA_SITE_KEY: ${{secrets.RECAPTCHA_SITE_KEY}} - RECAPTCHA_SECRET_KEY: ${{secrets.RECAPTCHA_SECRET_KEY}} - MAIL_USERNAME: ${{secrets.MAIL_USERNAME}} - MAIL_PASSWORD: ${{secrets.MAIL_PASSWORD}} + HEALTH_CHECK_URL: http://localhost:4000 + COMPOSE_PROJECT_NAME: pr-${{ github.event.pull_request.number }} + MONGO_DB_URL: mongodb://mongodb:27017/talawa-test-db + REDIS_HOST: redis-stack-server + REDIS_PORT: 6379 + ACCESS_TOKEN_SECRET: ${{ secrets.GITHUB_TOKEN }}_${{ github.run_id }}_${{ github.run_number }} + REFRESH_TOKEN_SECRET: ${{ secrets.GITHUB_TOKEN }}_${{ github.run_id }}_${{ github.run_attempt }} + LAST_RESORT_SUPERADMIN_EMAIL: "abc@gmail.com" + COLORIZE_LOGS: "true" + LOG_LEVEL: "info" + RECAPTCHA_SITE_KEY: ${{secrets.RECAPTCHA_SITE_KEY}} + RECAPTCHA_SECRET_KEY: ${{secrets.RECAPTCHA_SECRET_KEY}} + MAIL_USERNAME: ${{secrets.MAIL_USERNAME}} + MAIL_PASSWORD: ${{secrets.MAIL_PASSWORD}} JSDocs: if: ${{ github.actor != 'dependabot[bot]' }} From fbbb7ea05cfc1775b7b165c6145e50803e23a46c Mon Sep 17 00:00:00 2001 From: prayansh_chhablani Date: Sun, 22 Dec 2024 13:49:40 +0530 Subject: [PATCH 10/42] test fix --- tests/helpers/volunteers.ts | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/tests/helpers/volunteers.ts b/tests/helpers/volunteers.ts index 026dc4313a..ada916a6a3 100644 --- a/tests/helpers/volunteers.ts +++ b/tests/helpers/volunteers.ts @@ -138,8 +138,6 @@ export const createVolunteerAndActions = async (): Promise< }); const today = new Date(); - const yesterday = new Date(today); - yesterday.setDate(today.getDate() - 1); const twoWeeksAgo = new Date(today); twoWeeksAgo.setDate(today.getDate() - 14); const twoMonthsAgo = new Date(today); @@ -158,7 +156,7 @@ export const createVolunteerAndActions = async (): Promise< hoursHistory: [ { hours: 2, - date: yesterday, + date: today, }, { hours: 4, @@ -186,7 +184,7 @@ export const createVolunteerAndActions = async (): Promise< hoursHistory: [ { hours: 1, - date: yesterday, + date: today, }, { hours: 2, From 798b4f70746d2e6c55b16496202d44c35dfdb760 Mon Sep 17 00:00:00 2001 From: prayansh_chhablani Date: Sun, 22 Dec 2024 16:56:51 +0530 Subject: [PATCH 11/42] using mongosh --- .github/workflows/pull-request.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml index a8a696eb32..74df20399e 100644 --- a/.github/workflows/pull-request.yml +++ b/.github/workflows/pull-request.yml @@ -344,8 +344,9 @@ jobs: # Wait for MongoDB and Redis to be ready echo "Waiting for MongoDB..." - timeout=120 - until docker-compose -f docker-compose.dev.yaml exec -T mongodb mongo --eval "db.runCommand('ping').ok">/dev/null 2>&1 || [ $timeout -eq 0 ]; do + timeout=30 + until docker-compose -f docker-compose.dev.yaml exec -T mongodb mongosh --eval "db.runCommand({ ping: 1 }).ok">/dev/null 2>&1 || [ $timeout -eq 0 ]; do + echo "Waiting for MongoDB to be ready..." sleep 1 ((timeout--)) done @@ -356,7 +357,6 @@ jobs: echo "Shutting down services..." docker-compose -f docker-compose.dev.yaml down -v exit 1 - fi else echo "MongoDB is ready!" From 05f9c9790f694fb3a5f98f39f61228ae8fa8e5ed Mon Sep 17 00:00:00 2001 From: prayansh_chhablani Date: Sun, 22 Dec 2024 17:16:47 +0530 Subject: [PATCH 12/42] idenation fix --- .github/workflows/pull-request.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml index 74df20399e..40a9166aec 100644 --- a/.github/workflows/pull-request.yml +++ b/.github/workflows/pull-request.yml @@ -368,7 +368,7 @@ jobs: sleep 1 ((timeout--)) done - if[ $timeout -eq 0 ]; then + if [ $timeout -eq 0 ]; then echo "Error: Redis failed to start within timeout" docker-compose -f docker-compose.dev.yaml logs redis-stack-server docker-compose -f docker-compose.dev.yaml down -v From 006092e171a8e7f72d1f57e7df974fa327050dda Mon Sep 17 00:00:00 2001 From: prayansh_chhablani Date: Mon, 23 Dec 2024 22:42:29 +0530 Subject: [PATCH 13/42] pwd variable fix, redi-stack-server fix --- .env.sample | 5 ++++- .github/workflows/pull-request.yml | 9 +++++++-- docker-compose.dev.yaml | 26 +++++++------------------- setup.ts | 11 +++++++++++ 4 files changed, 29 insertions(+), 22 deletions(-) diff --git a/.env.sample b/.env.sample index fa6a0fabaa..073cf6b0c2 100644 --- a/.env.sample +++ b/.env.sample @@ -104,4 +104,7 @@ MINIO_DATA_DIR= # this environment variable is for setting the environment variable for Image Upload size -IMAGE_SIZE_LIMIT_KB=3000 \ No newline at end of file +IMAGE_SIZE_LIMIT_KB=3000 + +# This environment variable is for setting the working directory when Docker is used +PWD=. \ No newline at end of file diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml index 40a9166aec..a72db56825 100644 --- a/.github/workflows/pull-request.yml +++ b/.github/workflows/pull-request.yml @@ -354,7 +354,7 @@ jobs: echo "Error: MongoDB failed to start within timeout" echo "Fetching MongoDB logs..." docker-compose -f docker-compose.dev.yaml logs mongodb - echo "Shutting down services..." + echo "Shutting down MongoDB..." docker-compose -f docker-compose.dev.yaml down -v exit 1 @@ -370,10 +370,15 @@ jobs: done if [ $timeout -eq 0 ]; then echo "Error: Redis failed to start within timeout" + echo "Fetching Redis logs..." docker-compose -f docker-compose.dev.yaml logs redis-stack-server + echo "Shutting down Redis..." docker-compose -f docker-compose.dev.yaml down -v exit 1 - fi + + else + echo "Redis is ready!" + fi # Wait for TALAWA API to be healthy timeout=60 diff --git a/docker-compose.dev.yaml b/docker-compose.dev.yaml index 12907723b7..99086d1f9d 100644 --- a/docker-compose.dev.yaml +++ b/docker-compose.dev.yaml @@ -1,5 +1,3 @@ -version: "3.8" - services: mongodb: image: mongo:latest @@ -37,6 +35,9 @@ services: build: context: . dockerfile: Dockerfile.dev + container_name: talawa-api-dev + ports: + - "4000:4000" volumes: - .:/usr/src/app - /usr/src/app/node_modules @@ -45,30 +46,17 @@ services: - redis-stack-server - minio environment: - - MONGO_DB_URL=mongodb://mongodb:27017 + - MONGO_DB_URL=mongodb://mongodb:27017/talawa-api - REDIS_HOST=redis-stack-server - REDIS_PORT=6379 - - caddy: - image: caddy/caddy:2.2.1-alpine - container_name: caddy-service - restart: unless-stopped - ports: - - "80:80" - - "443:443" - volumes: - - ./Caddyfile:/etc/caddy/Caddyfile - - $PWD/site:/srv - - caddy_data:/data - - caddy_config:/config + networks: + - talawa-network volumes: mongodb-data: redis-data: - caddy_data: - caddy_config: minio-data: networks: talawa-network: - driver: bridge + driver: bridge \ No newline at end of file diff --git a/setup.ts b/setup.ts index bad4b347bd..4e1a689055 100644 --- a/setup.ts +++ b/setup.ts @@ -1015,6 +1015,14 @@ async function main(): Promise { const REDIS_PASSWORD = ""; const MINIO_ENDPOINT = "http://minio:9000"; + const { pwdVariable } = await inquirer.prompt({ + type: "input", + name: "pwdVariable", + message: + "Please enter the value for PWD (working directory for Docker setup):", + default: ".", + }); + const config = dotenv.parse(fs.readFileSync(".env")); config.MONGO_DB_URL = DB_URL; @@ -1022,18 +1030,21 @@ async function main(): Promise { config.REDIS_PORT = REDIS_PORT; config.REDIS_PASSWORD = REDIS_PASSWORD; config.MINIO_ENDPOINT = MINIO_ENDPOINT; + config.PWD = pwdVariable; process.env.MONGO_DB_URL = DB_URL; process.env.REDIS_HOST = REDIS_HOST; process.env.REDIS_PORT = REDIS_PORT; process.env.REDIS_PASSWORD = REDIS_PASSWORD; process.env.MINIO_ENDPOINT = MINIO_ENDPOINT; + process.env.PWD = pwdVariable; updateEnvVariable(config); console.log(`Your MongoDB URL is:\n${process.env.MONGO_DB_URL}`); console.log(`Your Redis host is:\n${process.env.REDIS_HOST}`); console.log(`Your Redis port is:\n${process.env.REDIS_PORT}`); console.log(`Your MinIO endpoint is:\n${process.env.MINIO_ENDPOINT}`); + console.log(`Your PWD value is:\n${process.env.PWD}`); } if (!isDockerInstallation) { From 1c57fbaff478673e63353eee30270db1693e9070 Mon Sep 17 00:00:00 2001 From: prayansh_chhablani Date: Mon, 23 Dec 2024 23:00:30 +0530 Subject: [PATCH 14/42] health-check-api --- .github/workflows/pull-request.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml index a72db56825..b376ea3ac7 100644 --- a/.github/workflows/pull-request.yml +++ b/.github/workflows/pull-request.yml @@ -382,7 +382,7 @@ jobs: # Wait for TALAWA API to be healthy timeout=60 - until docker-compose -f docker-compose.dev.yaml exec -T talawa-api-dev curl -sf "http://localhost:4000/health" 2>&1 || [ $timeout -eq 0 ]; do + until docker-compose -f docker-compose.dev.yaml exec -T talawa-api-dev curl -sf "http://localhost:4000/graphql" 2>&1 || [ $timeout -eq 0 ]; do echo "Waiting for API to start... ($timeout seconds remaining)" sleep 1 ((timeout--)) From 08c8d163f4ef84073f7c51e2f02bd61191e18d9c Mon Sep 17 00:00:00 2001 From: prayansh_chhablani Date: Tue, 24 Dec 2024 00:17:40 +0530 Subject: [PATCH 15/42] api fix --- .github/workflows/pull-request.yml | 2 +- Accept: | 0 GET | 0 Host: | 0 User-Agent: | 0 5 files changed, 1 insertion(+), 1 deletion(-) create mode 100644 Accept: create mode 100644 GET create mode 100644 Host: create mode 100644 User-Agent: diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml index b376ea3ac7..1fac810783 100644 --- a/.github/workflows/pull-request.yml +++ b/.github/workflows/pull-request.yml @@ -382,7 +382,7 @@ jobs: # Wait for TALAWA API to be healthy timeout=60 - until docker-compose -f docker-compose.dev.yaml exec -T talawa-api-dev curl -sf "http://localhost:4000/graphql" 2>&1 || [ $timeout -eq 0 ]; do + until docker-compose -f docker-compose.dev.yaml exec -T talawa-api-dev curl -v -X OPTIONS "http://talawa-api-dev:4000/graphql" 2>&1 || [ $timeout -eq 0 ]; do echo "Waiting for API to start... ($timeout seconds remaining)" sleep 1 ((timeout--)) diff --git a/Accept: b/Accept: new file mode 100644 index 0000000000..e69de29bb2 diff --git a/GET b/GET new file mode 100644 index 0000000000..e69de29bb2 diff --git a/Host: b/Host: new file mode 100644 index 0000000000..e69de29bb2 diff --git a/User-Agent: b/User-Agent: new file mode 100644 index 0000000000..e69de29bb2 From a228c0736fa8ba444dd2e933877de3f2e305c109 Mon Sep 17 00:00:00 2001 From: prayansh_chhablani Date: Tue, 24 Dec 2024 00:23:19 +0530 Subject: [PATCH 16/42] removing unnecessary files --- Accept: | 0 GET | 0 Host: | 0 User-Agent: | 0 4 files changed, 0 insertions(+), 0 deletions(-) delete mode 100644 Accept: delete mode 100644 GET delete mode 100644 Host: delete mode 100644 User-Agent: diff --git a/Accept: b/Accept: deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/GET b/GET deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/Host: b/Host: deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/User-Agent: b/User-Agent: deleted file mode 100644 index e69de29bb2..0000000000 From 67baf1bba2fd6ea89a906efc459ea190e3868767 Mon Sep 17 00:00:00 2001 From: prayansh_chhablani Date: Fri, 27 Dec 2024 16:00:46 +0530 Subject: [PATCH 17/42] fixing replic-set issues --- Dockerfile.mongo | 32 ++++++++++++++++++++++++++++++++ docker-compose.dev.yaml | 30 ++++++++++++++++++------------ init-replica.sh | 20 ++++++++++++++++++++ 3 files changed, 70 insertions(+), 12 deletions(-) create mode 100644 Dockerfile.mongo create mode 100644 init-replica.sh diff --git a/Dockerfile.mongo b/Dockerfile.mongo new file mode 100644 index 0000000000..4d766bd846 --- /dev/null +++ b/Dockerfile.mongo @@ -0,0 +1,32 @@ +# Use official MongoDB base image +FROM mongo:latest + +# Update system packages and install prerequisites +RUN apt-get update && apt-get install -y \ + gnupg \ + curl \ + sudo \ + && rm -rf /var/lib/apt/lists/* + +# Import the MongoDB public GPG key +RUN curl -fsSL https://www.mongodb.org/static/pgp/server-8.0.asc | \ + sudo gpg -o /usr/share/keyrings/mongodb-server-8.0.gpg --dearmor + +# Create the MongoDB list file +RUN echo "deb [ arch=amd64,arm64 signed-by=/usr/share/keyrings/mongodb-server-8.0.gpg ] https://repo.mongodb.org/apt/ubuntu noble/mongodb-org/8.0 multiverse" | \ + sudo tee /etc/apt/sources.list.d/mongodb-org-8.0.list + +# Reload the package database and install MongoDB +RUN apt-get update && apt-get install -y mongodb-org && rm -rf /var/lib/apt/lists/* + +# Create MongoDB data directory +RUN mkdir -p /var/lib/mongodb && chown -R mongodb:mongodb /var/lib/mongodb + +COPY init-replica.sh /docker-entrypoint-initdb.d/ +RUN chmod +x /docker-entrypoint-initdb.d/init-replica.sh + +# Expose MongoDB port +EXPOSE 27017 + +# Command to run MongoDB with the replica set (run as root with sudo) +CMD ["/docker-entrypoint-initdb.d/init-replica.sh"] diff --git a/docker-compose.dev.yaml b/docker-compose.dev.yaml index 99086d1f9d..df0e2c06b7 100644 --- a/docker-compose.dev.yaml +++ b/docker-compose.dev.yaml @@ -1,13 +1,15 @@ services: - mongodb: - image: mongo:latest + mongo: + build: + context: . + dockerfile: Dockerfile.mongo + container_name: mongo ports: - - 27017:27017 + - "27017:27017" volumes: - - mongodb-data:/data/db + - mongo_data:/var/lib/mongodb networks: - talawa-network - redis-stack-server: image: redis/redis-stack-server:latest ports: @@ -22,7 +24,7 @@ services: ports: - "9000:9000" - "9001:9001" - environment: + environment: - MINIO_ROOT_USER=${MINIO_ROOT_USER} - MINIO_ROOT_PASSWORD=${MINIO_ROOT_PASSWORD} command: server /data --console-address ":9001" @@ -42,21 +44,25 @@ services: - .:/usr/src/app - /usr/src/app/node_modules depends_on: - - mongodb - - redis-stack-server - - minio + mongo: + condition: service_started + redis-stack-server: + condition: service_started + minio: + condition: service_started environment: - - MONGO_DB_URL=mongodb://mongodb:27017/talawa-api + - MONGO_DB_URL=mongodb://mongo:27017?replicaSet=rs0 - REDIS_HOST=redis-stack-server - REDIS_PORT=6379 networks: - talawa-network + volumes: - mongodb-data: redis-data: minio-data: + mongo_data: networks: talawa-network: - driver: bridge \ No newline at end of file + driver: bridge diff --git a/init-replica.sh b/init-replica.sh new file mode 100644 index 0000000000..01c7f8ee7f --- /dev/null +++ b/init-replica.sh @@ -0,0 +1,20 @@ +#!/bin/bash +# init-replicaset.sh + +mongod --replSet rs0 --dbpath /var/lib/mongodb --bind_ip_all & + +# Wait for MongoDB to start +sleep 10 + +# Initialize the replica set +mongosh --eval ' + rs.initiate({ + _id: "rs0", + members: [ + { _id: 0, host: "mongo:27017" } + ] + }) +' + +# Keep container running +tail -f /dev/null \ No newline at end of file From a22e41dad96e0745cb4b2a06f27dc992cc86469f Mon Sep 17 00:00:00 2001 From: prayansh_chhablani Date: Fri, 27 Dec 2024 16:34:18 +0530 Subject: [PATCH 18/42] fixing workflow --- .github/workflows/pull-request.yml | 1 - Dockerfile.mongo | 8 -------- 2 files changed, 9 deletions(-) diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml index 358aaa14e2..6c2cc3b076 100644 --- a/.github/workflows/pull-request.yml +++ b/.github/workflows/pull-request.yml @@ -399,7 +399,6 @@ jobs: RECAPTCHA_SECRET_KEY: ${{secrets.RECAPTCHA_SECRET_KEY}} MAIL_USERNAME: ${{secrets.MAIL_USERNAME}} MAIL_PASSWORD: ${{secrets.MAIL_PASSWORD}} -======= Test-Builds: name: Test Development and Production Builds diff --git a/Dockerfile.mongo b/Dockerfile.mongo index 4d766bd846..2724e2dc97 100644 --- a/Dockerfile.mongo +++ b/Dockerfile.mongo @@ -1,32 +1,24 @@ -# Use official MongoDB base image FROM mongo:latest -# Update system packages and install prerequisites RUN apt-get update && apt-get install -y \ gnupg \ curl \ sudo \ && rm -rf /var/lib/apt/lists/* -# Import the MongoDB public GPG key RUN curl -fsSL https://www.mongodb.org/static/pgp/server-8.0.asc | \ sudo gpg -o /usr/share/keyrings/mongodb-server-8.0.gpg --dearmor -# Create the MongoDB list file RUN echo "deb [ arch=amd64,arm64 signed-by=/usr/share/keyrings/mongodb-server-8.0.gpg ] https://repo.mongodb.org/apt/ubuntu noble/mongodb-org/8.0 multiverse" | \ sudo tee /etc/apt/sources.list.d/mongodb-org-8.0.list -# Reload the package database and install MongoDB RUN apt-get update && apt-get install -y mongodb-org && rm -rf /var/lib/apt/lists/* -# Create MongoDB data directory RUN mkdir -p /var/lib/mongodb && chown -R mongodb:mongodb /var/lib/mongodb COPY init-replica.sh /docker-entrypoint-initdb.d/ RUN chmod +x /docker-entrypoint-initdb.d/init-replica.sh -# Expose MongoDB port EXPOSE 27017 -# Command to run MongoDB with the replica set (run as root with sudo) CMD ["/docker-entrypoint-initdb.d/init-replica.sh"] From e455a7c39278877a726237a0687725f65df17cde Mon Sep 17 00:00:00 2001 From: prayansh_chhablani Date: Fri, 27 Dec 2024 17:30:12 +0530 Subject: [PATCH 19/42] identation --- .github/workflows/pull-request.yml | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml index 6c2cc3b076..f2aa6cd569 100644 --- a/.github/workflows/pull-request.yml +++ b/.github/workflows/pull-request.yml @@ -323,9 +323,9 @@ jobs: echo "Waiting for MongoDB..." timeout=30 until docker-compose -f docker-compose.dev.yaml exec -T mongodb mongosh --eval "db.runCommand({ ping: 1 }).ok">/dev/null 2>&1 || [ $timeout -eq 0 ]; do - echo "Waiting for MongoDB to be ready..." - sleep 1 - ((timeout--)) + echo "Waiting for MongoDB to be ready..." + sleep 1 + ((timeout--)) done if [ $timeout -eq 0 ]; then echo "Error: MongoDB failed to start within timeout" @@ -340,18 +340,18 @@ jobs: fi echo "Waiting for Redis..." - timeout=30 - until docker-compose -f docker-compose.dev.yaml exec -T redis-stack-server redis-cli ping >/dev/null 2>&1 || [ $timeout -eq 0 ]; do - sleep 1 - ((timeout--)) + timeout=30 + until docker-compose -f docker-compose.dev.yaml exec -T redis-stack-server redis-cli ping >/dev/null 2>&1 || [ $timeout -eq 0 ]; do + sleep 1 + ((timeout--)) done if [ $timeout -eq 0 ]; then - echo "Error: Redis failed to start within timeout" - echo "Fetching Redis logs..." + echo "Error: Redis failed to start within timeout" + echo "Fetching Redis logs..." docker-compose -f docker-compose.dev.yaml logs redis-stack-server echo "Shutting down Redis..." - docker-compose -f docker-compose.dev.yaml down -v - exit 1 + docker-compose -f docker-compose.dev.yaml down -v + exit 1 else echo "Redis is ready!" From 01e8d37d9e8fd21d6268e69516d9241e537be6ec Mon Sep 17 00:00:00 2001 From: prayansh_chhablani Date: Fri, 27 Dec 2024 17:50:38 +0530 Subject: [PATCH 20/42] indentaion fix --- .github/workflows/pull-request.yml | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml index f2aa6cd569..c04a337fb6 100644 --- a/.github/workflows/pull-request.yml +++ b/.github/workflows/pull-request.yml @@ -274,8 +274,10 @@ jobs: min_coverage: 95.0 Docker-Check: + name: Docker Check needs: Test-Application runs-on: ubuntu-latest + steps: - name: Checkout repository uses: actions/checkout@v4 @@ -334,7 +336,6 @@ jobs: echo "Shutting down MongoDB..." docker-compose -f docker-compose.dev.yaml down -v exit 1 - else echo "MongoDB is ready!" fi @@ -351,28 +352,27 @@ jobs: docker-compose -f docker-compose.dev.yaml logs redis-stack-server echo "Shutting down Redis..." docker-compose -f docker-compose.dev.yaml down -v - exit 1 - + exit 1 else echo "Redis is ready!" fi - # Wait for TALAWA API to be healthy - timeout=60 + # Wait for TALAWA API to be healthy + timeout=60 until docker-compose -f docker-compose.dev.yaml exec -T talawa-api-dev curl -v -X OPTIONS "http://talawa-api-dev:4000/graphql" 2>&1 || [ $timeout -eq 0 ]; do echo "Waiting for API to start... ($timeout seconds remaining)" sleep 1 ((timeout--)) - done + done - if [ $timeout -eq 0 ]; then - echo "Error: API failed to start within timeout" - docker-compose -f docker-compose.dev.yaml logs - docker-compose -f docker-compose.dev.yaml down -v - exit 1 - fi + if [ $timeout -eq 0 ]; then + echo "Error: API failed to start within timeout" + docker-compose -f docker-compose.dev.yaml logs + docker-compose -f docker-compose.dev.yaml down -v + exit 1 + fi - echo "API started successfully" + echo "API started successfully" # Ensure cleanup runs even if the script fails cleanup() { From 22e66be2772d7d755fdb4060a9cadb391beb39ba Mon Sep 17 00:00:00 2001 From: prayansh_chhablani Date: Fri, 27 Dec 2024 18:33:09 +0530 Subject: [PATCH 21/42] merge 2 --- .github/workflows/pull-request.yml | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml index c04a337fb6..b956eac568 100644 --- a/.github/workflows/pull-request.yml +++ b/.github/workflows/pull-request.yml @@ -433,7 +433,15 @@ jobs: LAST_RESORT_SUPERADMIN_EMAIL: "abc@gmail.com" COLORIZE_LOGS: "true" LOG_LEVEL: "info" - node-version: ${{ matrix.node-version }} + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Set up Node.js + uses: actions/setup-node@v4 + with: + node-version: ${{ matrix.node-version }} - name: Install dependencies run: npm ci From 31a7dff99af2375f04aa50c1ae11917401099e3e Mon Sep 17 00:00:00 2001 From: prayansh_chhablani Date: Fri, 27 Dec 2024 18:37:28 +0530 Subject: [PATCH 22/42] idenation fix 2 --- .github/workflows/pull-request.yml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml index b956eac568..4f71abc4c0 100644 --- a/.github/workflows/pull-request.yml +++ b/.github/workflows/pull-request.yml @@ -435,13 +435,13 @@ jobs: LOG_LEVEL: "info" steps: - - name: Checkout repository - uses: actions/checkout@v4 + - name: Checkout repository + uses: actions/checkout@v4 - - name: Set up Node.js - uses: actions/setup-node@v4 - with: - node-version: ${{ matrix.node-version }} + - name: Set up Node.js + uses: actions/setup-node@v4 + with: + node-version: ${{ matrix.node-version }} - name: Install dependencies run: npm ci From 1a53bab4a1ad5a78eb0c7457242b4fd825510366 Mon Sep 17 00:00:00 2001 From: prayansh_chhablani Date: Fri, 27 Dec 2024 19:03:35 +0530 Subject: [PATCH 23/42] correction mongo build --- Dockerfile.mongo | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/Dockerfile.mongo b/Dockerfile.mongo index 2724e2dc97..c5519738d6 100644 --- a/Dockerfile.mongo +++ b/Dockerfile.mongo @@ -3,14 +3,13 @@ FROM mongo:latest RUN apt-get update && apt-get install -y \ gnupg \ curl \ - sudo \ && rm -rf /var/lib/apt/lists/* RUN curl -fsSL https://www.mongodb.org/static/pgp/server-8.0.asc | \ - sudo gpg -o /usr/share/keyrings/mongodb-server-8.0.gpg --dearmor + gpg --dearmor -o /usr/share/keyrings/mongodb-server-8.0.gpg RUN echo "deb [ arch=amd64,arm64 signed-by=/usr/share/keyrings/mongodb-server-8.0.gpg ] https://repo.mongodb.org/apt/ubuntu noble/mongodb-org/8.0 multiverse" | \ - sudo tee /etc/apt/sources.list.d/mongodb-org-8.0.list + tee /etc/apt/sources.list.d/mongodb-org-8.0.list RUN apt-get update && apt-get install -y mongodb-org && rm -rf /var/lib/apt/lists/* From d62920ff451640b00bf78c41edebeec8043e83ce Mon Sep 17 00:00:00 2001 From: prayansh_chhablani Date: Fri, 27 Dec 2024 19:36:37 +0530 Subject: [PATCH 24/42] suggestions --- .github/workflows/pull-request.yml | 3 +-- Dockerfile.mongo | 2 ++ init-replica.sh | 21 ++++++++++++++------- 3 files changed, 17 insertions(+), 9 deletions(-) diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml index 4f71abc4c0..eb46a7b9bc 100644 --- a/.github/workflows/pull-request.yml +++ b/.github/workflows/pull-request.yml @@ -310,7 +310,6 @@ jobs: # Verify docker-compose file exists if [ ! -f "docker-compose.dev.yaml" ]; then echo "Error: docker-compose.dev.yaml not found" - docker-compose -f docker-compose.dev.yaml logs exit 1 fi @@ -324,7 +323,7 @@ jobs: # Wait for MongoDB and Redis to be ready echo "Waiting for MongoDB..." timeout=30 - until docker-compose -f docker-compose.dev.yaml exec -T mongodb mongosh --eval "db.runCommand({ ping: 1 }).ok">/dev/null 2>&1 || [ $timeout -eq 0 ]; do + until docker-compose -f docker-compose.dev.yaml exec -T mongo mongosh --eval "db.runCommand({ ping: 1 }).ok">/dev/null 2>&1 || [ $timeout -eq 0 ]; do echo "Waiting for MongoDB to be ready..." sleep 1 ((timeout--)) diff --git a/Dockerfile.mongo b/Dockerfile.mongo index c5519738d6..758440d501 100644 --- a/Dockerfile.mongo +++ b/Dockerfile.mongo @@ -5,6 +5,8 @@ RUN apt-get update && apt-get install -y \ curl \ && rm -rf /var/lib/apt/lists/* +RUN rm -f /etc/apt/keyrings/mongodb.asc + RUN curl -fsSL https://www.mongodb.org/static/pgp/server-8.0.asc | \ gpg --dearmor -o /usr/share/keyrings/mongodb-server-8.0.gpg diff --git a/init-replica.sh b/init-replica.sh index 01c7f8ee7f..4420d4b7e6 100644 --- a/init-replica.sh +++ b/init-replica.sh @@ -3,18 +3,25 @@ mongod --replSet rs0 --dbpath /var/lib/mongodb --bind_ip_all & -# Wait for MongoDB to start -sleep 10 +until mongosh --eval "db.adminCommand('ping')" >/dev/null 2>&1; do + echo "Waiting for MongoDB to be ready..." + sleep 2 +done -# Initialize the replica set -mongosh --eval ' +if ! mongosh --eval ' rs.initiate({ _id: "rs0", members: [ { _id: 0, host: "mongo:27017" } ] - }) -' + })' >/dev/null 2>&1; then + echo "Failed to initialize replica set" + exti 1 +fi + +until mongosh --eval 'rs.status().ok' | grep -q 1; do + echo "Waiting for replica set to be ready..." + sleep 2 +done -# Keep container running tail -f /dev/null \ No newline at end of file From 5d8cdd9931d14b8cc5d268ae034428016905691d Mon Sep 17 00:00:00 2001 From: prayansh_chhablani Date: Fri, 27 Dec 2024 21:32:18 +0530 Subject: [PATCH 25/42] fixing build error --- Dockerfile.mongo | 14 ++++++++------ init-replica.sh | 2 +- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/Dockerfile.mongo b/Dockerfile.mongo index 758440d501..6c202403e7 100644 --- a/Dockerfile.mongo +++ b/Dockerfile.mongo @@ -3,17 +3,19 @@ FROM mongo:latest RUN apt-get update && apt-get install -y \ gnupg \ curl \ - && rm -rf /var/lib/apt/lists/* - -RUN rm -f /etc/apt/keyrings/mongodb.asc + && mkdir -p /etc/apt/keyrings \ + && curl -fsSL https://www.mongodb.org/static/pgp/server-8.0.asc | tee /etc/apt/keyrings/mongodb.asc \ + && chmod 644 /etc/apt/keyrings/mongodb.asc \ + && echo "deb [signed-by=/etc/apt/keyrings/mongodb.asc] https://repo.mongodb.org/apt/ubuntu jammy/mongodb-org/8.0 multiverse" > /etc/apt/sources.list.d/mongodb-org-8.0.list \ + && apt-get update RUN curl -fsSL https://www.mongodb.org/static/pgp/server-8.0.asc | \ - gpg --dearmor -o /usr/share/keyrings/mongodb-server-8.0.gpg + gpg --batch --yes --dearmor -o /usr/share/keyrings/mongodb-server-8.0.gpg RUN echo "deb [ arch=amd64,arm64 signed-by=/usr/share/keyrings/mongodb-server-8.0.gpg ] https://repo.mongodb.org/apt/ubuntu noble/mongodb-org/8.0 multiverse" | \ tee /etc/apt/sources.list.d/mongodb-org-8.0.list -RUN apt-get update && apt-get install -y mongodb-org && rm -rf /var/lib/apt/lists/* +RUN apt-get update && apt-get install -y mongodb-org RUN mkdir -p /var/lib/mongodb && chown -R mongodb:mongodb /var/lib/mongodb @@ -22,4 +24,4 @@ RUN chmod +x /docker-entrypoint-initdb.d/init-replica.sh EXPOSE 27017 -CMD ["/docker-entrypoint-initdb.d/init-replica.sh"] +CMD ["/docker-entrypoint-initdb.d/init-replica.sh"] \ No newline at end of file diff --git a/init-replica.sh b/init-replica.sh index 4420d4b7e6..9cf0e7aa18 100644 --- a/init-replica.sh +++ b/init-replica.sh @@ -24,4 +24,4 @@ until mongosh --eval 'rs.status().ok' | grep -q 1; do sleep 2 done -tail -f /dev/null \ No newline at end of file +wait $MONGOD_PID \ No newline at end of file From cfcd134277eca1b4138ae5429f6eb7b7dd870dff Mon Sep 17 00:00:00 2001 From: prayansh_chhablani Date: Fri, 27 Dec 2024 22:14:34 +0530 Subject: [PATCH 26/42] error fix --- Dockerfile.mongo | 3 --- 1 file changed, 3 deletions(-) diff --git a/Dockerfile.mongo b/Dockerfile.mongo index 6c202403e7..946cdbf57f 100644 --- a/Dockerfile.mongo +++ b/Dockerfile.mongo @@ -12,9 +12,6 @@ RUN apt-get update && apt-get install -y \ RUN curl -fsSL https://www.mongodb.org/static/pgp/server-8.0.asc | \ gpg --batch --yes --dearmor -o /usr/share/keyrings/mongodb-server-8.0.gpg -RUN echo "deb [ arch=amd64,arm64 signed-by=/usr/share/keyrings/mongodb-server-8.0.gpg ] https://repo.mongodb.org/apt/ubuntu noble/mongodb-org/8.0 multiverse" | \ - tee /etc/apt/sources.list.d/mongodb-org-8.0.list - RUN apt-get update && apt-get install -y mongodb-org RUN mkdir -p /var/lib/mongodb && chown -R mongodb:mongodb /var/lib/mongodb From a1425e04aa5967bb31b87e5bb5b858967aa312ca Mon Sep 17 00:00:00 2001 From: prayansh_chhablani Date: Fri, 27 Dec 2024 22:19:57 +0530 Subject: [PATCH 27/42] error fix --- Dockerfile.mongo | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/Dockerfile.mongo b/Dockerfile.mongo index 946cdbf57f..5eed3412e5 100644 --- a/Dockerfile.mongo +++ b/Dockerfile.mongo @@ -5,12 +5,9 @@ RUN apt-get update && apt-get install -y \ curl \ && mkdir -p /etc/apt/keyrings \ && curl -fsSL https://www.mongodb.org/static/pgp/server-8.0.asc | tee /etc/apt/keyrings/mongodb.asc \ - && chmod 644 /etc/apt/keyrings/mongodb.asc \ - && echo "deb [signed-by=/etc/apt/keyrings/mongodb.asc] https://repo.mongodb.org/apt/ubuntu jammy/mongodb-org/8.0 multiverse" > /etc/apt/sources.list.d/mongodb-org-8.0.list \ - && apt-get update + && chmod 644 /etc/apt/keyrings/mongodb.asc -RUN curl -fsSL https://www.mongodb.org/static/pgp/server-8.0.asc | \ - gpg --batch --yes --dearmor -o /usr/share/keyrings/mongodb-server-8.0.gpg +RUN echo "deb [signed-by=/etc/apt/keyrings/mongodb.asc] https://repo.mongodb.org/apt/ubuntu jammy/mongodb-org/8.0 multiverse" > /etc/apt/sources.list.d/mongodb-org-8.0.list RUN apt-get update && apt-get install -y mongodb-org From cd44d422b077f5dd9f369f396fddb9a95a930bea Mon Sep 17 00:00:00 2001 From: prayansh_chhablani Date: Fri, 27 Dec 2024 23:29:30 +0530 Subject: [PATCH 28/42] ai suggestions --- init-replica.sh | 1 - 1 file changed, 1 deletion(-) diff --git a/init-replica.sh b/init-replica.sh index 9cf0e7aa18..c53df491f8 100644 --- a/init-replica.sh +++ b/init-replica.sh @@ -16,7 +16,6 @@ if ! mongosh --eval ' ] })' >/dev/null 2>&1; then echo "Failed to initialize replica set" - exti 1 fi until mongosh --eval 'rs.status().ok' | grep -q 1; do From 9b300e1c8868b9aa06a8cd7135dbcbd7cc01dae2 Mon Sep 17 00:00:00 2001 From: prayansh_chhablani Date: Sat, 28 Dec 2024 00:06:22 +0530 Subject: [PATCH 29/42] added caddy service --- docker-compose.dev.yaml | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/docker-compose.dev.yaml b/docker-compose.dev.yaml index df0e2c06b7..03d6471122 100644 --- a/docker-compose.dev.yaml +++ b/docker-compose.dev.yaml @@ -56,12 +56,26 @@ services: - REDIS_PORT=6379 networks: - talawa-network + caddy: + image: caddy/caddy:2.2.1-alpine + container_name: caddy-service + restart: unless-stopped + ports: + - "80:80" + - "443:443" + volumes: + - ./Caddyfile:/etc/caddy/Caddyfile + - $PWD/site:/srv + - caddy_data:/data + - caddy_config:/config volumes: redis-data: minio-data: mongo_data: + caddy_data: + caddy_config: networks: talawa-network: From 94fad12bd0b77e029dee9c4f292936d55a8c8e46 Mon Sep 17 00:00:00 2001 From: prayansh_chhablani Date: Sat, 28 Dec 2024 00:59:54 +0530 Subject: [PATCH 30/42] suggestions --- docker-compose.dev.yaml | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/docker-compose.dev.yaml b/docker-compose.dev.yaml index 03d6471122..2688514c45 100644 --- a/docker-compose.dev.yaml +++ b/docker-compose.dev.yaml @@ -4,8 +4,18 @@ services: context: . dockerfile: Dockerfile.mongo container_name: mongo + restart: unless-stopped + healthcheck: + test: ["CMD", "mongosh", "--eval", "'db.runCommand(\"ping\").ok'"] + interval: 10s + timeout: 5s + retries: 5 + deploy: + resources: + limits: + memory: 1G ports: - - "27017:27017" + - "127.0.0.1:27017:27017" volumes: - mongo_data:/var/lib/mongodb networks: From baaa36db3cbb8f3e5d886a187da660d72b4a1c21 Mon Sep 17 00:00:00 2001 From: prayansh_chhablani Date: Sun, 29 Dec 2024 19:45:57 +0530 Subject: [PATCH 31/42] simpler config for replSet --- .env.sample | 1 + Dockerfile.mongo | 21 --------------------- docker-compose.dev.yaml | 16 ++++++++-------- init-replica.sh | 26 -------------------------- 4 files changed, 9 insertions(+), 55 deletions(-) delete mode 100644 Dockerfile.mongo delete mode 100644 init-replica.sh diff --git a/.env.sample b/.env.sample index 073cf6b0c2..a3b839830f 100644 --- a/.env.sample +++ b/.env.sample @@ -24,6 +24,7 @@ REFRESH_TOKEN_SECRET= # This environment variable is used to provide connection string of the mongoDB # database for talawa-api to connect to. +# Sample url for docker setup: mongodb://localhost:port/?replicaSet=rs0&directConnection=true MONGO_DB_URL= diff --git a/Dockerfile.mongo b/Dockerfile.mongo deleted file mode 100644 index 5eed3412e5..0000000000 --- a/Dockerfile.mongo +++ /dev/null @@ -1,21 +0,0 @@ -FROM mongo:latest - -RUN apt-get update && apt-get install -y \ - gnupg \ - curl \ - && mkdir -p /etc/apt/keyrings \ - && curl -fsSL https://www.mongodb.org/static/pgp/server-8.0.asc | tee /etc/apt/keyrings/mongodb.asc \ - && chmod 644 /etc/apt/keyrings/mongodb.asc - -RUN echo "deb [signed-by=/etc/apt/keyrings/mongodb.asc] https://repo.mongodb.org/apt/ubuntu jammy/mongodb-org/8.0 multiverse" > /etc/apt/sources.list.d/mongodb-org-8.0.list - -RUN apt-get update && apt-get install -y mongodb-org - -RUN mkdir -p /var/lib/mongodb && chown -R mongodb:mongodb /var/lib/mongodb - -COPY init-replica.sh /docker-entrypoint-initdb.d/ -RUN chmod +x /docker-entrypoint-initdb.d/init-replica.sh - -EXPOSE 27017 - -CMD ["/docker-entrypoint-initdb.d/init-replica.sh"] \ No newline at end of file diff --git a/docker-compose.dev.yaml b/docker-compose.dev.yaml index 2688514c45..77d082492d 100644 --- a/docker-compose.dev.yaml +++ b/docker-compose.dev.yaml @@ -1,25 +1,25 @@ services: mongo: - build: - context: . - dockerfile: Dockerfile.mongo + image: mongo:latest container_name: mongo + command: ["--replSet", "rs0", "--bind_ip_all"] restart: unless-stopped healthcheck: - test: ["CMD", "mongosh", "--eval", "'db.runCommand(\"ping\").ok'"] + test: mongosh --eval "try { rs.status().ok } catch (e) { 0 }" interval: 10s timeout: 5s retries: 5 deploy: resources: limits: - memory: 1G + memory: 1G ports: - - "127.0.0.1:27017:27017" + - "27017:27017" volumes: - - mongo_data:/var/lib/mongodb + - mongo_data:/data/db networks: - talawa-network + redis-stack-server: image: redis/redis-stack-server:latest ports: @@ -55,7 +55,7 @@ services: - /usr/src/app/node_modules depends_on: mongo: - condition: service_started + condition: service_healthy redis-stack-server: condition: service_started minio: diff --git a/init-replica.sh b/init-replica.sh deleted file mode 100644 index c53df491f8..0000000000 --- a/init-replica.sh +++ /dev/null @@ -1,26 +0,0 @@ -#!/bin/bash -# init-replicaset.sh - -mongod --replSet rs0 --dbpath /var/lib/mongodb --bind_ip_all & - -until mongosh --eval "db.adminCommand('ping')" >/dev/null 2>&1; do - echo "Waiting for MongoDB to be ready..." - sleep 2 -done - -if ! mongosh --eval ' - rs.initiate({ - _id: "rs0", - members: [ - { _id: 0, host: "mongo:27017" } - ] - })' >/dev/null 2>&1; then - echo "Failed to initialize replica set" -fi - -until mongosh --eval 'rs.status().ok' | grep -q 1; do - echo "Waiting for replica set to be ready..." - sleep 2 -done - -wait $MONGOD_PID \ No newline at end of file From 5cf642af243d9ec75dc26bdb01aae52c6cdfd582 Mon Sep 17 00:00:00 2001 From: prayansh_chhablani Date: Sun, 29 Dec 2024 20:17:41 +0530 Subject: [PATCH 32/42] env fix --- .github/workflows/pull-request.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml index eb46a7b9bc..a9ce061ecf 100644 --- a/.github/workflows/pull-request.yml +++ b/.github/workflows/pull-request.yml @@ -386,7 +386,7 @@ jobs: env: HEALTH_CHECK_URL: http://localhost:4000 COMPOSE_PROJECT_NAME: pr-${{ github.event.pull_request.number }} - MONGO_DB_URL: mongodb://mongodb:27017/talawa-test-db + MONGO_DB_URL: mongodb://mongo:27017?replicaSet=rs0 REDIS_HOST: redis-stack-server REDIS_PORT: 6379 ACCESS_TOKEN_SECRET: ${{ secrets.GITHUB_TOKEN }}_${{ github.run_id }}_${{ github.run_number }} From 5e6a5e9aa780484bf2e484ed4a49b7c51391b2ec Mon Sep 17 00:00:00 2001 From: prayansh_chhablani Date: Sun, 29 Dec 2024 23:36:45 +0530 Subject: [PATCH 33/42] suggestion --- .github/workflows/pull-request.yml | 8 +++----- .github/workflows/scripts/docker_file_check.sh | 11 +++++++++++ 2 files changed, 14 insertions(+), 5 deletions(-) create mode 100755 .github/workflows/scripts/docker_file_check.sh diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml index eb46a7b9bc..c52efd2e3b 100644 --- a/.github/workflows/pull-request.yml +++ b/.github/workflows/pull-request.yml @@ -308,10 +308,8 @@ jobs: docker-compose -f docker-compose.dev.yaml down -v || true # Verify docker-compose file exists - if [ ! -f "docker-compose.dev.yaml" ]; then - echo "Error: docker-compose.dev.yaml not found" - exit 1 - fi + chmod +x scripts/docker_check.sh + ./scripts/docker_check.sh # Start containers if ! timeout 300 docker-compose -f docker-compose.dev.yaml up -d --build; then @@ -386,7 +384,7 @@ jobs: env: HEALTH_CHECK_URL: http://localhost:4000 COMPOSE_PROJECT_NAME: pr-${{ github.event.pull_request.number }} - MONGO_DB_URL: mongodb://mongodb:27017/talawa-test-db + MONGO_DB_URL: mongodb://mongo:27017?replicaSet=rs0 REDIS_HOST: redis-stack-server REDIS_PORT: 6379 ACCESS_TOKEN_SECRET: ${{ secrets.GITHUB_TOKEN }}_${{ github.run_id }}_${{ github.run_number }} diff --git a/.github/workflows/scripts/docker_file_check.sh b/.github/workflows/scripts/docker_file_check.sh new file mode 100755 index 0000000000..f847488c96 --- /dev/null +++ b/.github/workflows/scripts/docker_file_check.sh @@ -0,0 +1,11 @@ +#!/bin/bash + +echo "Stopping and removing any running containers..." +docker-compose -f ../../docker-compose.dev.yaml down -v || true + +if [ ! -f "../../docker-compose.dev.yaml" ]; then + echo "Error: docker-compose.dev.yaml not found" + exit 1 +fi + +echo "docker-compose.dev.yaml file found. Ready to proceed." \ No newline at end of file From 481b979a17d1669be39a92b24bc78cb8f9a78682 Mon Sep 17 00:00:00 2001 From: prayansh_chhablani Date: Mon, 30 Dec 2024 00:48:55 +0530 Subject: [PATCH 34/42] final fix --- docker-compose.dev.yaml | 11 ++++++----- init-mongo.sh | 31 +++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 5 deletions(-) create mode 100755 init-mongo.sh diff --git a/docker-compose.dev.yaml b/docker-compose.dev.yaml index 77d082492d..6f7dd71200 100644 --- a/docker-compose.dev.yaml +++ b/docker-compose.dev.yaml @@ -2,23 +2,24 @@ services: mongo: image: mongo:latest container_name: mongo - command: ["--replSet", "rs0", "--bind_ip_all"] restart: unless-stopped healthcheck: test: mongosh --eval "try { rs.status().ok } catch (e) { 0 }" - interval: 10s + interval: 30s timeout: 5s - retries: 5 + retries: 30 deploy: resources: limits: memory: 1G ports: - - "27017:27017" + - "127.0.0.1:27017:27017" volumes: - mongo_data:/data/db + - ./init-mongo.sh:/init-mongo.sh networks: - talawa-network + entrypoint: ["/bin/bash", "/init-mongo.sh"] redis-stack-server: image: redis/redis-stack-server:latest @@ -61,7 +62,7 @@ services: minio: condition: service_started environment: - - MONGO_DB_URL=mongodb://mongo:27017?replicaSet=rs0 + - MONGO_DB_URL=mongodb://mongo:27017/talawa-api?replicaSet=rs0&directConnection=true - REDIS_HOST=redis-stack-server - REDIS_PORT=6379 networks: diff --git a/init-mongo.sh b/init-mongo.sh new file mode 100755 index 0000000000..f1d5af39bc --- /dev/null +++ b/init-mongo.sh @@ -0,0 +1,31 @@ +mongod --replSet rs0 --bind_ip_all --dbpath /data/db & + +# Wait for MongoDB to start up +sleep 10 + +# Initialize the replica set +mongosh --eval ' + config = { + "_id" : "rs0", + "members" : [ + { + "_id" : 0, + "host" : "mongo:27017", + "priority": 1 + } + ] + }; + + while (true) { + try { + rs.initiate(config); + break; + } catch (err) { + print("Failed to initiate replica set, retrying in 5 seconds..."); + sleep(5000); + } + } +' + +# Keep container running +tail -f /dev/null \ No newline at end of file From 717ad626bb542dde12fa652064a94a0b2990e6e1 Mon Sep 17 00:00:00 2001 From: prayansh_chhablani Date: Mon, 30 Dec 2024 01:25:11 +0530 Subject: [PATCH 35/42] suggestions --- .github/workflows/pull-request.yml | 4 +-- .../workflows/scripts/docker_file_check.sh | 12 +++++---- init-mongo.sh | 26 +++++++++++++++++-- 3 files changed, 33 insertions(+), 9 deletions(-) diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml index c52efd2e3b..472edcaf63 100644 --- a/.github/workflows/pull-request.yml +++ b/.github/workflows/pull-request.yml @@ -308,8 +308,8 @@ jobs: docker-compose -f docker-compose.dev.yaml down -v || true # Verify docker-compose file exists - chmod +x scripts/docker_check.sh - ./scripts/docker_check.sh + chmod +x .github/workflows/scripts/docker_file_check.sh + ./.github/workflows/scripts/docker_file_check.sh # Start containers if ! timeout 300 docker-compose -f docker-compose.dev.yaml up -d --build; then diff --git a/.github/workflows/scripts/docker_file_check.sh b/.github/workflows/scripts/docker_file_check.sh index f847488c96..75cfc01e77 100755 --- a/.github/workflows/scripts/docker_file_check.sh +++ b/.github/workflows/scripts/docker_file_check.sh @@ -1,11 +1,13 @@ #!/bin/bash +REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)" -echo "Stopping and removing any running containers..." -docker-compose -f ../../docker-compose.dev.yaml down -v || true - -if [ ! -f "../../docker-compose.dev.yaml" ]; then - echo "Error: docker-compose.dev.yaml not found" +if ! command -v docker-compose &> /dev/null; then + echo "Error: docker-compose is not installed" exit 1 fi +docker-compose -f "${REPO_ROOT}/docker-compose.dev.yaml" down -v || { + echo "Warning: Failed to stop containers. Continuing anyway..." +} + echo "docker-compose.dev.yaml file found. Ready to proceed." \ No newline at end of file diff --git a/init-mongo.sh b/init-mongo.sh index f1d5af39bc..9f50eba388 100755 --- a/init-mongo.sh +++ b/init-mongo.sh @@ -1,7 +1,29 @@ +#!/bin/bash +set -e + +# Handle cleanup on script exit +cleanup() { + echo "Shutting down MongoDB..." + mongod --shutdown + exit 0 +} +trap cleanup SIGTERM SIGINT + mongod --replSet rs0 --bind_ip_all --dbpath /data/db & +MONGOD_PID=$! -# Wait for MongoDB to start up -sleep 10 +# Wait for MongoDB to be ready +MAX_TRIES=30 +COUNTER=0 +echo "Waiting for MongoDB to start..." +until mongosh --eval "db.adminCommand('ping')" >/dev/null 2>&1; do + if [ $COUNTER -gt $MAX_TRIES ]; then + echo "Error: MongoDB failed to start" + exit 1 + fi + let COUNTER=COUNTER+1 + sleep 1 +done # Initialize the replica set mongosh --eval ' From 44572771918c19f5549c4eec1deda1c9bd5c0271 Mon Sep 17 00:00:00 2001 From: prayansh_chhablani Date: Mon, 30 Dec 2024 02:13:41 +0530 Subject: [PATCH 36/42] last suggestions --- .github/workflows/pull-request.yml | 4 +++- init-mongo.sh | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml index 472edcaf63..c1caf99e79 100644 --- a/.github/workflows/pull-request.yml +++ b/.github/workflows/pull-request.yml @@ -356,7 +356,9 @@ jobs: # Wait for TALAWA API to be healthy timeout=60 - until docker-compose -f docker-compose.dev.yaml exec -T talawa-api-dev curl -v -X OPTIONS "http://talawa-api-dev:4000/graphql" 2>&1 || [ $timeout -eq 0 ]; do + until docker-compose -f docker-compose.dev.yaml exec -T talawa-api-dev curl -sf -X POST "http://talawa-api-dev:4000/graphql" \ + -H "Content-Type: application/json" \ + -d '{"query":"{ __typename }"}' 2>&1 || [ $timeout -eq 0 ]; d echo "Waiting for API to start... ($timeout seconds remaining)" sleep 1 ((timeout--)) diff --git a/init-mongo.sh b/init-mongo.sh index 9f50eba388..5b0bd22c7d 100755 --- a/init-mongo.sh +++ b/init-mongo.sh @@ -50,4 +50,4 @@ mongosh --eval ' ' # Keep container running -tail -f /dev/null \ No newline at end of file +wait $MONGOD_PID \ No newline at end of file From 6cc31618cd70e8e2575c5a0640e1af6decc89006 Mon Sep 17 00:00:00 2001 From: prayansh_chhablani Date: Mon, 30 Dec 2024 02:25:46 +0530 Subject: [PATCH 37/42] sytnax error --- .github/workflows/pull-request.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml index c1caf99e79..b8b765fc21 100644 --- a/.github/workflows/pull-request.yml +++ b/.github/workflows/pull-request.yml @@ -358,7 +358,7 @@ jobs: timeout=60 until docker-compose -f docker-compose.dev.yaml exec -T talawa-api-dev curl -sf -X POST "http://talawa-api-dev:4000/graphql" \ -H "Content-Type: application/json" \ - -d '{"query":"{ __typename }"}' 2>&1 || [ $timeout -eq 0 ]; d + -d '{"query":"{ __typename }"}' 2>&1 || [ $timeout -eq 0 ]; do echo "Waiting for API to start... ($timeout seconds remaining)" sleep 1 ((timeout--)) From 626991c5bea00bae0c4804e4c585bb43d2222c45 Mon Sep 17 00:00:00 2001 From: prayansh_chhablani Date: Mon, 30 Dec 2024 02:39:23 +0530 Subject: [PATCH 38/42] line continuation --- .github/workflows/pull-request.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml index b8b765fc21..0d332d61d5 100644 --- a/.github/workflows/pull-request.yml +++ b/.github/workflows/pull-request.yml @@ -356,8 +356,8 @@ jobs: # Wait for TALAWA API to be healthy timeout=60 - until docker-compose -f docker-compose.dev.yaml exec -T talawa-api-dev curl -sf -X POST "http://talawa-api-dev:4000/graphql" \ - -H "Content-Type: application/json" \ + until docker-compose -f docker-compose.dev.yaml exec -T talawa-api-dev curl -sf -X POST "http://talawa-api-dev:4000/graphql" \ + -H "Content-Type: application/json" \ -d '{"query":"{ __typename }"}' 2>&1 || [ $timeout -eq 0 ]; do echo "Waiting for API to start... ($timeout seconds remaining)" sleep 1 From 75939ab1c1fe2e68987c1c6f38a12145ef188155 Mon Sep 17 00:00:00 2001 From: prayansh_chhablani Date: Mon, 30 Dec 2024 08:52:25 +0530 Subject: [PATCH 39/42] revert suggestions --- .github/workflows/pull-request.yml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml index 0d332d61d5..472edcaf63 100644 --- a/.github/workflows/pull-request.yml +++ b/.github/workflows/pull-request.yml @@ -356,9 +356,7 @@ jobs: # Wait for TALAWA API to be healthy timeout=60 - until docker-compose -f docker-compose.dev.yaml exec -T talawa-api-dev curl -sf -X POST "http://talawa-api-dev:4000/graphql" \ - -H "Content-Type: application/json" \ - -d '{"query":"{ __typename }"}' 2>&1 || [ $timeout -eq 0 ]; do + until docker-compose -f docker-compose.dev.yaml exec -T talawa-api-dev curl -v -X OPTIONS "http://talawa-api-dev:4000/graphql" 2>&1 || [ $timeout -eq 0 ]; do echo "Waiting for API to start... ($timeout seconds remaining)" sleep 1 ((timeout--)) From 577175fd5d45ed1c4623c10d69850ba90012eadf Mon Sep 17 00:00:00 2001 From: prayansh_chhablani Date: Tue, 31 Dec 2024 14:42:21 +0530 Subject: [PATCH 40/42] db connection --- sample_data/users.json | 2 +- src/utilities/loadSampleData.ts | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/sample_data/users.json b/sample_data/users.json index 92f21c20ae..bcaee45ea1 100644 --- a/sample_data/users.json +++ b/sample_data/users.json @@ -21,7 +21,7 @@ "state": "State" }, "email": "testsuperadmin@example.com", - "password": "$2a$12$bSYpay6TRMpTOaAmYPFXku4avwmqfFBtmgg39TabxmtFEiz4plFtW", + "password": "$2a$12$gawMkattI6b.HAAwW7khxOJNzGZ2/N6YFe387/2yG8Z0G6tKVtv2y", "image": null, "createdAt": "2023-04-13T04:53:17.742Z", "__v": 0 diff --git a/src/utilities/loadSampleData.ts b/src/utilities/loadSampleData.ts index ad714daf06..cca9598ed4 100644 --- a/src/utilities/loadSampleData.ts +++ b/src/utilities/loadSampleData.ts @@ -83,7 +83,7 @@ async function formatDatabase(): Promise { async function insertCollections(collections: string[]): Promise { try { // Connect to MongoDB database - await connect(); + await connect("talawa-api"); const { format } = yargs(hideBin(process.argv)) .options({ @@ -168,7 +168,7 @@ async function insertCollections(collections: string[]): Promise { async function checkCountAfterImport(): Promise { try { // Connect to MongoDB database - await connect(); + await connect("talawa-api"); const collections = [ { name: "users", model: User }, From 89f67dd6949216160f6453856117ee173f0b74cb Mon Sep 17 00:00:00 2001 From: prayansh_chhablani Date: Tue, 31 Dec 2024 21:17:52 +0530 Subject: [PATCH 41/42] eslint removal --- setup.ts | 29 ++++++++++++++--------------- tsconfig.json | 7 ++++++- 2 files changed, 20 insertions(+), 16 deletions(-) diff --git a/setup.ts b/setup.ts index 4e1a689055..760de987aa 100644 --- a/setup.ts +++ b/setup.ts @@ -1,4 +1,3 @@ -/* eslint-disable no-restricted-imports */ import * as cryptolib from "crypto"; import dotenv from "dotenv"; import fs from "fs"; @@ -7,31 +6,31 @@ import path from "path"; import type { ExecException } from "child_process"; import { exec, spawn, execSync } from "child_process"; import { MongoClient } from "mongodb"; -import { MAXIMUM_IMAGE_SIZE_LIMIT_KB } from "./src/constants"; +import { MAXIMUM_IMAGE_SIZE_LIMIT_KB } from "@constants"; import { askForMongoDBUrl, checkConnection, checkExistingMongoDB, -} from "./src/setup/MongoDB"; -import { askToKeepValues } from "./src/setup/askToKeepValues"; -import { getNodeEnvironment } from "./src/setup/getNodeEnvironment"; -import { isValidEmail } from "./src/setup/isValidEmail"; -import { validateRecaptcha } from "./src/setup/reCaptcha"; +} from "@setup/MongoDB"; +import { askToKeepValues } from "@setup/askToKeepValues"; +import { getNodeEnvironment } from "@setup/getNodeEnvironment"; +import { isValidEmail } from "@setup/isValidEmail"; +import { validateRecaptcha } from "@setup/reCaptcha"; import { askForRedisUrl, checkExistingRedis, checkRedisConnection, -} from "./src/setup/redisConfiguration"; +} from "@setup/redisConfiguration"; import { setImageUploadSize, validateImageFileSize, -} from "./src/setup/setImageUploadSize"; -import { askForSuperAdminEmail } from "./src/setup/superAdmin"; -import { updateEnvVariable } from "./src/setup/updateEnvVariable"; -import { verifySmtpConnection } from "./src/setup/verifySmtpConnection"; -import { loadDefaultOrganiation } from "./src/utilities/loadDefaultOrg"; -import { isMinioInstalled } from "./src/setup/isMinioInstalled"; -import { installMinio } from "./src/setup/installMinio"; +} from "@setup/setImageUploadSize"; +import { askForSuperAdminEmail } from "@setup/superAdmin"; +import { updateEnvVariable } from "@setup/updateEnvVariable"; +import { verifySmtpConnection } from "@setup/verifySmtpConnection"; +import { loadDefaultOrganiation } from "@utilities/loadDefaultOrg"; +import { isMinioInstalled } from "@setup/isMinioInstalled"; +import { installMinio } from "@setup/installMinio"; dotenv.config(); diff --git a/tsconfig.json b/tsconfig.json index fc155159d5..a60626d601 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -8,6 +8,11 @@ "skipLibCheck": true /* Skip type checking all .d.ts files. */, "resolveJsonModule": true /* Allow to import JSON files */, "moduleResolution": "node", - "noUncheckedSideEffectImports": true /* Checks if module's path exists. */ + "noUncheckedSideEffectImports": true /* Checks if module's path exists. */, + "paths": { + "@constants": ["./src/constants"], + "@setup/*": ["./src/setup/*"], + "@utilities/*": ["./src/utilities/*"] + } } } From 6841b72722efd7efacc8504c1f11eb3a1d1e8ede Mon Sep 17 00:00:00 2001 From: prayansh_chhablani Date: Wed, 1 Jan 2025 16:53:50 +0530 Subject: [PATCH 42/42] fix failing tests --- src/utilities/loadSampleData.ts | 1 + tests/resolvers/Query/getVolunteerRanks.spec.ts | 4 ++-- tests/setup/checkExistingMongoDB.spec.ts | 5 ++++- tests/setup/mongoDB.spec.ts | 3 ++- tests/utilities/loadSampleData.spec.ts | 2 +- vite.config.mts | 10 ++++++++++ 6 files changed, 20 insertions(+), 5 deletions(-) diff --git a/src/utilities/loadSampleData.ts b/src/utilities/loadSampleData.ts index 60d1421c42..176a3c0eba 100644 --- a/src/utilities/loadSampleData.ts +++ b/src/utilities/loadSampleData.ts @@ -74,6 +74,7 @@ async function formatDatabase(): Promise { Post.deleteMany({}), AppUserProfile.deleteMany({}), RecurrenceRule.deleteMany({}), + Venue.deleteMany({}), ]); console.log("Cleared all collections\n"); } diff --git a/tests/resolvers/Query/getVolunteerRanks.spec.ts b/tests/resolvers/Query/getVolunteerRanks.spec.ts index 67060e0bcc..d742e10b74 100644 --- a/tests/resolvers/Query/getVolunteerRanks.spec.ts +++ b/tests/resolvers/Query/getVolunteerRanks.spec.ts @@ -77,7 +77,7 @@ describe("resolvers -> Query -> getVolunteerRanks", () => { {}, )) as unknown as VolunteerRank[]; - expect(volunteerRanks[0].hoursVolunteered).toEqual(6); + expect(volunteerRanks[0].hoursVolunteered).toEqual(2); expect(volunteerRanks[0].user._id).toEqual(testUser1?._id); expect(volunteerRanks[0].rank).toEqual(1); }); @@ -94,7 +94,7 @@ describe("resolvers -> Query -> getVolunteerRanks", () => { }, {}, )) as unknown as VolunteerRank[]; - expect(volunteerRanks[0].hoursVolunteered).toEqual(8); + expect(volunteerRanks[0].hoursVolunteered).toEqual(2); expect(volunteerRanks[0].user._id).toEqual(testUser1?._id); expect(volunteerRanks[0].rank).toEqual(1); }); diff --git a/tests/setup/checkExistingMongoDB.spec.ts b/tests/setup/checkExistingMongoDB.spec.ts index 02d934eca0..9d4bff9117 100644 --- a/tests/setup/checkExistingMongoDB.spec.ts +++ b/tests/setup/checkExistingMongoDB.spec.ts @@ -9,6 +9,8 @@ describe("Setup -> checkExistingMongoDB", () => { }); it("should return the first valid URL when a connection is found", async () => { const result = await checkExistingMongoDB(); + console.log(result); + console.log(process.env.MONGO_DB_URL); expect(result).toBe(process.env.MONGO_DB_URL); }); @@ -60,7 +62,8 @@ describe("Setup -> checkExistingMongoDB", () => { expect(result).toBe(false); }); it("should return the first valid URL when a connection is found", async () => { - process.env.MONGO_DB_URL = "mongodb://localhost:27017/talawa-api"; + process.env.MONGO_DB_URL = + "mongodb://localhost:27017/test?replicaSet=rs0&directConnection=true"; const result = await checkExistingMongoDB(); expect(result).toBe(process.env.MONGO_DB_URL); }); diff --git a/tests/setup/mongoDB.spec.ts b/tests/setup/mongoDB.spec.ts index c6969b5af3..9cf28acac6 100644 --- a/tests/setup/mongoDB.spec.ts +++ b/tests/setup/mongoDB.spec.ts @@ -117,7 +117,8 @@ describe("Setup -> mongoDB", () => { }); it("should return true for a successfull connection with MongoDB", async () => { - const url = "mongodb://localhost:27017"; + const url = + "mongodb://localhost:27017/test?replicaSet=rs0&directConnection=true"; const result = await module.checkConnection(url); expect(result).toEqual(true); }); diff --git a/tests/utilities/loadSampleData.spec.ts b/tests/utilities/loadSampleData.spec.ts index c5ab00832b..9140d0fb03 100644 --- a/tests/utilities/loadSampleData.spec.ts +++ b/tests/utilities/loadSampleData.spec.ts @@ -15,7 +15,7 @@ import { execSync } from "child_process"; describe("Sample Data Import Tests", () => { beforeAll(async () => { - await connect(); + await connect("talawa-api"); }); afterAll(async () => { diff --git a/vite.config.mts b/vite.config.mts index 12749c1ce5..87eae5c65a 100644 --- a/vite.config.mts +++ b/vite.config.mts @@ -1,6 +1,15 @@ import { defineConfig } from "vitest/config"; +import path from 'node:path'; export default defineConfig({ + resolve: { + alias: { + '@constants': path.resolve(__dirname, 'src/constants'), + '@setup': path.resolve(__dirname, 'src/setup'), + '@utilities': path.resolve(__dirname, 'src/utilities'), + }, + }, + test: { setupFiles: ["./config/vitestSetup.ts"], @@ -36,6 +45,7 @@ export default defineConfig({ "src/utilities/sample_data/*", "src/utilities/loadSampleData.ts", ], + // This is used to tell vitest which coverage provider to use. c8 is the newer and // recommended coverage provider for node.js applications. You can swap it with