From 9ecf566a7f93a960d92245005fc5242dd81de2d2 Mon Sep 17 00:00:00 2001 From: Aakash Singh Date: Wed, 13 Mar 2024 12:58:17 +0530 Subject: [PATCH 1/2] add builds for staging branches --- .github/workflows/deployment.yaml | 136 +++++++++--------------------- 1 file changed, 39 insertions(+), 97 deletions(-) diff --git a/.github/workflows/deployment.yaml b/.github/workflows/deployment.yaml index 762f965284..db925187e1 100644 --- a/.github/workflows/deployment.yaml +++ b/.github/workflows/deployment.yaml @@ -3,9 +3,12 @@ name: Deploy Care on: workflow_dispatch: push: + tags: + - 'v*' branches: - master - - production + - develop + - staging paths-ignore: - "docs/**" @@ -33,32 +36,37 @@ jobs: test: uses: ./.github/workflows/test-base.yml - build-staging: + build: needs: test - name: Build & Push Staging to container registries - if: github.ref == 'refs/heads/master' + name: Build & Push to container registries runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - - name: Docker meta + - name: Generate docker tags id: meta - uses: docker/metadata-action@v4 + uses: docker/metadata-action@v5 with: images: | ghcr.io/${{ github.repository }} ${{ secrets.DOCKER_HUB_USERNAME }}/${{ github.event.repository.name }} tags: | - type=raw,value=latest-${{ github.run_number }} + type=raw,value=production-latest,enable=${{ github.ref == 'refs/heads/v*' }} + type=raw,value=production-latest-${{ github.run_number }}-{{date 'YYYYMMDD'}}-{{sha}},enable=${{ github.ref == 'refs/heads/v*' }} + type=raw,value=staging-latest,enable=${{ github.ref == 'refs/heads/staging' }} + type=raw,value=staging-latest-${{ github.run_number }}-{{date 'YYYYMMDD'}}-{{sha}},enable=${{ github.ref == 'refs/heads/staging' }} + type=raw,value=latest,enable=${{ github.ref == 'refs/heads/master' }} + type=raw,value=latest-${{ github.run_number }},enable=${{ github.ref == 'refs/heads/master' }} + type=raw,value=latest,enable=${{ github.ref == 'refs/heads/develop' }} + type=raw,value=latest-${{ github.run_number }},enable=${{ github.ref == 'refs/heads/develop' }} type=semver,pattern={{version}} - type=semver,pattern={{major}}.{{minor}} flavor: | - latest=true + latest=false - - name: Set up QEMU + - name: Setup QEMU uses: docker/setup-qemu-action@v3 - - name: Set up Docker Buildx + - name: Setup Docker Buildx uses: docker/setup-buildx-action@v3 - name: Login to DockerHub @@ -75,14 +83,14 @@ jobs: password: ${{ secrets.GITHUB_TOKEN }} - name: Cache Docker layers - uses: actions/cache@v3 + uses: actions/cache@v4 with: path: /tmp/.buildx-cache - key: ${{ runner.os }}-buildx-${{ hashFiles('Pipfile.lock', 'docker/prod.Dockerfile') }} + key: ${{ runner.os }}-buildx-build-${{ hashFiles('Pipfile.lock', 'docker/prod.Dockerfile') }} restore-keys: | - ${{ runner.os }}-buildx- + ${{ runner.os }}-buildx-build- - - name: Build image + - name: Build and push image uses: docker/build-push-action@v5 with: context: . @@ -110,86 +118,19 @@ jobs: rm -rf /tmp/.buildx-cache mv /tmp/.buildx-cache-new /tmp/.buildx-cache - build-production: - needs: test - name: Build & Push Production to container registries - if: github.ref == 'refs/heads/production' + notify-release: + needs: build + if: github.ref == 'refs/tags/v*' + name: Notify release runs-on: ubuntu-latest steps: - - uses: actions/checkout@v4 - - - name: Docker meta - id: meta - uses: docker/metadata-action@v4 - with: - images: | - ghcr.io/${{ github.repository }} - ${{ secrets.DOCKER_HUB_USERNAME }}/${{ github.event.repository.name }} - tags: | - type=raw,value=production-latest,enable=${{ github.ref == 'refs/heads/production' }} - type=raw,value=production-latest-${{ github.run_number }}-{{date 'YYYYMMDD'}}-{{sha}} - type=semver,pattern={{version}} - type=semver,pattern={{major}}.{{minor}} - flavor: | - latest=false - - - name: Set up QEMU - uses: docker/setup-qemu-action@v3 - - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v3 - - - name: Login to DockerHub - uses: docker/login-action@v3 - with: - username: ${{ secrets.DOCKER_HUB_USERNAME }} - password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }} - - - name: Login to GitHub Container Registry - uses: docker/login-action@v3 - with: - registry: ghcr.io - username: ${{ github.actor }} - password: ${{ secrets.GITHUB_TOKEN }} - - - name: Cache Docker layers - uses: actions/cache@v3 - with: - path: /tmp/.buildx-cache - key: ${{ runner.os }}-buildx-${{ hashFiles('Pipfile.lock', 'docker/prod.Dockerfile') }} - restore-keys: | - ${{ runner.os }}-buildx- - - - name: Build image - uses: docker/build-push-action@v5 - with: - context: . - file: docker/prod.Dockerfile - push: true - provenance: false - platforms: linux/amd64,linux/arm64 - tags: ${{ steps.meta.outputs.tags }} - build-args: | - APP_VERSION=${{ github.sha }} - cache-from: type=local,src=/tmp/.buildx-cache - cache-to: type=local,dest=/tmp/.buildx-cache-new,mode=max - - - name: Create Sentry release - uses: getsentry/action-release@v1 - env: - SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }} - SENTRY_ORG: ${{ secrets.SENTRY_ORG }} - SENTRY_PROJECT: ${{ secrets.SENTRY_PROJECT }} - with: - version: ${{ github.sha }} - - - name: Move cache + - name: Notify release run: | - rm -rf /tmp/.buildx-cache - mv /tmp/.buildx-cache-new /tmp/.buildx-cache + echo "Release ${{ github.sha }} is ready to be deployed to production" deploy-staging-egov: - needs: build-staging + needs: build + if: github.ref == 'refs/heads/master' name: Deploy to ECS API Egov runs-on: ubuntu-latest environment: @@ -253,7 +194,8 @@ jobs: wait-for-service-stability: true deploy-staging-gcp: - needs: build-staging + needs: build + if: github.ref == 'refs/heads/staging' name: Deploy to staging GCP cluster runs-on: ubuntu-latest environment: @@ -299,7 +241,7 @@ jobs: kubectl apply -f care-celery-worker.yaml deploy-production-manipur: - needs: build-production + needs: notify-release name: Deploy to GKE Manipur runs-on: ubuntu-latest environment: @@ -345,7 +287,7 @@ jobs: kubectl apply -f care-celery-worker.yaml deploy-production-karnataka: - needs: build-production + needs: notify-release name: Deploy to GKE Karnataka runs-on: ubuntu-latest environment: @@ -391,7 +333,7 @@ jobs: kubectl apply -f care-celery-worker.yaml deploy-production-assam: - needs: build-production + needs: notify-release name: Deploy to GKE Assam runs-on: ubuntu-latest environment: @@ -437,7 +379,7 @@ jobs: kubectl apply -f care-celery-worker.yaml deploy-production-sikkim: - needs: build-production + needs: notify-release name: Deploy to GKE Sikkim runs-on: ubuntu-latest environment: @@ -483,7 +425,7 @@ jobs: kubectl apply -f care-celery-worker.yaml deploy-production-nagaland: - needs: build-production + needs: notify-release name: Deploy to GKE Nagaland runs-on: ubuntu-latest environment: @@ -529,7 +471,7 @@ jobs: kubectl apply -f care-celery-worker.yaml deploy-production-meghalaya: - needs: build-production + needs: notify-release name: Deploy to GKE Meghalaya runs-on: ubuntu-latest environment: From 140f0bc187fe40a78cad8cb06b6405eb6927b404 Mon Sep 17 00:00:00 2001 From: Aakash Singh Date: Wed, 13 Mar 2024 13:04:12 +0530 Subject: [PATCH 2/2] update branch names --- .github/workflows/deployment.yaml | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/.github/workflows/deployment.yaml b/.github/workflows/deployment.yaml index db925187e1..38d6537ef5 100644 --- a/.github/workflows/deployment.yaml +++ b/.github/workflows/deployment.yaml @@ -6,7 +6,6 @@ on: tags: - 'v*' branches: - - master - develop - staging paths-ignore: @@ -55,8 +54,6 @@ jobs: type=raw,value=production-latest-${{ github.run_number }}-{{date 'YYYYMMDD'}}-{{sha}},enable=${{ github.ref == 'refs/heads/v*' }} type=raw,value=staging-latest,enable=${{ github.ref == 'refs/heads/staging' }} type=raw,value=staging-latest-${{ github.run_number }}-{{date 'YYYYMMDD'}}-{{sha}},enable=${{ github.ref == 'refs/heads/staging' }} - type=raw,value=latest,enable=${{ github.ref == 'refs/heads/master' }} - type=raw,value=latest-${{ github.run_number }},enable=${{ github.ref == 'refs/heads/master' }} type=raw,value=latest,enable=${{ github.ref == 'refs/heads/develop' }} type=raw,value=latest-${{ github.run_number }},enable=${{ github.ref == 'refs/heads/develop' }} type=semver,pattern={{version}} @@ -130,7 +127,7 @@ jobs: deploy-staging-egov: needs: build - if: github.ref == 'refs/heads/master' + if: github.ref == 'refs/heads/develop' name: Deploy to ECS API Egov runs-on: ubuntu-latest environment: