From 1db3586361333c555aca8dff9486a65b518959c7 Mon Sep 17 00:00:00 2001 From: omar-sarfraz Date: Tue, 24 Sep 2024 17:22:14 +0500 Subject: [PATCH 1/6] deployment(backend): add basic CI --- .github/workflows/Express CI.yml | 34 ++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 .github/workflows/Express CI.yml diff --git a/.github/workflows/Express CI.yml b/.github/workflows/Express CI.yml new file mode 100644 index 0000000..4b8fa1d --- /dev/null +++ b/.github/workflows/Express CI.yml @@ -0,0 +1,34 @@ +name: Express CI + +on: + push: + branches: ["main", "backend/workflows"] + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + + - name: Install Sentry + run: curl -sL https://sentry.io/get-cli/ | sh + + - name: Login Sentry + run: sentry-cli login --auth-token ${{secrets.SENTRY_AUTH_TOKEN}} + + - name: Login Dockerhub + env: + DOCKER_USERNAME: ${{secrets.DOCKER_USERNAME}} + DOCKER_TOKEN: ${{secrets.DOCKER_TOKEN}} + run: docker login -u $DOCKER_USERNAME -p $DOCKER_TOKEN + + - name: Build Docker images for backend and graphql + run: | + docker compose build backend + docker compose build graphql + + - name: Push Docker images to DockerHub + run: | + docker push omarsarfraz/project-listings:backend + docker push omarsarfraz/project-listings:graphql From cb0e110e779fb6a16d4b0d98132bc2340cc200a2 Mon Sep 17 00:00:00 2001 From: omar-sarfraz Date: Tue, 24 Sep 2024 18:08:08 +0500 Subject: [PATCH 2/6] chore(deployment): add sentry env --- .github/workflows/Express CI.yml | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/.github/workflows/Express CI.yml b/.github/workflows/Express CI.yml index 4b8fa1d..75208d7 100644 --- a/.github/workflows/Express CI.yml +++ b/.github/workflows/Express CI.yml @@ -8,15 +8,13 @@ jobs: build: runs-on: ubuntu-latest + env: + ENVIRONMENT: ${{ secrets.ENVIRONMENT }} + SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }} + steps: - uses: actions/checkout@v4 - - name: Install Sentry - run: curl -sL https://sentry.io/get-cli/ | sh - - - name: Login Sentry - run: sentry-cli login --auth-token ${{secrets.SENTRY_AUTH_TOKEN}} - - name: Login Dockerhub env: DOCKER_USERNAME: ${{secrets.DOCKER_USERNAME}} From d76c43d0cf5022c4267d157575307f90ef145db0 Mon Sep 17 00:00:00 2001 From: omar-sarfraz Date: Tue, 24 Sep 2024 18:18:43 +0500 Subject: [PATCH 3/6] chore(deployment): add sentry-cli login command --- .github/workflows/Express CI.yml | 7 +++---- Backend/package.json | 3 ++- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/Express CI.yml b/.github/workflows/Express CI.yml index 75208d7..ea71913 100644 --- a/.github/workflows/Express CI.yml +++ b/.github/workflows/Express CI.yml @@ -8,10 +8,6 @@ jobs: build: runs-on: ubuntu-latest - env: - ENVIRONMENT: ${{ secrets.ENVIRONMENT }} - SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }} - steps: - uses: actions/checkout@v4 @@ -22,6 +18,9 @@ jobs: run: docker login -u $DOCKER_USERNAME -p $DOCKER_TOKEN - name: Build Docker images for backend and graphql + env: + ENVIRONMENT: ${{ secrets.ENVIRONMENT }} + SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }} run: | docker compose build backend docker compose build graphql diff --git a/Backend/package.json b/Backend/package.json index ab36699..651eb75 100644 --- a/Backend/package.json +++ b/Backend/package.json @@ -7,7 +7,8 @@ "start": "node -r dotenv/config dist/index.js dotenv_config_path=.env.local", "dev": "nodemon -r dotenv/config index.ts dotenv_config_path=.env.local", "test": "echo \"Error: no test specified\" && exit 1", - "sentry:sourcemaps": "sentry-cli sourcemaps inject --org arbisoft-m1 --project project-listings-backend ./dist && sentry-cli sourcemaps upload --org arbisoft-m1 --project project-listings-backend ./dist" + "sentry:login": "sentry-cli login --auth-token $SENTRY_AUTH_TOKEN", + "sentry:sourcemaps": "npm run sentry:login && sentry-cli sourcemaps inject --org arbisoft-m1 --project project-listings-backend ./dist && sentry-cli sourcemaps upload --org arbisoft-m1 --project project-listings-backend ./dist" }, "keywords": [], "author": "", From 8d7ccb8fb85bcee4f579b66c06e434ccf1602c5d Mon Sep 17 00:00:00 2001 From: omar-sarfraz Date: Tue, 24 Sep 2024 18:58:44 +0500 Subject: [PATCH 4/6] refactor: rename backend CI workflow --- .github/workflows/{Express CI.yml => Backend CI.yml} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename .github/workflows/{Express CI.yml => Backend CI.yml} (98%) diff --git a/.github/workflows/Express CI.yml b/.github/workflows/Backend CI.yml similarity index 98% rename from .github/workflows/Express CI.yml rename to .github/workflows/Backend CI.yml index ea71913..2fd3b08 100644 --- a/.github/workflows/Express CI.yml +++ b/.github/workflows/Backend CI.yml @@ -1,4 +1,4 @@ -name: Express CI +name: Backend CI on: push: From 902f6fb509447904fbacf19f650d9472942060ef Mon Sep 17 00:00:00 2001 From: omar-sarfraz Date: Tue, 24 Sep 2024 19:17:16 +0500 Subject: [PATCH 5/6] deployment(backend): add env vars in CI workflow --- .github/workflows/Backend CI.yml | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/.github/workflows/Backend CI.yml b/.github/workflows/Backend CI.yml index 2fd3b08..41391bd 100644 --- a/.github/workflows/Backend CI.yml +++ b/.github/workflows/Backend CI.yml @@ -21,6 +21,15 @@ jobs: env: ENVIRONMENT: ${{ secrets.ENVIRONMENT }} SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }} + DB_NAME: ${{ secrets.DB_NAME}} + DB_USER: ${{ secrets.DB_USER}} + DB_HOST: ${{ secrets.DB_HOST}} + DB_PORT: ${{ secrets.DB_PORT}} + DB_PASSWORD: ${{ secrets.DB_PASSWORD}} + PORT: ${{ secrets.PORT}} + KEY: ${{ secrets.KEY}} + SECTRET: ${{ secrets.SECTRET}} + GEMINI_API_KEY: ${{ secrets.GEMINI_API_KEY}} run: | docker compose build backend docker compose build graphql From 563f59d0a34e131d6b4ef2e0999eaf66cb9312bb Mon Sep 17 00:00:00 2001 From: omar-sarfraz Date: Wed, 25 Sep 2024 11:35:16 +0500 Subject: [PATCH 6/6] deployment(backend): add basic CD workflow --- .github/workflows/Backend-CD.yml | 31 +++++++++++++++++++ .../{Backend CI.yml => Backend-CI.yml} | 9 ------ 2 files changed, 31 insertions(+), 9 deletions(-) create mode 100644 .github/workflows/Backend-CD.yml rename .github/workflows/{Backend CI.yml => Backend-CI.yml} (68%) diff --git a/.github/workflows/Backend-CD.yml b/.github/workflows/Backend-CD.yml new file mode 100644 index 0000000..ebfb7d9 --- /dev/null +++ b/.github/workflows/Backend-CD.yml @@ -0,0 +1,31 @@ +name: Backend CD + +on: + workflow_run: + workflows: ["Backend CI"] + types: + - completed + +jobs: + build: + runs-on: self-hosted + + steps: + - uses: actions/checkout@v4 + + - name: Pull Docker image + run: sudo docker compose pull + + - name: Start Containers + env: + ENVIRONMENT: ${{ secrets.ENVIRONMENT }} + DB_NAME: ${{ secrets.DB_NAME}} + DB_USER: ${{ secrets.DB_USER}} + DB_HOST: ${{ secrets.DB_HOST}} + DB_PORT: ${{ secrets.DB_PORT}} + DB_PASSWORD: ${{ secrets.DB_PASSWORD}} + PORT: ${{ secrets.PORT}} + KEY: ${{ secrets.KEY}} + SECTRET: ${{ secrets.SECTRET}} + GEMINI_API_KEY: ${{ secrets.GEMINI_API_KEY}} + run: sudo docker compose up --force-recreate diff --git a/.github/workflows/Backend CI.yml b/.github/workflows/Backend-CI.yml similarity index 68% rename from .github/workflows/Backend CI.yml rename to .github/workflows/Backend-CI.yml index 41391bd..2fd3b08 100644 --- a/.github/workflows/Backend CI.yml +++ b/.github/workflows/Backend-CI.yml @@ -21,15 +21,6 @@ jobs: env: ENVIRONMENT: ${{ secrets.ENVIRONMENT }} SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }} - DB_NAME: ${{ secrets.DB_NAME}} - DB_USER: ${{ secrets.DB_USER}} - DB_HOST: ${{ secrets.DB_HOST}} - DB_PORT: ${{ secrets.DB_PORT}} - DB_PASSWORD: ${{ secrets.DB_PASSWORD}} - PORT: ${{ secrets.PORT}} - KEY: ${{ secrets.KEY}} - SECTRET: ${{ secrets.SECTRET}} - GEMINI_API_KEY: ${{ secrets.GEMINI_API_KEY}} run: | docker compose build backend docker compose build graphql