Skip to content

add docs from gofr-web #19

add docs from gofr-web

add docs from gofr-web #19

Workflow file for this run

name: Workflow-Pipeline
on:
push:
paths:
- docs/**
branches:
- add-docs
pull_request:
branches:
- main
- development
env:
GCR_PROJECT: zs-products
APP_NAME: gofr-web
CLUSTER_NAME: products-cluster
STAGE_NAMESPACE: gofr-stage
PROD_NAMESPACE: gofr
REGISTRY: ghcr.io
jobs:
stage_build:
runs-on: ubuntu-latest
outputs:
image: '${{ steps.output-image.outputs.image }}'
strategy:
matrix:
node-version:
- 16.x
steps:
- uses: actions/checkout@v4
- name: Log in to the Container registry
uses: docker/login-action@v1
with:
registry: '${{ env.REGISTRY }}'
username: '${{ github.actor }}'
password: '${{ secrets.GITHUB_TOKEN }}'
- name: pull
run: |
docker pull ghcr.io/gofr-dev/website:workflow-package
- name: Login to GCR
uses: docker/login-action@v2
with:
registry: gcr.io
username: _json_key
password: ${{ secrets.GCR_KEY }}
- name: building docker image
uses: docker/build-push-action@v2
with:
tags: 'gcr.io/${{ env.GCR_PROJECT }}/${{ env.APP_NAME }}:${{ github.sha }}'
context: ./
file: ./docs/Dockerfile
push: true
- id: output-image
run: >-
echo "image=`echo gcr.io/${{ env.GCR_PROJECT }}/${{ env.APP_NAME
}}:${{ github.sha }}`" >> "$GITHUB_OUTPUT"
stage_deployment:
runs-on: ubuntu-latest
needs: stage_build
env:
image: '${{ needs.stage_build.outputs.image }}'
steps:
- name: Set up Cloud SDK
uses: google-github-actions/setup-gcloud@v0
with:
project_id: '${{ env.GCR_PROJECT }}'
service_account_key: '${{ secrets.DEPLOY_KEY }}'
export_default_credentials: true
- name: Update Kubectl component
run: gcloud --quiet components update kubectl
- name: Set GCloud Project and Fetch Cluster Credentials
run: gcloud container clusters get-credentials ${{ env.CLUSTER_NAME }} --zone=us-central1 --project=${{ env.GCR_PROJECT }}
- name: Set Deployment Image
run: kubectl set image deployment/${{ env.APP_NAME }} ${{ env.APP_NAME }}=${{ env.image }} --namespace ${{ env.STAGE_NAMESPACE }}
check-tag:
runs-on: ubuntu-latest
if: 'startsWith(github.ref, ''refs/tags/v'')'
outputs:
tag_exists: '${{ steps.tag-check.outputs.tag_exists }}'
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Set up Cloud SDK
uses: google-github-actions/setup-gcloud@v0
with:
project_id: '${{ env.GCR_PROJECT }}'
service_account_key: '${{ secrets.DEPLOY_KEY }}'
export_default_credentials: true
- name: Check if tag exists
id: tag-check
run: >
if gcloud container images describe gcr.io/${{ env.GCR_PROJECT }}/${{
env.APP_NAME }}:${{ github.sha }} 2>/dev/null; then
echo "tag_exists=true" >> "$GITHUB_OUTPUT"
else
echo "tag_exists=false" >> "$GITHUB_OUTPUT"
fi
- name: Print commit has value
run: |
echo "${{ github.sha }}"
- name: Print tag_exists value
run: |
echo "${{ steps.tag-check.outputs.tag_exists }}"
retag:
name: Retagging existing image
runs-on: ubuntu-latest
needs: check-tag
if: '${{ needs.check-tag.outputs.tag_exists == ''true'' }}'
outputs:
image: '${{ steps.output-image.outputs.image }}'
steps:
- name: Extract Release Tag
run: 'echo "RELEASE_VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV'
- name: Re tag and Push Docker Image to GCR
run: >
docker pull gcr.io/${{ env.GCR_PROJECT }}/${{ env.APP_NAME }}:${{
github.sha }}
docker tag gcr.io/${{ env.GCR_PROJECT }}/${{ env.APP_NAME }}:${{
github.sha }} gcr.io/${{ env.GCR_PROJECT }}/${{ env.APP_NAME }}:${{
env.RELEASE_VERSION }}
docker push gcr.io/${{ env.GCR_PROJECT }}/${{ env.APP_NAME }}:${{
env.RELEASE_VERSION }}
- id: output-image
run: >-
echo "image=`echo gcr.io/${{ env.GCR_PROJECT }}/${{ env.APP_NAME
}}:${{ env.RELEASE_VERSION }}`" >> "$GITHUB_OUTPUT"
# prod_deployment:
# runs-on: ubuntu-latest
# name: "\U0001F680 Deploy to Prod"
# needs: retag
# env:
# image: '${{ needs.retag.outputs.image }}'
# steps:
# - name: Extract Release Tag
# run: 'echo "RELEASE_VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV'
# - name: Set up Cloud SDK
# uses: google-github-actions/setup-gcloud@v0
# with:
# project_id: '${{ env.GCR_PROJECT }}'
# service_account_key: '${{ secrets.DEPLOY_KEY }}'
# export_default_credentials: true
# - name: Update Kubectl component
# run: gcloud --quiet components update kubectl
# - name: Set GCloud Project and Fetch Cluster Credentials
# run: >-
# gcloud container clusters get-credentials ${{ env.CLUSTER_NAME }}
# --zone=us-central1 --project=${{ env.GCR_PROJECT }}
# - name: Set Deployment Image for API
# run: >-
# kubectl set image deployment/${{ env.APP_NAME }} ${{ env.APP_NAME
# }}=${{ env.image }} --namespace ${{ env.PROD_NAMESPACE }}