Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .config/nextest.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ test-threads = 1

[profile.unit]
default-filter = 'not kind(test)'
slow-timeout = { period = "20s" }
slow-timeout = { period = "5s" }
fail-fast = false
9 changes: 0 additions & 9 deletions .devcontainer/Dockerfile

This file was deleted.

28 changes: 0 additions & 28 deletions .devcontainer/devcontainer.json

This file was deleted.

28 changes: 0 additions & 28 deletions .devcontainer/docker-compose.yml

This file was deleted.

12 changes: 0 additions & 12 deletions .devcontainer/post-create.sh

This file was deleted.

2 changes: 1 addition & 1 deletion deploy/docker/.dockerignore → .dockerignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
**/target/
**/tests/
.git/
15 changes: 3 additions & 12 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,14 +1,5 @@
# Define development environment variables in a bash-compliant format.

# AWS config for local administration.
AWS_ACCESS_KEY_ID=''
AWS_SECRET_ACCESS_KEY=''
AWS_DEFAULT_REGION=''
AWS_DEFAULT_OUTPUT='json'

# Lambda specific
PROD_LAMBDA_LOG_GROUP='api-rust-ApiFunction-XXXXXXXXXXXX'

# Shared by deployment targets.
PROD_RUST_LOG='info'
PROD_POSTGRES_URI='postgres://postgres:password@host:5432/postgres'
DATABASE_URL='postgresql://postgres:developer@localhost:5432/postgres'
JWT_SECRET='dev-only-change-me'
PORT='3000'
57 changes: 31 additions & 26 deletions .github/workflows/deploy_lambda.yml
Original file line number Diff line number Diff line change
@@ -1,42 +1,47 @@
# AWS Example SAM Deploy: https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/deploying-using-github.html
# Cargo Lambda example: https://www.cargo-lambda.info/guide/getting-started.html#github-actions
# Cargo Lambda in CI: https://www.cargo-lambda.info/guide/getting-started.html
name: Deploy Lambda
on:
push:
branches:
- main
paths:
- '**/src/**'
- '**/Cargo.toml'
- "**/src/**"
- "**/Cargo.toml"
- "Cargo.lock"
- "lib/migrations/**"
- "lib/.sqlx/**"
jobs:
sam-deploy:
deploy:
runs-on: ubuntu-latest
if: ${{ vars.DEPLOY_LAMBDA == 'true' }}
env:
# Build the sqlx query macros from the committed lib/.sqlx cache; there is
# no database in this job.
SQLX_OFFLINE: "true"
RUST_LOG: ${{ vars.RUST_LOG }}
DATABASE_URL: ${{ secrets.DATABASE_URL }}
JWT_SECRET: ${{ secrets.JWT_SECRET }}
steps:
- uses: actions/checkout@v3
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
- uses: Swatinem/rust-cache@v2
- uses: mlugg/setup-zig@v1
with:
targets: aarch64-unknown-linux-gnu
- name: Run tests
run: cargo test --release --features lambda
- name: Install Zig toolchain
uses: korandoru/setup-zig@v1
version: 0.14.0
- uses: taiki-e/install-action@v2
with:
zig-version: 0.13.0
- name: Install Cargo Lambda
uses: jaxxstorm/action-install-gh-release@v1.9.0
with:
repo: cargo-lambda/cargo-lambda
platform: linux
arch: x86_64
- run: cargo lambda build --release --features lambda --arm64
- uses: aws-actions/setup-sam@v2
- uses: aws-actions/configure-aws-credentials@v1
tool: cargo-lambda
- uses: aws-actions/configure-aws-credentials@v4
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ vars.AWS_REGION }}
- run: |
cd deploy/aws_sam
sam deploy --no-confirm-changeset --no-fail-on-empty-changeset --parameter-overrides RustLog="${{ vars.RUST_LOG }}" PostgresUri="${{ secrets.POSTGRES_URI }}"
# Cross-compile for arm64 and deploy behind a public function URL, passing
# the job's env through to the function.
- run: cargo lambda build --release --features lambda --arm64
- run: >-
cargo lambda deploy --enable-function-url
--env-var RUST_LOG="${RUST_LOG:-info}"
--env-var DATABASE_URL="$DATABASE_URL"
--env-var JWT_SECRET="$JWT_SECRET"
api-rust
47 changes: 41 additions & 6 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,47 @@ on:
paths:
- "**/src/**"
- "**/Cargo.toml"
- "lib/migrations/**"
- "lib/.sqlx/**"
jobs:
cargo-test:
# Lint and unit tests. The sqlx query macros compile against the committed
# lib/.sqlx cache, so no database is needed here.
unit:
runs-on: ubuntu-latest
env:
SQLX_OFFLINE: "true"
steps:
- uses: actions/checkout@v3
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
- name: Run tests
run: cargo test
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
with:
components: clippy, rustfmt
- uses: Swatinem/rust-cache@v2
- uses: taiki-e/install-action@v2
with:
tool: just,nextest
- run: just check

# Repository contract tests against a real Postgres.
e2e:
runs-on: ubuntu-latest
services:
postgres:
image: postgres:16
env:
POSTGRES_PASSWORD: postgres
ports:
- 5432:5432
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
env:
SQLX_OFFLINE: "true"
DATABASE_URL: postgres://postgres:postgres@localhost:5432/postgres
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
- uses: Swatinem/rust-cache@v2
- uses: taiki-e/install-action@nextest
- run: cargo nextest run --profile e2e --features testing
3 changes: 0 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
target/
.aws-sam/
.env
.env.*
!.env.example
.bash_history
.Trash-*
50 changes: 1 addition & 49 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,52 +8,4 @@
"source.organizeImports": "explicit",
"source.convertImportFormat": "explicit",
},
"github.copilot.chat.copilotDebugCommand.enabled": false,
"git.terminalAuthentication": false,
"restoreTerminals.terminals": [
{
"splitTerminals": [
{
"name": "dev",
"commands": [
"./scripts/test-unit.sh && ./scripts/run.sh"
]
},
{
"name": "preview AWS SAM",
"commands": [
"sleep 5; ./scripts/test-e2e.sh && ./scripts/preview_sam.sh"
]
}
]
},
{
"splitTerminals": [
{
"name": "bash",
"commands": []
}
]
}
],
// CloudFormation intrinsic functions.
"yaml.customTags": [
"!And",
"!If",
"!Not",
"!Equals",
"!Or",
"!FindInMap sequence",
"!Base64",
"!Cidr",
"!Ref",
"!Sub",
"!GetAtt",
"!GetAZs",
"!ImportValue",
"!Select",
"!Select sequence",
"!Split",
"!Join sequence"
],
}
}
31 changes: 31 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"version": "2.0.0",
"tasks": [
{
"label": "dev",
"type": "shell",
"command": "just dev",
"isBackground": true,
"problemMatcher": [],
"presentation": { "group": "dev" },
"runOptions": { "runOn": "folderOpen" }
},
// Release builds, slow to start; run on demand via "Tasks: Run Task".
{
"label": "docker",
"type": "shell",
"command": "just docker",
"isBackground": true,
"problemMatcher": [],
"presentation": { "group": "dev" }
},
{
"label": "lambda",
"type": "shell",
"command": "just lambda",
"isBackground": true,
"problemMatcher": [],
"presentation": { "group": "dev" }
}
]
}
Loading
Loading