-
Notifications
You must be signed in to change notification settings - Fork 1
55 lines (51 loc) · 2.01 KB
/
api-deploy.yml
File metadata and controls
55 lines (51 loc) · 2.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
name: API Lambda Deploy ⁁
on:
push:
branches:
- main
paths:
- api/**
- .github/workflows/api-deploy.yml
tags:
- '*.*.*'
workflow_dispatch: {}
permissions:
contents: read
jobs:
build-deploy:
environment: ${{ github.ref == 'refs/heads/main' && 'dev' || 'prod' }}
name: Build & Deploy 📦
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.11"
- name: Setup AWS CLI
uses: aws-actions/configure-aws-credentials@e3dd6a429d7300a6a4c196c26e071d42e0343502 # v4.0.2
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ secrets.AWS_REGION }}
- name: Rust Cache
uses: Swatinem/rust-cache@v2
- name: Install dependencies
run: |
pip install cargo-lambda
cargo install sqlx-cli
- name: Build
run: cargo lambda build --release --output-format zip -p api -p consumer
- name: Migrate Database
env:
DSQL_ENDPOINT: ${{ secrets.DSQL_ENDPOINT }}
run: |
cd api
token=$(aws dsql generate-db-connect-admin-auth-token --hostname $DSQL_ENDPOINT)
encoded_token=$(echo "$token" | jq -Rr @uri)
sqlx migrate run --database-url "postgresql://admin:${encoded_token}@${DSQL_ENDPOINT}/postgres?sslmode=require"
cd ..
- name: Upload api to Lambda
run: aws lambda update-function-code --function-name kb2-lambda-function-${{ github.ref == 'refs/heads/main' && 'dev' || 'prod' }} --zip-file fileb://target/lambda/api/bootstrap.zip
- name: Upload consumer to Lambda
run: aws lambda update-function-code --function-name kb2-lambda-consumer-${{ github.ref == 'refs/heads/main' && 'dev' || 'prod' }} --zip-file fileb://target/lambda/consumer/bootstrap.zip