v2.26.3 #50
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 & Deploy | |
on: | |
release: | |
types: [published] | |
jobs: | |
build: | |
name: Build | |
runs-on: ubuntu-latest | |
steps: | |
- name: Login to Registry | |
run: echo ${{ secrets.GITHUB_TOKEN }} | docker login ghcr.io -u ${{ github.actor }} --password-stdin | |
- name: Check out code into the Go module directory | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: Build image | |
run: docker build -t ghcr.io/${GITHUB_REPOSITORY}:${GITHUB_REF#refs/tags/v} . | |
- name: Publish image | |
run: docker push --all-tags ghcr.io/${GITHUB_REPOSITORY} | |
- name: Logout | |
run: docker logout ghcr.io | |
deploy: | |
name: Deploy | |
runs-on: ubuntu-latest | |
needs: build | |
permissions: | |
contents: read | |
id-token: write | |
env: | |
NAMESPACE: production | |
DEPLOYMENT: rest-api-v2 | |
CONTAINER: rest-api | |
steps: | |
- name: Check out | |
uses: actions/checkout@v4 | |
- name: Authenticate to Google Cloud | |
uses: google-github-actions/auth@v1 | |
with: | |
workload_identity_provider: '${{ secrets.GC_WORKLOAD_IDENTITY_PROVIDER }}' | |
service_account: '${{ secrets.GC_SERVICE_ACCOUNT }}' | |
- name: Get GKE cluster credentials | |
uses: google-github-actions/get-gke-credentials@v1 | |
with: | |
cluster_name: '${{ secrets.GC_GKE_CLUSTER_NAME }}' | |
location: '${{ secrets.GC_GKE_CLUSTER_LOCATION }}' | |
- name: Deploy image | |
run: kubectl -n ${NAMESPACE} set image deployment/${DEPLOYMENT} ${CONTAINER}=ghcr.io/${GITHUB_REPOSITORY}:${GITHUB_REF#refs/tags/v} | |
- name: Check rollout | |
if: success() | |
run: kubectl -n ${NAMESPACE} rollout status deployment/${DEPLOYMENT} -w --timeout=5m | |
- name: Roll back | |
if: failure() | |
run: kubectl -n ${NAMESPACE} rollout undo deployment/${DEPLOYMENT} |