65 prep skyviewer api for new developmentdev ops #85
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
# Builds, pushes, and deploys the Skyviewer API container | |
name: 'Build and deploy branch-tagged Skyviewer API in Dev' | |
on: | |
pull_request: | |
types: | |
- 'opened' | |
- 'synchronize' | |
- 'reopened' | |
- 'closed' | |
branches: | |
- 'develop' | |
jobs: | |
build-push-deploy: | |
name: 'Build, Publish, and Deploy' | |
runs-on: ubuntu-latest | |
if: ${{ github.event.action != 'closed'}} | |
# Checkout the repository to the GitHub Actions runner | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v2 | |
- name: Print GitHub event action | |
run: | | |
echo "${{ github.event.action }}" | |
# gcloud CLI setup | |
- name: Login to GCP | |
uses: google-github-actions/setup-gcloud@v0 | |
with: | |
service_account_key: ${{ secrets.DEV_SA_KEY }} | |
project_id: ${{ secrets.SV_PROJ_NAME }} | |
export_default_credentials: true | |
# 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 Docker image | |
run: |- | |
docker build \ | |
--tag "gcr.io/${{ secrets.SV_PROJ_NAME }}/skyviewer-api:${{ github.sha }}" . | |
# Push the Docker image to Google Container Registry | |
- name: Publish image to GCR | |
run: |- | |
docker push "gcr.io/${{ secrets.SV_PROJ_NAME }}/skyviewer-api:${{ github.sha }}" | |
- name: Get VPC connector name | |
run: echo "vpc_connector=$(gcloud compute networks vpc-access connectors list --region=us-central1 --limit=1 --format='value(name)')" >> $GITHUB_ENV | |
# Deploy to Cloud Run. | |
- name: Deploy a tagged version to Cloud Run without redirecting traffic | |
run: |- | |
gcloud run deploy skyviewer-api --quiet \ | |
--image=gcr.io/${{ secrets.SV_PROJ_NAME }}/skyviewer-api:${{ github.sha }} \ | |
--vpc-connector=${{ env.vpc_connector }} \ | |
--region=us-central1 \ | |
--tag=${{ github.head_ref }} \ | |
--no-traffic | |
# Create or update a comment with the URL | |
- name: Find Comment | |
uses: peter-evans/find-comment@v1 | |
id: fc | |
with: | |
issue-number: ${{ github.event.pull_request.number }} | |
comment-author: 'github-actions[bot]' | |
body-includes: A preview of this PR | |
- name: Create or update a comment with the URL to the PR | |
uses: peter-evans/create-or-update-comment@v1 | |
with: | |
comment-id: ${{ steps.fc.outputs.comment-id }} | |
issue-number: ${{ github.event.pull_request.number }} | |
body: | | |
A preview of this PR will be available at https://${{ github.head_ref }}---skyviewer-api-int-2eici5myiq-uc.a.run.app until the request is closed. | |
reactions: '+1' | |
edit-mode: replace | |
remove-tag: | |
name: 'Remove branch tag' | |
runs-on: ubuntu-latest | |
if: ${{ github.event.action == 'closed'}} | |
steps: | |
# gcloud CLI setup | |
- name: Login to GCP | |
uses: google-github-actions/setup-gcloud@v0 | |
with: | |
service_account_key: ${{ secrets.DEV_SA_KEY }} | |
project_id: ${{ secrets.SV_PROJ_NAME }} | |
export_default_credentials: true | |
# Remove the branch tag when the PR is closed | |
- name: Remove branch tag | |
run: gcloud run services update-traffic skyviewer-api --remove-tags=${{ github.head_ref }} --region=us-central1 |