Skip to content

Deploy to staging

Deploy to staging #584

name: Deploy to staging
on:
workflow_run:
workflows: ["Test"]
branches:
- develop
types:
- completed
env:
PROJECT_ID: ${{ secrets.GKE_PROJECT }}
GKE_CLUSTER: p5-gke-cluster
GKE_ZONE: us-east4
DEPLOYMENT_NAME: web-editor-node
IMAGE: ${{ secrets.DOCKER_USERNAME }}/p5.js-web-editor-staging
jobs:
push_to_registry:
environment: staging
name: Push Docker image to Docker Hub
runs-on: ubuntu-latest
steps:
- name: Check out the repo
uses: actions/checkout@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Login to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Build and push to Docker Hub
uses: docker/build-push-action@v4
with:
context: .
file: ./Dockerfile
pull: true
push: true
tags: |
${{ env.IMAGE }}:${{ github.sha }}
${{ env.IMAGE }}:latest
target: production
# Setup gcloud CLI
- uses: google-github-actions/setup-gcloud@v0.2.0
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.2.1
with:
cluster_name: ${{ env.GKE_CLUSTER }}
location: ${{ env.GKE_ZONE }}
credentials: ${{ secrets.GKE_SA_KEY }}
# Deploy the Docker image to the GKE cluster
- name: Deploy
run: |-
kubectl set image deployment/$DEPLOYMENT_NAME web-editor-app=index.docker.io/$IMAGE:$GITHUB_SHA --namespace=staging
kubectl get services -o wide