Skip to content

Merge pull request #193 from ToberoCat/master #3

Merge pull request #193 from ToberoCat/master

Merge pull request #193 from ToberoCat/master #3

name: Build
on:
push:
branches:
- master
env:
PROJECT_ID: ${{ secrets.GKE_PROJECT }}
GKE_CLUSTER: kipr
GKE_ZONE: us-central1-a
IMAGE: kipr/simulator
concurrency: ${{ github.workflow }}
jobs:
build-publish:
name: Build
runs-on: ubuntu-latest
outputs:
image_version: ${{ steps.image_tag.outputs.IMAGE_TAG }}
steps:
- name: Checkout
uses: actions/checkout@v2
with:
submodules: true
# Calculate image tag name from commit hash
- name: Set image tag output
id: image_tag
run: |-
echo "::set-output name=IMAGE_TAG::${GITHUB_SHA::8}"
# Setup gcloud CLI
- name: Set up gcloud CLI
uses: google-github-actions/setup-gcloud@v0.2.1
with:
service_account_key: ${{ secrets.GCR_SA_KEY }}
project_id: ${{ secrets.GKE_PROJECT }}
# Ensure there isn't already a Docker image for this version
- name: Ensure Docker image does not exist
run: |-
NUM_IMAGES=$(gcloud container images list-tags gcr.io/kipr-321905/kipr/simulator --filter="tags:${{ steps.image_tag.outputs.IMAGE_TAG }}" --format=json | jq '. | length')
if (( NUM_IMAGES > 0 )); then exit 1; fi
# Configure Docker to use the gcloud command-line tool as a credential helper for authentication
- name: Configure Docker with gcloud
run: |-
gcloud --quiet auth configure-docker
# Build the Docker image
- name: Build Docker image
run: |-
docker build \
--tag "gcr.io/$PROJECT_ID/$IMAGE:${{ steps.image_tag.outputs.IMAGE_TAG }}" \
.
# Push the Docker image to Google Container Registry
- name: Publish Docker image to GCR
run: |-
docker push "gcr.io/$PROJECT_ID/$IMAGE:${{ steps.image_tag.outputs.IMAGE_TAG }}"
deploy-to-staging:
name: Deploy to staging
runs-on: ubuntu-latest
needs: build-publish
steps:
- name: Checkout deployment repo
uses: actions/checkout@v2
with:
repository: 'kipr/kipr-yamls'
ssh-key: ${{ secrets.KIPR_YAMLS_REPO_KEY }}
# Get the GKE credentials so we can deploy to the cluster
- name: Get GKE credentials
uses: google-github-actions/get-gke-credentials@v0.2.1
with:
cluster_name: ${{ env.GKE_CLUSTER }}
location: ${{ env.GKE_ZONE }}
credentials: ${{ secrets.GCR_SA_KEY }}
- name: Deploy to GKE
run: |-
helm upgrade \
--install \
--namespace prerelease \
--values ./simulator/values.prerelease.yaml \
--set imageVersion=${{ needs.build-publish.outputs.image_version }} \
simulator-prerelease ./simulator