idk fix? #19
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 | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v2 | |
- name: Set up Rust | |
uses: actions-rs/toolchain@v1 | |
with: | |
toolchain: nightly | |
default: true | |
override: true | |
- name: Load target cache | |
uses: actions/cache/restore@v4 | |
with: | |
path: | | |
target | |
~/.cargo/registry | |
~/.cargo/git | |
key: ${{ runner.os }}-rust-cache | |
- 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: 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 | |
# always run this, even if any of the previous steps fail | |
- name: Save target cache | |
if: always() | |
uses: actions/cache/save@v4 | |
with: | |
path: | | |
target | |
~/.cargo/registry | |
~/.cargo/git | |
key: ${{ runner.os }}-rust-cache |