61 lines
2.0 KiB
YAML
61 lines
2.0 KiB
YAML
name: CI
|
|
|
|
on:
|
|
push:
|
|
|
|
env:
|
|
PROJECT_ID: zealous-zebra
|
|
|
|
jobs:
|
|
build:
|
|
name: Google Cloud / Test, Build, and Deploy
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
|
|
- name: Checkout
|
|
uses: actions/checkout@master
|
|
|
|
- name: Set project and image names
|
|
run: |
|
|
SHORT_BRANCH_NAME=$(expr $GITHUB_REF : '.*/\(.*\)') && \
|
|
SHORT_BRANCH_NAME=${SHORT_BRANCH_NAME,,} && \
|
|
BRANCH_NAME=$GITHUB_REPOSITORY/$SHORT_BRANCH_NAME && \
|
|
BRANCH_NAME=${BRANCH_NAME,,} && \
|
|
echo "::set-env name=SHORT_BRANCH_NAME::$SHORT_BRANCH_NAME" && \
|
|
echo "::set-env name=BRANCH_NAME::$BRANCH_NAME" && \
|
|
echo "::set-env name=SHA7::$(git rev-parse --short=7 $GITHUB_SHA)"
|
|
|
|
# Setup gcloud CLI
|
|
- uses: GoogleCloudPlatform/github-actions/setup-gcloud@master
|
|
with:
|
|
version: '295.0.0'
|
|
project_id: ${{ env.PROJECT_ID }}
|
|
service_account_key: ${{ secrets.GCLOUD_AUTH }}
|
|
|
|
# Build and push image to Google Container Registry
|
|
- name: Build
|
|
# Tagging w/ the commit SHA blocks the :latest tag on GCR
|
|
run: |
|
|
gcloud builds submit \
|
|
--tag "gcr.io/$PROJECT_ID/$BRANCH_NAME:$SHA7" \
|
|
--machine-type n1-highcpu-32 \
|
|
--timeout 3600s \
|
|
|
|
# Create instance template from container image
|
|
- name: Create instance template
|
|
run: |
|
|
gcloud compute instance-templates create-with-container "zebrad-$SHORT_BRANCH_NAME-$SHA7" \
|
|
--service-account cos-vm@zealous-zebra.iam.gserviceaccount.com \
|
|
--scopes cloud-platform \
|
|
--container-image "gcr.io/$PROJECT_ID/$BRANCH_NAME:$SHA7" \
|
|
--machine-type n1-highmem-8
|
|
|
|
# Deploy managed instance group using the new instance template
|
|
- name: Deploy managed instance group
|
|
run: |
|
|
gcloud compute instance-groups managed create "zebrad-$SHORT_BRANCH_NAME-$SHA7" \
|
|
--template "zebrad-$SHORT_BRANCH_NAME-$SHA7" \
|
|
--base-instance-name "zebrad-$SHORT_BRANCH_NAME-$SHA7" \
|
|
--size 3 \
|
|
--region us-central1
|