Continuing to modify workflow/main.yml #28
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: Build and Deploy to Google Compute Engine | |
on: | |
push: | |
branches: [main] | |
jobs: | |
build-and-deploy: | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
node-version: [20.x] | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v2 | |
- name: Use Node.js ${{ matrix.node-version }} | |
uses: actions/setup-node@v3 | |
with: | |
node-version: ${{ matrix.node-version }} | |
- name: Install dependencies | |
run: npm ci | |
# Setup gcloud CLI | |
- uses: GoogleCloudPlatform/github-actions/setup-gcloud@v1 | |
with: | |
version: '290.0.1' | |
service_account_key: ${{ secrets.GCP_SA_KEY }} | |
project_id: ${{ secrets.GCP_PROJECT_ID }} | |
# Configure Docker to use the gcloud command-line tool as a credential | |
# helper for authentication | |
- run: gcloud --quiet auth configure-docker | |
# Build the Docker image | |
- name: Build | |
run: | | |
docker build --tag "gcr.io/${{ secrets.GCP_PROJECT_ID }}/${{ secrets.GCP_INSTANCE_NAME }}-image:${{ github.sha }}" . | |
# Push the Docker image to Google Container Registry | |
- name: Publish | |
run: | | |
docker push "gcr.io/${{ secrets.GCP_PROJECT_ID }}/${{ secrets.GCP_INSTANCE_NAME }}-image:${{ github.sha }}" | |
# Deploy the Docker container on GCE | |
- name: Deploy | |
run: | | |
gcloud compute instances update-container "${{ secrets.GCP_INSTANCE_NAME }}" \ | |
--zone "${{ secrets.GCP_INSTANCE_ZONE }}" \ | |
--container-image "gcr.io/${{ secrets.GCP_PROJECT_ID }}/${{ secrets.GCP_INSTANCE_NAME }}-image:${{ github.sha }}" |