etc #35
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-${{ hashFiles('**/Cargo.lock') }} | |
restore-keys: ${{ runner.os }}-rust-cache | |
- name: Set up Rust | |
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: Login to Google Cloud | |
id: gcp-auth | |
uses: google-github-actions/auth@v2 | |
with: | |
token_format: 'access_token' | |
project_id: ${{ secrets.GCP_PROJECT_ID }} | |
workload_identity_provider: ${{ secrets.GCP_WLIF_PROVIDER }} | |
service_account: ${{ secrets.GCP_SA }} | |
access_token_lifetime: 600s | |
- name: Login to Docker Hub | |
uses: docker/login-action@v2 | |
with: | |
username: ${{ secrets.DOCKER_USERNAME }} | |
password: ${{ secrets.DOCKER_PASSWORD }} | |
- name: Login to Artifact Registry | |
uses: docker/login-action@v2 | |
with: | |
registry: us-central1-docker.pkg.dev | |
username: oauth2accesstoken | |
password: ${{ steps.gcp-auth.outputs.access_token }} | |
- name: Build Docker image | |
run: | | |
docker build . -t onlycs/attendance:latest -t us-central1-docker.pkg.dev/${{ secrets.GCP_PROJECT_ID }}/attendance/attendance:latest | |
- name: Push Docker image | |
run: | | |
docker push us-central1-docker.pkg.dev/${{ secrets.GCP_PROJECT_ID }}/attendance/attendance:latest | |
docker push onlycs/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() && (steps.cache-restore.outputs.cache-hit != 'true' || steps.cache-restore.outputs.cache-primary-key == '${{ runner.os }}-rust-cache') | |
uses: actions/cache/save@v4 | |
with: | |
path: | | |
/home/runner/work/attendance/attendance/src-api/target | |
~/.cargo/registry | |
~/.cargo/git | |
key: ${{ runner.os }}-rust-cache-${{ hashFiles('**/Cargo.lock') }} |