Migrated to native Rust and containerized Postgres.
This commit is contained in:
+105
@@ -0,0 +1,105 @@
|
||||
version: "3"
|
||||
|
||||
vars:
|
||||
SERVER_DIR: "{{.TASKFILE_DIR}}/server"
|
||||
COMPOSE_CMD: docker compose -f "{{.TASKFILE_DIR}}/compose.yaml"
|
||||
DATABASE_URL: '{{.DATABASE_URL | default "postgres://expenses:expenses@127.0.0.1:5432/expenses"}}'
|
||||
|
||||
tasks:
|
||||
default:
|
||||
cmds:
|
||||
- task --list
|
||||
|
||||
setup:
|
||||
internal: true
|
||||
cmds:
|
||||
- test -f "{{.SERVER_DIR}}/.env" || cp "{{.SERVER_DIR}}/.env.example" "{{.SERVER_DIR}}/.env"
|
||||
|
||||
db-up:
|
||||
desc: Start PostgreSQL
|
||||
cmds:
|
||||
- "{{.COMPOSE_CMD}} up -d --wait postgres"
|
||||
|
||||
db-down:
|
||||
desc: Stop PostgreSQL and remove containers
|
||||
cmds:
|
||||
- "{{.COMPOSE_CMD}} down"
|
||||
|
||||
db-logs:
|
||||
desc: Follow PostgreSQL logs
|
||||
cmds:
|
||||
- "{{.COMPOSE_CMD}} logs -f postgres"
|
||||
|
||||
db-shell:
|
||||
desc: Open a PostgreSQL shell
|
||||
cmds:
|
||||
- "{{.COMPOSE_CMD}} exec postgres psql -U expenses -d expenses"
|
||||
|
||||
db-reset:
|
||||
desc: Stop PostgreSQL and delete its data volume
|
||||
cmds:
|
||||
- echo "Resetting PostgreSQL data volume..."
|
||||
- "{{.COMPOSE_CMD}} down -v"
|
||||
|
||||
run:
|
||||
desc: Run the API
|
||||
deps: [db-up]
|
||||
cmds:
|
||||
- cd "{{.SERVER_DIR}}" && DATABASE_URL="{{.DATABASE_URL}}" cargo run --locked
|
||||
|
||||
dev:
|
||||
desc: Run the API with cargo-watch
|
||||
deps: [setup, db-up]
|
||||
cmds:
|
||||
- cd "{{.SERVER_DIR}}" && DATABASE_URL="{{.DATABASE_URL}}" cargo watch -w src -w migrations -w Cargo.toml -w Cargo.lock -x 'run --locked'
|
||||
|
||||
migrate:
|
||||
desc: Run database migrations
|
||||
deps: [db-up]
|
||||
cmds:
|
||||
- cd "{{.SERVER_DIR}}" && DATABASE_URL="{{.DATABASE_URL}}" SQLX_OFFLINE=false cargo sqlx migrate run
|
||||
|
||||
sqlx-prepare:
|
||||
desc: Prepare SQLx query metadata
|
||||
deps: [migrate]
|
||||
cmds:
|
||||
- cd "{{.SERVER_DIR}}" && DATABASE_URL="{{.DATABASE_URL}}" SQLX_OFFLINE=false cargo sqlx prepare --all
|
||||
|
||||
sqlx-check:
|
||||
desc: Check SQLx query metadata
|
||||
deps: [migrate]
|
||||
cmds:
|
||||
- cd "{{.SERVER_DIR}}" && DATABASE_URL="{{.DATABASE_URL}}" SQLX_OFFLINE=false cargo sqlx prepare --check --all
|
||||
|
||||
fmt:
|
||||
desc: Format Rust code
|
||||
cmds:
|
||||
- cd "{{.SERVER_DIR}}" && cargo fmt --all
|
||||
|
||||
fmt-check:
|
||||
desc: Check Rust formatting
|
||||
cmds:
|
||||
- cd "{{.SERVER_DIR}}" && cargo fmt --all -- --check
|
||||
|
||||
check:
|
||||
desc: Run cargo check
|
||||
cmds:
|
||||
- cd "{{.SERVER_DIR}}" && SQLX_OFFLINE=true cargo check --locked
|
||||
|
||||
clippy:
|
||||
desc: Run Clippy with warnings denied
|
||||
cmds:
|
||||
- cd "{{.SERVER_DIR}}" && SQLX_OFFLINE=true cargo clippy --locked --all-targets -- -D warnings
|
||||
|
||||
test:
|
||||
desc: Run Rust tests
|
||||
cmds:
|
||||
- cd "{{.SERVER_DIR}}" && SQLX_OFFLINE=true cargo test --locked
|
||||
|
||||
ci-offline:
|
||||
desc: Run offline CI checks
|
||||
deps: [fmt-check, check, clippy, test]
|
||||
|
||||
ci:
|
||||
desc: Run the full CI checks
|
||||
deps: [db-up, sqlx-check, ci-offline]
|
||||
+2
-29
@@ -1,32 +1,12 @@
|
||||
services:
|
||||
server:
|
||||
build:
|
||||
context: ./server
|
||||
dockerfile: Dockerfile
|
||||
init: true
|
||||
depends_on:
|
||||
postgres:
|
||||
condition: service_healthy
|
||||
environment:
|
||||
RUST_LOG: trace
|
||||
HOST: 0.0.0.0
|
||||
PORT: 3000
|
||||
DATABASE_URL: postgres://expenses:expenses@postgres:5432/expenses
|
||||
SQLX_OFFLINE: "true"
|
||||
ports:
|
||||
- "3000:3000"
|
||||
volumes:
|
||||
- server-target:/app/target
|
||||
- ./server:/app
|
||||
networks:
|
||||
- expenses_net
|
||||
|
||||
postgres:
|
||||
image: postgres:17-alpine
|
||||
environment:
|
||||
POSTGRES_DB: expenses
|
||||
POSTGRES_USER: expenses
|
||||
POSTGRES_PASSWORD: expenses
|
||||
ports:
|
||||
- 5432:5432
|
||||
healthcheck:
|
||||
test: ["CMD-SHELL", "pg_isready -U expenses -d expenses"]
|
||||
interval: 5s
|
||||
@@ -34,13 +14,6 @@ services:
|
||||
retries: 5
|
||||
volumes:
|
||||
- postgres-data:/var/lib/postgresql/data
|
||||
networks:
|
||||
- expenses_net
|
||||
|
||||
volumes:
|
||||
server-target:
|
||||
postgres-data:
|
||||
|
||||
networks:
|
||||
expenses_net:
|
||||
name: expenses_net
|
||||
@@ -1,5 +0,0 @@
|
||||
/target
|
||||
.git
|
||||
.env
|
||||
.vscode
|
||||
.DS_Store
|
||||
@@ -0,0 +1,4 @@
|
||||
RUST_LOG=info
|
||||
HOST=127.0.0.1
|
||||
PORT=3000
|
||||
DATABASE_URL=postgres://expenses:expenses@localhost:5432/expenses
|
||||
@@ -1,8 +0,0 @@
|
||||
FROM rust:bookworm
|
||||
|
||||
RUN cargo install cargo-watch --locked \
|
||||
&& cargo install sqlx-cli --version 0.8.6 --locked --no-default-features --features postgres,rustls
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
CMD ["cargo", "watch", "--watch", "src", "--watch", "Cargo.toml", "--watch", "Cargo.lock", "--exec", "run --locked"]
|
||||
Reference in New Issue
Block a user