65 lines
2.0 KiB
YAML
65 lines
2.0 KiB
YAML
name: Build and deploy to GKE
|
|
|
|
on:
|
|
push:
|
|
branches:
|
|
- "k8s"
|
|
workflow_dispatch:
|
|
|
|
env:
|
|
PROJECT_ID: ${{ secrets.GKE_PROJECT }}
|
|
GKE_CLUSTER: ${{ secrets.GKE_CLUSTER }}
|
|
GKE_ZONE: ${{ secrets.GKE_ZONE }}
|
|
DEPLOYMENT_NAME: v3-liq
|
|
IMAGE: v3-liq
|
|
|
|
jobs:
|
|
setup-build-publish-deploy:
|
|
name: Setup, Build, Publish, and Deploy
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- name: Checkout
|
|
uses: actions/checkout@v2
|
|
|
|
# Setup gcloud CLI
|
|
- uses: google-github-actions/setup-gcloud@v0
|
|
with:
|
|
service_account_key: ${{ secrets.GKE_SA_KEY }}
|
|
project_id: ${{ secrets.GKE_PROJECT }}
|
|
|
|
# Configure docker to use the gcloud command-line tool as a credential helper
|
|
- run: |-
|
|
gcloud --quiet auth configure-docker
|
|
|
|
# Get the GKE credentials so we can deploy to the cluster
|
|
- uses: google-github-actions/get-gke-credentials@v0
|
|
with:
|
|
cluster_name: ${{ env.GKE_CLUSTER }}
|
|
location: ${{ env.GKE_ZONE }}
|
|
credentials: ${{ secrets.GKE_SA_KEY }}
|
|
|
|
# Build the Docker image
|
|
- name: Build
|
|
run: |-
|
|
docker build \
|
|
--tag "gcr.io/$PROJECT_ID/$IMAGE:$GITHUB_SHA" \
|
|
--build-arg GITHUB_SHA="$GITHUB_SHA" \
|
|
--build-arg GITHUB_REF="$GITHUB_REF" \
|
|
.
|
|
|
|
# Push the Docker image to gcr
|
|
- name: Publish
|
|
run: |-
|
|
docker push "gcr.io/$PROJECT_ID/$IMAGE:$GITHUB_SHA"
|
|
# Set up kustomize
|
|
- name: Set up Kustomize
|
|
run: |-
|
|
curl --location https://github.com/kubernetes-sigs/kustomize/releases/download/kustomize%2Fv4.2.0/kustomize_v4.2.0_linux_amd64.tar.gz | tar xz
|
|
chmod u+x ./kustomize
|
|
# Deploy GKE cluster
|
|
- name: Deploy
|
|
run: |-
|
|
./kustomize edit set image gcr.io/PROJECT_ID/IMAGE:TAG=gcr.io/$PROJECT_ID/$IMAGE:$GITHUB_SHA
|
|
./kustomize build . | kubectl apply -f -
|
|
kubectl rollout status deployment/$DEPLOYMENT_NAME
|
|
kubectl get services -o wide |