Skip to content

change

change #10

Workflow file for this run

name: Build and Deploy to GKE
on:
push:
branches:
- deployment-ci
env:
PROJECT_ID: ${{ secrets.GCP_PROJECT_ID }}
GKE_CLUSTER: ${{ secrets.GKE_CLUSTER_NAME }}
GKE_ZONE: ${{ secrets.GKE_CLUSTER_LOCATION }}
DOCKER_HUB_USERNAME: ${{ secrets.DOCKER_HUB_USERNAME }}
DEPLOYMENT_NAME: ranter-deploy-dev
IMAGE: ranter-dev-image
jobs:
setup-build-publish-deploy:
name: Setup, Build, Publish, and Deploy
runs-on: ubuntu-latest
environment: production
steps:
- name: Checkout
uses: actions/checkout@v2
# Setup gcloud CLI
- uses: google-github-actions/setup-gcloud@v0.2.1
with:
service_account_key: ${{ secrets.GCP_SA_KEY }}
project_id: ${{ secrets.GCP_PROJECT_ID }}
# helper for authentication
- run: |-
gcloud --quiet auth configure-docker
# Get the GKE credentials so we can deploy to the cluster
- name: Get GKE credentials
run: |-
gcloud container clusters get-credentials $GKE_CLUSTER --zone $GKE_ZONE --project $PROJECT_ID
# Build the Docker image
- name: Build
run: |-
docker build \
--tag "$DOCKER_HUB_USERNAME/$IMAGE:latest" \
--build-arg GITHUB_SHA="$GITHUB_SHA" \
--build-arg GITHUB_REF="$GITHUB_REF" \
.
# Log in to Docker Hub
- name: Log in to Docker Hub
run: |-
echo "${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}" | docker login -u "${{ secrets.DOCKER_HUB_USERNAME }}" --password-stdin
# Push the Docker image
- name: Push
run: |-
docker push "$DOCKER_HUB_USERNAME/$IMAGE:latest"
# Get the access token
- name: Get access token
id: get-access-token
run: |-
echo "::set-output name=access_token::$(gcloud auth print-access-token)"
# Deploy the Docker image to the GKE cluster
- name: Deploy
run: |-
kubectl set image deployment/$DEPLOYMENT_NAME $DEPLOYMENT_NAME=$DOCKER_HUB_USERNAME/$IMAGE:latest --token "${{ steps.get-access-token.outputs.access_token }}"
kubectl rollout status deployment/$DEPLOYMENT_NAME --token "${{ steps.get-access-token.outputs.access_token }}"
kubectl get services -o wide --token "${{ steps.get-access-token.outputs.access_token }}"