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 to GKE new | |
on: | |
push: | |
branches: | |
- main | |
env: | |
PROJECT_ID: jokr-d-gke-prj | |
PROJECT_NUMBER: 1007977410651 | |
USE_GKE_GCLOUD_AUTH_PLUGIN: True | |
CLUSTER: joker-gke-dev | |
CLUSTER_REGION: us-central1 | |
REPOSITORY: jokr-repository | |
REPOSITORY_REGION: us-central1 | |
IMAGE: clouddemo | |
jobs: | |
build: | |
runs-on: self-hosted | |
permissions: | |
id-token: write | |
contents: read | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
# | |
# Authenticate to Google Cloud using workload identity federation | |
# | |
- id: 'auth' | |
name: 'Obtain access token by using workload identity federation' | |
uses: 'google-github-actions/[email protected]' | |
with: | |
create_credentials_file: true | |
token_format: access_token | |
install_components: "gke-gcloud-auth-plugin" | |
project_id: ${{ env.PROJECT_ID }} | |
workload_identity_provider: projects/${{ env.PROJECT_NUMBER }}/locations/global/workloadIdentityPools/github-actions-wrkld-id-pool/providers/jokr-wlidp-prvdr-dev | |
service_account: [email protected] | |
- name: Connect to Artifact Registry | |
run: |- | |
echo ${{ steps.auth.outputs.access_token }} | docker login -u oauth2accesstoken --password-stdin https://${{ env.REPOSITORY_REGION }}-docker.pkg.dev | |
- name: Connect to GKE | |
uses: google-github-actions/get-gke-credentials@v2 | |
with: | |
cluster_name: ${{ env.CLUSTER }} | |
location: ${{ env.CLUSTER_REGION }} | |
use_internal_ip: true | |
# The KUBECONFIG env var is automatically exported and picked up by kubectl. | |
- id: 'get-pods' | |
run: 'kubectl get pods -A' | |
# | |
# Build the .NET code | |
# | |
- name: Build solution | |
run: |- | |
dotnet publish applications/clouddemo/netcore/CloudDemo.MvcCore.sln \ | |
--configuration Release \ | |
--framework net6.0 | |
# | |
# Build the Docker image and push it to Artifact Registry | |
# | |
- name: Create image tag | |
run: echo "IMAGE_TAG=${{ env.REPOSITORY_REGION }}-docker.pkg.dev/${{ env.PROJECT_ID }}/${{ env.REPOSITORY }}/${{ env.IMAGE }}:$GITHUB_SHA" >> $GITHUB_ENV | |
- name: Lock image version in deployment.yaml | |
run: sed -i 's|CLOUDDEMO_IMAGE|${{ env.IMAGE_TAG }}|g' applications/clouddemo/netcore/deployment.yaml | |
- name: Build Docker image | |
run: docker build --tag "${{ env.IMAGE_TAG }}" applications/clouddemo/netcore | |
- name: Publish Docker image to Google Artifact Registry | |
run: docker push "${{ env.IMAGE_TAG }}" | |
# | |
# Deploy to GKE | |
# | |
- name: Deploy to GKE | |
run: kubectl apply -f applications/clouddemo/netcore/deployment.yaml | |
# run: kubectl get pods -A | |