fix app_name env #8
Workflow file for this run
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 Test Service | |
on: | |
push: | |
branches: | |
- main | |
- development | |
tags: | |
- "*" | |
pull_request: | |
branches: | |
- main | |
- development | |
env: | |
app_name: test-service | |
jobs: | |
build: | |
name: Build | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
with: | |
fetch-depth: 0 | |
- name: Set up Go 1.21 | |
uses: actions/setup-go@v4 | |
with: | |
go-version: 1.21 | |
id: Go | |
- name: Get dependencies | |
run: | | |
go mod download | |
- name: Build | |
run: | | |
CGO_ENABLED=0 GOOS=linux go build -ldflags '-extldflags "-static"' -o build/test-service . | |
- name: Upload Artifacts | |
uses: actions/upload-artifact@v2 | |
with: | |
name: artifacts | |
path: build | |
dockerize_stage: | |
runs-on: ubuntu-latest | |
name: π³ Dockerize - Stage | |
needs: [ build ] | |
if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }} | |
steps: | |
- name: Checkout Code | |
uses: actions/checkout@v3 | |
- name: Download Artifacts | |
uses: actions/download-artifact@v3 | |
with: | |
name: artifacts | |
path: build | |
- name: Login to GCR | |
uses: docker/login-action@v2 | |
with: | |
registry: gcr.io | |
username: _json_key | |
password: ${{ secrets.GCR_KEY }} | |
- name: Build and Push Image | |
uses: docker/build-push-action@v3 | |
with: | |
push: true | |
context: ./ | |
file: ./Dockerfile | |
tags: gcr.io/zs-products/test-service:${{ github.sha }} | |
- uses: actions/upload-artifact@v2 | |
with: | |
name: variables | |
path: variables | |
dockerize_prod: | |
runs-on: ubuntu-latest | |
name: π³ Dockerize - Prod | |
needs: [ build ] | |
if: startsWith(github.ref,'refs/tags/v') | |
steps: | |
- name: Extract Release Tag | |
run: echo "RELEASE_VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV | |
- name: Checkout Code | |
uses: actions/checkout@v3 | |
- name: Download Artifacts | |
uses: actions/download-artifact@v3 | |
with: | |
name: artifacts | |
path: build | |
- name: Login to GCR | |
uses: docker/login-action@v2 | |
with: | |
registry: gcr.io | |
username: _json_key | |
password: ${{ secrets.GCR_KEY }} | |
- name: Build and Push Image | |
uses: docker/build-push-action@v3 | |
with: | |
push: true | |
context: ./ | |
file: ./Dockerfile | |
tags: gcr.io/zs-products/test-service:${{ env.RELEASE_VERSION }} | |
- uses: actions/upload-artifact@v2 | |
with: | |
name: variables | |
path: variables | |
stage_deployment: | |
runs-on: ubuntu-latest | |
name: π Deploy to Stage | |
needs: [ dockerize_stage ] | |
if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }} | |
steps: | |
- name: Set up Cloud SDK | |
uses: google-github-actions/setup-gcloud@v0 | |
with: | |
project_id: zs-products | |
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 products-cluster --zone=us-central1 --project=zs-products | |
- name: Set Deployment Image | |
run: kubectl set image deployment/${{ env.app_name }} ${{ env.app_name }}=gcr.io/zs-products/${{ env.app_name }}:${{ github.sha }} --namespace gofr-stage | |
prod_deployment: | |
runs-on: ubuntu-latest | |
name: π Deploy to Prod | |
needs: [ dockerize_prod ] | |
if: startsWith(github.ref,'refs/tags/v') | |
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: zs-products | |
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 products-cluster --zone=us-central1 --project=zs-products | |
- name: Set Deployment Image | |
run: kubectl set image deployment/${{ env.app_name }} ${{ env.app_name }}=gcr.io/zs-products/${{ env.app_name }}:${{ env.RELEASE_VERSION }} --namespace gofr |