ok buddy #24
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
name: Deploy | |
on: | |
push: | |
branches: | |
- main | |
paths: | |
- 'src-api/**/*' | |
- '.github/workflows/deploy.yml' | |
workflow_dispatch: | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
defaults: | |
run: | |
working-directory: src-api | |
permissions: | |
contents: read | |
id-token: write # Required for Google Cloud | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v2 | |
- name: Load target cache | |
uses: actions/cache/restore@v4 | |
id: cache-restore | |
with: | |
path: | | |
/home/runner/work/attendance/attendance/src-api/target | |
~/.cargo/registry | |
~/.cargo/git | |
key: ${{ runner.os }}-rust-cache | |
- name: Set up Rust | |
if: steps.cache-restore.outputs.cache-hit != 'true' | |
uses: actions-rs/toolchain@v1 | |
with: | |
toolchain: nightly | |
default: true | |
override: true | |
- name: Build | |
run: cargo build --release | |
env: | |
DATABASE_URL: ${{ secrets.DATABASE_URL }} | |
- name: Build Docker image | |
run: docker build -t onlycs/attendance . | |
- name: Login to Docker Hub | |
run: docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }} | |
- name: Push Docker image | |
run: docker push onlycs/attendance | |
- name: Login to Google Cloud | |
uses: google-github-actions/auth@v2 | |
with: | |
project_id: ${{ secrets.GCP_PROJECT_ID }} | |
workload_identity_provider: ${{ secrets.GCP_WLIP }} | |
service_account: ${{ secrets.GCP_SA }} | |
- name: Setup GCP Docker | |
run: gcloud auth configure-docker us-central1-docker.pkg.dev | |
- name: Push to GCR | |
run: | | |
docker tag onlycs/attendance us-central1-docker.pkg.dev/${{ secrets.GCP_PROJECT_ID }}/attendance/attendance:latest | |
docker push us-central1-docker.pkg.dev/${{ secrets.GCP_PROJECT_ID }}/attendance/attendance:latest | |
- name: Deploy to Cloud Run | |
run: | | |
gcloud run deploy attendance \ | |
--image=us-central1-docker.pkg.dev/${{ secrets.GCP_PROJECT_ID }}/attendance/attendance:latest \ | |
--platform=managed \ | |
--region=us-central1 \ | |
--allow-unauthenticated | |
- name: Save target cache | |
if: always() | |
uses: actions/cache/save@v4 | |
with: | |
path: | | |
/home/runner/work/attendance/attendance/src-api/target | |
~/.cargo/registry | |
~/.cargo/git | |
key: ${{ steps.cache-restore.outputs.cache-primary-key }} |