Skip to content

Commit

Permalink
Merge pull request #1968 from coronasafe/sainak/feat/staging-builds
Browse files Browse the repository at this point in the history
Add builds for staging branches
  • Loading branch information
gigincg authored Mar 13, 2024
2 parents 90565c2 + 140f0bc commit e435d9e
Showing 1 changed file with 37 additions and 98 deletions.
135 changes: 37 additions & 98 deletions .github/workflows/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ name: Deploy Care
on:
workflow_dispatch:
push:
tags:
- 'v*'
branches:
- master
- production
- develop
- staging
paths-ignore:
- "docs/**"

Expand Down Expand Up @@ -33,32 +35,35 @@ 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/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
Expand All @@ -75,14 +80,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: .
Expand Down Expand Up @@ -110,86 +115,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/develop'
name: Deploy to ECS API Egov
runs-on: ubuntu-latest
environment:
Expand Down Expand Up @@ -253,7 +191,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:
Expand Down Expand Up @@ -299,7 +238,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:
Expand Down Expand Up @@ -345,7 +284,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:
Expand Down Expand Up @@ -391,7 +330,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:
Expand Down Expand Up @@ -437,7 +376,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:
Expand Down Expand Up @@ -483,7 +422,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:
Expand Down Expand Up @@ -529,7 +468,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:
Expand Down

0 comments on commit e435d9e

Please sign in to comment.