Skip to content

Commit

Permalink
Add Github Actions for deployment and releasing
Browse files Browse the repository at this point in the history
  • Loading branch information
umatare5 committed Apr 30, 2022
1 parent be828a5 commit da4ac10
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 0 deletions.
63 changes: 63 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
name: Deploy

on:
workflow_dispatch:
push:
tags:
- '*'

env:
PROJECT_NUMBER: ${{ secrets.GCP_PROJECT_NUMBER }}
PROJECT_ID: ${{ secrets.GCP_PROJECT }}
GCR_LOCATION: asia.gcr.io
GCR_REGION: asia-northeast1
WI_POOL_ID: ${{ secrets.WI_POOL_ID }}
WI_PROVIDER_ID: ${{ secrets.WI_PROVIDER_ID }}
WI_SERVICE_ACCOUNT: ${{ secrets.WI_SERVICE_ACCOUNT }}
LOGBOOK_ATMOS_TOKEN: ${{ secrets.LOGBOOK_ATMOS_TOKEN }}
LOGBOOK_ATMOS_API: ${{ secrets.LOGBOOK_ATMOS_API }}
SERVICE: logbook-api

jobs:
deploy:
runs-on: ubuntu-latest
permissions:
contents: 'read'
id-token: 'write'

steps:
- name: Checkout
uses: actions/checkout@v3

- name: Setup Cloud SDK
id: 'auth'
uses: google-github-actions/auth@v0
with:
create_credentials_file: true
workload_identity_provider:
projects/${{ env.PROJECT_NUMBER }}/locations/global/workloadIdentityPools/${{ env.WI_POOL_ID }}/providers/${{ env.WI_PROVIDER_ID }}
service_account: ${{ env.WI_SERVICE_ACCOUNT }}

- name: Activate gcloud
run: gcloud auth login --brief --cred-file="${{ steps.auth.outputs.credentials_file_path }}"

- name: Authorize Docker push
run: gcloud auth configure-docker --quiet

- name: Build Container Image
run: docker build -t ${{ env.GCR_LOCATION }}/${{ env.PROJECT_ID }}/${{ env.SERVICE }}:${{ github.sha }} .

- name: Push Container Image
run: docker push ${{ env.GCR_LOCATION }}/${{ env.PROJECT_ID }}/${{ env.SERVICE }}:${{ github.sha }}

- name: Deploy to Cloud Run
id: deploy
uses: google-github-actions/deploy-cloudrun@v0
with:
image: ${{ env.GCR_LOCATION }}/${{ env.PROJECT_ID }}/${{ env.SERVICE }}:${{ github.sha }}
project_id: ${{ env.PROJECT_ID }}
region: ${{ env.GCR_REGION }}
service: ${{ env.SERVICE }}
env_vars: LOGBOOK_ATMOS_TOKEN=${{ env.LOGBOOK_ATMOS_TOKEN }},LOGBOOK_ATMOS_API=${{ env.LOGBOOK_ATMOS_API }}
tag: latest
no_traffic: false
29 changes: 29 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Release

on:
workflow_dispatch:
push:
tags:
- '*'

env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

jobs:
goreleaser:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: 0

- name: Set up Go
uses: actions/setup-go@v2

- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v2
with:
distribution: goreleaser
version: latest
args: release --rm-dist

0 comments on commit da4ac10

Please sign in to comment.