Skip to content

Commit a8dc4ae

Browse files
Create deploy-to-gke.yaml
Signed-off-by: John Osborne <[email protected]>
1 parent 5826afc commit a8dc4ae

File tree

1 file changed

+66
-0
lines changed

1 file changed

+66
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
name: Release Latest Changes
2+
3+
on:
4+
workflow_dispatch:
5+
push:
6+
branches: [ main ]
7+
8+
jobs:
9+
release:
10+
runs-on: ubuntu-latest
11+
permissions:
12+
contents: read
13+
packages: write
14+
id-token: write
15+
16+
# The "_DEFAULT" env vars below allow this to work out-of-the-box under "chainguard-dev" org.
17+
# The "_OVERRIDE" env vars below override the default ones, and are sourced from GitHub secrets.
18+
# If running this workflow from a fork, you must set the following secrets in your repository settings:
19+
# PROJECT_ID, WORKLOAD_IDENTITY_PROVIDER, SERVICE_ACCOUNT_NAME, CLUSTER_NAME, CLUSTER_LOCATION
20+
env:
21+
# Google Cloud project ID
22+
PROJECT_ID_DEFAULT: josborne-gke-demo
23+
# To properly set this up, see "Setting up Identity Federation for GitHub Actions"
24+
# https://cloud.google.com/blog/products/identity-security/enabling-keyless-authentication-from-github-actions
25+
WORKLOAD_IDENTITY_PROVIDER_DEFAULT: projects/895401504149/locations/global/workloadIdentityPools/github-actions-pool/providers/github-actions-provider
26+
# This service account must have write access to GCR and the GKE cluster
27+
SERVICE_ACCOUNT_NAME_DEFAULT: github-actions
28+
SERVICE_ACCOUNT_NAME_OVERRIDE: ${{ secrets.SERVICE_ACCOUNT_NAME }}
29+
# GKE cluster details
30+
CLUSTER_NAME_DEFAULT: josborne-gke-demo
31+
CLUSTER_LOCATION_DEFAULT: us-central1
32+
33+
steps:
34+
- name: 'Setup env vars'
35+
run: |
36+
echo "PROJECT_ID=${PROJECT_ID_DEFAULT}" >> $GITHUB_ENV
37+
echo "WORKLOAD_IDENTITY_PROVIDER=${WORKLOAD_IDENTITY_PROVIDER_DEFAULT}" >> $GITHUB_ENV
38+
echo "SERVICE_ACCOUNT_NAME=${SERVICE_ACCOUNT_NAME_DEFAULT}" >> $GITHUB_ENV
39+
echo "CLUSTER_NAME=${CLUSTER_NAME_DEFAULT}" >> $GITHUB_ENV
40+
echo "CLUSTER_LOCATION=${CLUSTER_LOCATION_DEFAULT}" >> $GITHUB_ENV
41+
- uses: actions/checkout@v4
42+
- name: 'Authenticate to Google Cloud'
43+
uses: 'google-github-actions/auth@v2'
44+
with:
45+
# Default is to generate a key file, which is automatically configured for use with gcloud.
46+
workload_identity_provider: '${{ env.WORKLOAD_IDENTITY_PROVIDER }}'
47+
service_account: '${{ env.SERVICE_ACCOUNT_NAME }}@${{ env.PROJECT_ID }}.iam.gserviceaccount.com'
48+
49+
- name: 'Set up Cloud SDK'
50+
uses: 'google-github-actions/setup-gcloud@v2'
51+
52+
- name: 'Use gcloud CLI'
53+
run: 'gcloud info'
54+
55+
- id: 'get-credentials'
56+
uses: 'google-github-actions/get-gke-credentials@v2'
57+
with:
58+
cluster_name: ${{ env.CLUSTER_NAME }}
59+
location: ${{ env.CLUSTER_LOCATION }}
60+
project_id: ${{ env.PROJECT_ID }}
61+
62+
# The KUBECONFIG env var is automatically exported and picked up by kubectl.
63+
- id: 'get-pods'
64+
run: 'kubectl get pods'
65+
# CONTAINER_NAME="$(kubectl get deployment ${DEPLOYMENT_NAME} -o json 2>/dev/null | jq -r '.spec.template.spec.containers[0].name')"
66+
# kubectl set image deployment/${DEPLOYMENT_NAME} ${CONTAINER_NAME}=$(cat ko.images)

0 commit comments

Comments
 (0)