From 89e0121090f155ad6b633a3e884adcfe1d0c71ad Mon Sep 17 00:00:00 2001 From: Chafah Sani Date: Sat, 30 May 2026 16:35:12 +0200 Subject: [PATCH 1/3] feat: add CI staging workflow for non-main branches --- .github/workflows/ci.yml | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 .github/workflows/ci.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..1824257 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,36 @@ +name: CI - Staging + +on: + push: + branches-ignore: [main] + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-node@v4 + with: + node-version: '20' + - run: corepack enable && corepack prepare pnpm@10.33.0 --activate + - run: pnpm install --no-frozen-lockfile + - run: pnpm build + - run: pnpm test + + docker: + needs: build + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: docker/setup-buildx-action@v2 + - uses: docker/login-action@v2 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_PASSWORD }} + - uses: docker/build-push-action@v4 + with: + context: . + push: true + tags: | + chafah/nodejs-app:${{ github.ref_name }}-staging + chafah/nodejs-app:staging From ff590ad125d8c2b12785832262c807d0117fc6a8 Mon Sep 17 00:00:00 2001 From: Chafah Sani Date: Sat, 30 May 2026 16:37:07 +0200 Subject: [PATCH 2/3] fix: sanitize branch name in docker tag --- .github/workflows/ci.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1824257..9d033e4 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -22,6 +22,9 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 + - name: Set tag + id: meta + run: echo "branch=$(echo ${{ github.ref_name }} | sed 's/\//-/g')" >> $GITHUB_OUTPUT - uses: docker/setup-buildx-action@v2 - uses: docker/login-action@v2 with: @@ -32,5 +35,5 @@ jobs: context: . push: true tags: | - chafah/nodejs-app:${{ github.ref_name }}-staging + chafah/nodejs-app:${{ steps.meta.outputs.branch }}-staging chafah/nodejs-app:staging From 67228bdd7c5c65e1c628af0f12b5bc16c6b65014 Mon Sep 17 00:00:00 2001 From: Chafah Sani Date: Sat, 30 May 2026 16:44:58 +0200 Subject: [PATCH 3/3] feat: CI=dev, staging=release/*, prod=main+hotfix/* --- .github/workflows/ci-cd.yml | 4 +- .github/workflows/ci.yml | 4 +- .github/workflows/deploy-staging.yml | 72 ++++++++++++++++++++++++++++ 3 files changed, 77 insertions(+), 3 deletions(-) create mode 100644 .github/workflows/deploy-staging.yml diff --git a/.github/workflows/ci-cd.yml b/.github/workflows/ci-cd.yml index 33825ad..ceccb79 100644 --- a/.github/workflows/ci-cd.yml +++ b/.github/workflows/ci-cd.yml @@ -2,7 +2,9 @@ name: Deploy to Production on: push: - branches: [main] + branches: + - main + - 'hotfix/**' jobs: build: diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9d033e4..65a1c46 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -35,5 +35,5 @@ jobs: context: . push: true tags: | - chafah/nodejs-app:${{ steps.meta.outputs.branch }}-staging - chafah/nodejs-app:staging + chafah/nodejs-app:${{ steps.meta.outputs.branch }}-dev + chafah/nodejs-app:dev diff --git a/.github/workflows/deploy-staging.yml b/.github/workflows/deploy-staging.yml new file mode 100644 index 0000000..3ebb285 --- /dev/null +++ b/.github/workflows/deploy-staging.yml @@ -0,0 +1,72 @@ +name: Deploy to Staging + +on: + push: + branches: + - 'release/**' + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-node@v4 + with: + node-version: '20' + - run: corepack enable && corepack prepare pnpm@10.33.0 --activate + - run: pnpm install --no-frozen-lockfile + - run: pnpm build + - run: pnpm test + + docker: + needs: build + runs-on: ubuntu-latest + env: + NODE_ENV: staging + outputs: + image_tag: ${{ steps.meta.outputs.tag }} + steps: + - uses: actions/checkout@v4 + - name: Set image tag + id: meta + run: | + BRANCH=$(echo ${{ github.ref_name }} | sed 's/\//-/g') + echo "tag=${BRANCH}-$(date +'%Y-%m-%d-%H%M%S')-staging" >> $GITHUB_OUTPUT + - uses: docker/setup-buildx-action@v2 + - uses: docker/login-action@v2 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_PASSWORD }} + - uses: docker/build-push-action@v4 + with: + context: . + push: true + build-args: NODE_ENV=staging + tags: | + chafah/nodejs-app:${{ steps.meta.outputs.tag }} + chafah/nodejs-app:staging + + deploy: + needs: docker + runs-on: ubuntu-latest + permissions: + contents: write + steps: + - uses: actions/checkout@v4 + - uses: aws-actions/configure-aws-credentials@v4 + with: + aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} + aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} + aws-region: ${{ secrets.AWS_REGION }} + - run: aws eks update-kubeconfig --name landmark-eks-stg --region ${{ secrets.AWS_REGION }} + - name: Update image tag in k8s manifest + run: | + sed -i "s|image:.*|image: chafah/nodejs-app:${{ needs.docker.outputs.image_tag }}|" k8s/05-service/deployment-service.yaml + - name: Commit updated manifest to repo + run: | + git config user.name "github-actions" + git config user.email "github-actions@github.com" + git add k8s/05-service/deployment-service.yaml + git commit -m "chore: update staging image to ${{ needs.docker.outputs.image_tag }}" || true + git push + - run: kubectl apply -f k8s/05-service/deployment-service.yaml