Deploy to staging #300
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: 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@v2 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v1 | |
- name: Login to Docker Hub | |
uses: docker/login-action@v1 | |
with: | |
username: ${{ secrets.DOCKER_USERNAME }} | |
password: ${{ secrets.DOCKER_PASSWORD }} | |
- name: Build and push to Docker Hub | |
uses: docker/build-push-action@v2 | |
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/[email protected] | |
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/[email protected] | |
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 |