Skip to content

spuricous workdir

spuricous workdir #2

Workflow file for this run

# Copyright 2020 Google, LLC.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
name: Build and Deploy to Google Compute Engine
on:
push:
branches:
- cloud-run
env:
PROJECT_ID: ${{ secrets.GCE_PROJECT }}
GCE_INSTANCE: rollbot-vm
GCE_INSTANCE_ZONE: us-central1-a
jobs:
setup-build-publish-deploy:
name: Setup, Build, Publish, and Deploy
runs-on: ubuntu-latest
# Add "id-token" with the intended permissions.
permissions:
contents: 'read'
id-token: 'write'
steps:
- name: Checkout
uses: actions/checkout@v3
- id: 'auth'
uses: 'google-github-actions/auth@v1'
with:
credentials_json: '${{ secrets.GCE_SA_KEY }}'
- name: Set up Cloud SDK
uses: google-github-actions/setup-gcloud@v1
- run: |-
gcloud --quiet auth configure-docker
- name: Build
run: |-
docker build --tag "gcr.io/$PROJECT_ID/$GCE_INSTANCE-image:$GITHUB_SHA" .
- name: Publish
run: |-
docker push "gcr.io/$PROJECT_ID/$GCE_INSTANCE-image:$GITHUB_SHA"
- name: Update startup script to prune and update IP address
run: |-
gcloud compute instances add-metadata $GCE_INSTANCE \
--zone "$GCE_INSTANCE_ZONE" \
--metadata=startup-script="#! /bin/bash
docker image prune -af"
- name: Deploy
run: |-
gcloud compute instances update-container "$GCE_INSTANCE" \
--zone "$GCE_INSTANCE_ZONE" \
--container-image "gcr.io/$PROJECT_ID/$GCE_INSTANCE-image:$GITHUB_SHA"
- name: Purge GCR images
run: |-
gcloud container images list-tags gcr.io/$PROJECT_ID/$GCE_INSTANCE-image \
--format="get(digest)" --filter="NOT tags=$GITHUB_SHA" | \
awk -v image_path="gcr.io/$PROJECT_ID/$GCE_INSTANCE-image@" '{print image_path $1}' | \
xargs -r gcloud container images delete --force-delete-tags --quiet