From 9df45fc00b97ac4ab2ea2514d11c8d1e99fb2569 Mon Sep 17 00:00:00 2001 From: Aakash Singh Date: Wed, 13 Mar 2024 13:38:35 +0530 Subject: [PATCH 1/3] Add builds for staging branches --- .github/workflows/deploy.yaml | 140 ++++++++++++---------------------- 1 file changed, 49 insertions(+), 91 deletions(-) diff --git a/.github/workflows/deploy.yaml b/.github/workflows/deploy.yaml index 6e760362cd6..863de2aaf8f 100644 --- a/.github/workflows/deploy.yaml +++ b/.github/workflows/deploy.yaml @@ -5,6 +5,8 @@ on: branches: - develop - master + tags: + - v* pull_request: branches: - develop @@ -38,9 +40,9 @@ jobs: uses: actions/cache@v3 with: path: /tmp/.buildx-cache - key: ${{ runner.os }}-buildx-${{ hashFiles('package-lock.json', 'Dockerfile') }} + key: ${{ runner.os }}-buildx-build-${{ hashFiles('package-lock.json', 'Dockerfile') }} restore-keys: | - ${{ runner.os }}-buildx- + ${{ runner.os }}-buildx-build- - name: Test build uses: docker/build-push-action@v3 @@ -60,132 +62,88 @@ jobs: rm -rf /tmp/.buildx-cache mv /tmp/.buildx-cache-new /tmp/.buildx-cache - build-staging: + build: needs: test - name: Build & Push Staging to container registries - if: github.ref == 'refs/heads/develop' + name: Build & Push to container registries runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - 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_owner }}/${{ env.IMAGE_NAME }} - ${{ secrets.DOCKER_HUB_USERNAME }}/${{ env.IMAGE_NAME }} + ghcr.io/${{ github.repository }} + ${{ secrets.DOCKER_HUB_USERNAME }}/${{ github.event.repository.name }} tags: | + 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/develop' }} - type=raw,value=latest-${{ github.run_number }}-{{date 'YYYYMMDD'}}-{{sha}} + 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 Docker Buildx - uses: docker/setup-buildx-action@v2 + - name: Setup QEMU + uses: docker/setup-qemu-action@v3 - - name: Cache Docker layers - uses: actions/cache@v3 - with: - path: /tmp/.buildx-cache - key: ${{ runner.os }}-buildx-${{ hashFiles('package-lock.json', 'Dockerfile') }} - restore-keys: | - ${{ runner.os }}-buildx- + - name: Setup Docker Buildx + uses: docker/setup-buildx-action@v3 - name: Login to DockerHub - uses: docker/login-action@v2 + 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@v2 + uses: docker/login-action@v3 with: registry: ghcr.io username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} - - name: Build image - uses: docker/build-push-action@v3 - with: - context: . - file: Dockerfile - push: true - tags: ${{ steps.meta.outputs.tags }} - cache-from: type=local,src=/tmp/.buildx-cache - cache-to: type=local,mode=max,dest=/tmp/.buildx-cache-new - - - name: Move cache - run: | - 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/master' - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - - name: Docker meta - id: meta - uses: docker/metadata-action@v4 - with: - images: | - ghcr.io/${{ github.repository_owner }}/${{ env.IMAGE_NAME }} - ${{ secrets.DOCKER_HUB_USERNAME }}/${{ env.IMAGE_NAME }} - tags: | - type=raw,value=production-latest,enable=${{ github.ref == 'refs/heads/master' }} - 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 Docker Buildx - uses: docker/setup-buildx-action@v2 - - name: Cache Docker layers - uses: actions/cache@v3 + uses: actions/cache@v4 with: path: /tmp/.buildx-cache - key: ${{ runner.os }}-buildx-${{ hashFiles('package-lock.json', 'Dockerfile') }} + key: ${{ runner.os }}-buildx-build-${{ hashFiles('package-lock.json', 'Dockerfile') }} restore-keys: | - ${{ runner.os }}-buildx- - - - name: Login to DockerHub - uses: docker/login-action@v2 - with: - username: ${{ secrets.DOCKER_HUB_USERNAME }} - password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }} - - - name: Login to GitHub Container Registry - uses: docker/login-action@v2 - with: - registry: ghcr.io - username: ${{ github.actor }} - password: ${{ secrets.GITHUB_TOKEN }} + ${{ runner.os }}-buildx-build- - - name: Build image - uses: docker/build-push-action@v3 + - name: Build and push image + uses: docker/build-push-action@v5 with: context: . file: Dockerfile push: true + provenance: false + platforms: linux/amd64,linux/arm64 tags: ${{ steps.meta.outputs.tags }} cache-from: type=local,src=/tmp/.buildx-cache - cache-to: type=local,mode=max,dest=/tmp/.buildx-cache-new + cache-to: type=local,dest=/tmp/.buildx-cache-new,mode=max - name: Move cache run: | rm -rf /tmp/.buildx-cache mv /tmp/.buildx-cache-new /tmp/.buildx-cache + notify-release: + needs: build + if: github.ref == 'refs/tags/v*' + name: Notify release + runs-on: ubuntu-latest + steps: + - name: Notify release + run: | + echo "Release ${{ github.sha }} is ready to be deployed to production" + 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: @@ -231,7 +189,7 @@ jobs: kubectl apply -f care-fe.yaml deploy-production-manipur: - needs: build-production + needs: notify-release name: Deploy to GKE Manipur runs-on: ubuntu-latest environment: @@ -277,7 +235,7 @@ jobs: kubectl apply -f care-fe.yaml deploy-production-karnataka: - needs: build-production + needs: notify-release name: Deploy to GKE Karnataka runs-on: ubuntu-latest environment: @@ -323,7 +281,7 @@ jobs: kubectl apply -f care-fe.yaml deploy-production-sikkim: - needs: build-production + needs: notify-release name: Deploy to GKE Sikkim runs-on: ubuntu-latest environment: @@ -369,7 +327,7 @@ jobs: kubectl apply -f care-fe.yaml deploy-production-assam: - needs: build-production + needs: notify-release name: Deploy to GKE Assam runs-on: ubuntu-latest environment: @@ -415,7 +373,7 @@ jobs: kubectl apply -f care-fe.yaml deploy-production-nagaland: - needs: build-production + needs: notify-release name: Deploy to GKE Nagaland runs-on: ubuntu-latest environment: @@ -461,7 +419,7 @@ jobs: kubectl apply -f care-fe.yaml deploy-production-meghalaya: - needs: build-production + needs: notify-release name: Deploy to GKE Meghalaya runs-on: ubuntu-latest environment: From 936d9c1f725e6f5d0528fad5c9c5714599c61d12 Mon Sep 17 00:00:00 2001 From: Aakash Singh Date: Wed, 13 Mar 2024 13:43:14 +0530 Subject: [PATCH 2/3] update cache action --- .github/workflows/deploy.yaml | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/.github/workflows/deploy.yaml b/.github/workflows/deploy.yaml index 863de2aaf8f..ab06106547a 100644 --- a/.github/workflows/deploy.yaml +++ b/.github/workflows/deploy.yaml @@ -31,25 +31,26 @@ jobs: runs-on: ubuntu-latest name: Test steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Set up Docker Buildx uses: docker/setup-buildx-action@v2 - name: Cache Docker layers - uses: actions/cache@v3 + uses: actions/cache@v4 with: path: /tmp/.buildx-cache - key: ${{ runner.os }}-buildx-build-${{ hashFiles('package-lock.json', 'Dockerfile') }} + key: ${{ runner.os }}-buildx-test-${{ hashFiles('package-lock.json', 'Dockerfile') }} restore-keys: | - ${{ runner.os }}-buildx-build- + ${{ runner.os }}-buildx-test- - name: Test build - uses: docker/build-push-action@v3 + uses: docker/build-push-action@v5 with: context: . file: Dockerfile push: false + provenance: false cache-from: type=local,src=/tmp/.buildx-cache cache-to: type=local,mode=max,dest=/tmp/.buildx-cache-new From e30fde26441dae0e751037ab172023575da78534 Mon Sep 17 00:00:00 2001 From: Aakash Singh Date: Wed, 13 Mar 2024 13:44:27 +0530 Subject: [PATCH 3/3] build on branches only --- .github/workflows/deploy.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/deploy.yaml b/.github/workflows/deploy.yaml index ab06106547a..8be67339b27 100644 --- a/.github/workflows/deploy.yaml +++ b/.github/workflows/deploy.yaml @@ -65,6 +65,7 @@ jobs: build: needs: test + if: github.ref == 'refs/heads/develop' || github.ref == 'refs/heads/staging' || github.ref == 'refs/tags/v*' name: Build & Push to container registries runs-on: ubuntu-latest steps: