|
| 1 | +name: Deploy to production |
| 2 | +on: |
| 3 | + workflow_run: |
| 4 | + workflows: ["Test"] |
| 5 | + branches: |
| 6 | + - release |
| 7 | + types: |
| 8 | + - completed |
| 9 | +env: |
| 10 | + PROJECT_ID: ${{ secrets.GKE_PROJECT }} |
| 11 | + GKE_CLUSTER: p5js-web-editor-cluster |
| 12 | + GKE_ZONE: us-east1-c |
| 13 | + DEPLOYMENT_NAME: web-editor-node |
| 14 | + IMAGE: ${{ secrets.DOCKER_USERNAME }}/p5.js-web-editor |
| 15 | +jobs: |
| 16 | + push_to_registry: |
| 17 | + environment: production |
| 18 | + name: Push Docker image to Docker Hub |
| 19 | + runs-on: ubuntu-latest |
| 20 | + steps: |
| 21 | + - name: Check out the repo |
| 22 | + uses: actions/checkout@v2 |
| 23 | + - name: Set up Docker Buildx |
| 24 | + uses: docker/setup-buildx-action@v1 |
| 25 | + - name: Login to Docker Hub |
| 26 | + uses: docker/login-action@v1 |
| 27 | + with: |
| 28 | + username: ${{ secrets.DOCKER_USERNAME }} |
| 29 | + password: ${{ secrets.DOCKER_PASSWORD }} |
| 30 | + - name: Build and push to Docker Hub |
| 31 | + uses: docker/build-push-action@v2 |
| 32 | + with: |
| 33 | + context: . |
| 34 | + file: ./Dockerfile |
| 35 | + pull: true |
| 36 | + push: true |
| 37 | + tags: | |
| 38 | + ${{ env.IMAGE }}:${{ github.sha }} |
| 39 | + ${{ env.IMAGE }}:latest |
| 40 | + target: production |
| 41 | + # Setup gcloud CLI |
| 42 | + - uses: google-github-actions/setup-gcloud@v0.2.0 |
| 43 | + with: |
| 44 | + service_account_key: ${{ secrets.GKE_SA_KEY }} |
| 45 | + project_id: ${{ secrets.GKE_PROJECT }} |
| 46 | + |
| 47 | + # Configure docker to use the gcloud command-line tool as a credential helper |
| 48 | + - run: |- |
| 49 | + gcloud --quiet auth configure-docker |
| 50 | + |
| 51 | + # Get the GKE credentials so we can deploy to the cluster |
| 52 | + - uses: google-github-actions/get-gke-credentials@v0.2.1 |
| 53 | + with: |
| 54 | + cluster_name: ${{ env.GKE_CLUSTER }} |
| 55 | + location: ${{ env.GKE_ZONE }} |
| 56 | + credentials: ${{ secrets.GKE_SA_KEY }} |
| 57 | + |
| 58 | + # Deploy the Docker image to the GKE cluster |
| 59 | + - name: Deploy |
| 60 | + run: |- |
| 61 | + kubectl set image deployment/$DEPLOYMENT_NAME web-editor-app=index.docker.io/$IMAGE:$GITHUB_SHA |
| 62 | + kubectl get services -o wide |
| 63 | +
|
0 commit comments