Merge pull request #1203 from nidhey27/refactor/basic-auth-middleware #349
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Build and Deploy | |
on: | |
push: | |
tags: | |
- "v*.*.*" | |
branches: | |
- main | |
- development | |
env: | |
APP_NAME: gofr-website | |
WEBSITE_REGISTRY: ghcr.io | |
GAR_PROJECT: raramuri-tech | |
GAR_REGISTRY: kops-dev | |
CLUSTER_NAME: raramuri-tech | |
CLUSTER_PROJECT: raramuri-tech | |
NAMESPACE: gofr-dev | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
name: 🔧Build | |
steps: | |
- name: Checkout Code | |
uses: actions/checkout@v4 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: Log in to the GitHub Container registry | |
uses: docker/login-action@v3 | |
with: | |
registry: ${{ env.WEBSITE_REGISTRY }} | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Download UI Image | |
run: | | |
docker pull ${{ env.WEBSITE_REGISTRY }}/gofr-dev/website:latest | |
- name: Build Image | |
uses: docker/build-push-action@v6 | |
with: | |
push: false | |
context: ./ | |
file: ./docs/Dockerfile | |
dockerize: | |
if: ${{ startsWith(github.ref, 'refs/tags/v')}} | |
runs-on: ubuntu-latest | |
outputs: | |
image: ${{ steps.output-image.outputs.image }} | |
name: 🐳 Dockerize | |
needs: build | |
steps: | |
- name: Checkout Code | |
uses: actions/checkout@v4 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: Login to GAR | |
uses: docker/login-action@v3 | |
with: | |
registry: us-central1-docker.pkg.dev | |
username: _json_key | |
password: ${{ secrets.deploy_key }} | |
- name: Log in to the GitHub Container registry | |
uses: docker/login-action@v3 | |
with: | |
registry: ${{ env.WEBSITE_REGISTRY }} | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Download UI Image | |
run: | | |
docker pull ${{ env.WEBSITE_REGISTRY }}/gofr-dev/website:latest | |
- name: Build and Push Image Stage | |
uses: docker/build-push-action@v6 | |
with: | |
push: true | |
context: ./ | |
file: ./docs/Dockerfile | |
tags: us-central1-docker.pkg.dev/${{ env.GAR_PROJECT }}/${{ env.GAR_REGISTRY }}/${{ env.APP_NAME }}:${{ github.sha }} | |
- id: output-image | |
run: echo "image=`echo us-central1-docker.pkg.dev/${{ env.GAR_PROJECT }}/${{ env.GAR_REGISTRY }}/${{ env.APP_NAME }}:${{ github.sha }}`" >> "$GITHUB_OUTPUT" | |
deployment: | |
runs-on: ubuntu-latest | |
name: 🚀 Deploy | |
needs: dockerize | |
container: | |
image: ghcr.io/zopsmart/gha-images:deployments-0.1.3 | |
options: --rm | |
env: | |
image: ${{needs.dockerize.outputs.image}} | |
steps: | |
- name: Checkout Code | |
uses: actions/checkout@v4 | |
- name: Authorize to GCP service account | |
uses: google-github-actions/auth@v2 | |
with: | |
credentials_json: ${{ secrets.deploy_key }} | |
- name: Set GCloud Project and Fetch Cluster Credentials | |
run: gcloud container clusters get-credentials ${{ env.CLUSTER_NAME }} --region=us-central1 --project=${{ env.CLUSTER_PROJECT }} | |
- name: Update Deployment Image | |
run: kubectl set image deployment/${{ env.APP_NAME }} ${{ env.APP_NAME }}=${{ env.image }} --namespace ${{ env.NAMESPACE }} |