Compare commits
9
Commits
v0.4.0
...
81a0cab8b5
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
81a0cab8b5
|
||
|
|
9a02410dd4
|
||
|
|
de411bc7d7
|
||
|
|
77c0b36fd3
|
||
|
|
e8572768e0
|
||
|
|
1e3a89f146
|
||
|
|
a3a699c507
|
||
|
|
7ca4c655a4 | ||
|
|
50d0ea630f |
@@ -0,0 +1,12 @@
|
|||||||
|
APP_ENV=development
|
||||||
|
BACKEND_PORT=8000
|
||||||
|
FRONTEND_URL=http://localhost:4200
|
||||||
|
RUST_LOG=debug
|
||||||
|
ALLOWED_ORIGINS=https://soaricarus.com,https://www.soaricarus.com
|
||||||
|
SECRET_MAIN_KEY=refero34o8rfhfjn983thf39fhc943rf923n3h
|
||||||
|
ROOT_DIRECTORY=/home/icarus/mydata
|
||||||
|
POSTGRES_MAIN_USER=icarus
|
||||||
|
POSTGRES_MAIN_PASSWORD=password
|
||||||
|
POSTGRES_MAIN_DB=icarus_db
|
||||||
|
POSTGRES_MAIN_HOST=main_db
|
||||||
|
DATABASE_URL=postgres://${POSTGRES_MAIN_USER}:${POSTGRES_MAIN_PASSWORD}@${POSTGRES_MAIN_HOST}:5432/${POSTGRES_MAIN_DB}
|
||||||
@@ -9,14 +9,14 @@ jobs:
|
|||||||
runs-on: ubuntu-24.04
|
runs-on: ubuntu-24.04
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout code
|
- name: Checkout code
|
||||||
uses: actions/checkout@v5
|
uses: actions/checkout@v6
|
||||||
with:
|
with:
|
||||||
fetch-depth: 0 # Important for git describe --tags
|
fetch-depth: 0 # Important for git describe --tags
|
||||||
|
|
||||||
- name: Install Rust
|
- name: Install Rust
|
||||||
uses: actions-rs/toolchain@v1
|
uses: actions-rs/toolchain@v1
|
||||||
with:
|
with:
|
||||||
toolchain: 1.94
|
toolchain: 1.96.1
|
||||||
components: cargo
|
components: cargo
|
||||||
|
|
||||||
- name: Extract Version from Cargo.toml
|
- name: Extract Version from Cargo.toml
|
||||||
|
|||||||
+124
-59
@@ -6,18 +6,42 @@ on:
|
|||||||
pull_request:
|
pull_request:
|
||||||
branches: [ "main" ]
|
branches: [ "main" ]
|
||||||
|
|
||||||
|
concurrency:
|
||||||
|
group: ${{ github.workflow }}-${{ github.ref }}
|
||||||
|
cancel-in-progress: true
|
||||||
|
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build:
|
check:
|
||||||
|
name: Check
|
||||||
|
runs-on: ubuntu-24.04
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v6
|
||||||
|
- uses: actions-rust-lang/setup-rust-toolchain@v1
|
||||||
|
with:
|
||||||
|
toolchain: 1.96.1
|
||||||
|
- uses: Swatinem/rust-cache@v2
|
||||||
|
- run: |
|
||||||
|
mkdir -p ~/.ssh
|
||||||
|
echo "${{ secrets.MYREPO_TOKEN }}" > ~/.ssh/icarus_models_deploy_key
|
||||||
|
chmod 600 ~/.ssh/icarus_models_deploy_key
|
||||||
|
ssh-keyscan ${{ secrets.MYHOST }} >> ~/.ssh/known_hosts
|
||||||
|
|
||||||
|
eval $(ssh-agent -s)
|
||||||
|
ssh-add -v ~/.ssh/icarus_models_deploy_key
|
||||||
|
|
||||||
|
cargo check
|
||||||
|
|
||||||
|
test:
|
||||||
|
name: Test Suite
|
||||||
runs-on: ubuntu-24.04
|
runs-on: ubuntu-24.04
|
||||||
services:
|
services:
|
||||||
postgres:
|
postgres:
|
||||||
image: postgres:18.3-alpine
|
image: postgres:18.4-alpine
|
||||||
env:
|
env:
|
||||||
POSTGRES_PASSWORD: ${{ secrets.POSTGRES_PASSWORD }}
|
POSTGRES_USER: ${{ secrets.DB_TEST_USER || 'testuser' }}
|
||||||
POSTGRES_USER: ${{ secrets.POSTGRES_USER }}
|
POSTGRES_PASSWORD: ${{ secrets.DB_TEST_PASSWORD || 'testpassword' }}
|
||||||
POSTGRES_DB: ${{ secrets.POSTGRES_DB }}
|
POSTGRES_DB: ${{ secrets.DB_TEST_NAME || 'testdb' }}
|
||||||
ports:
|
|
||||||
- 5432:5432
|
|
||||||
options: >-
|
options: >-
|
||||||
--health-cmd pg_isready
|
--health-cmd pg_isready
|
||||||
--health-interval 10s
|
--health-interval 10s
|
||||||
@@ -25,55 +49,96 @@ jobs:
|
|||||||
--health-retries 5
|
--health-retries 5
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v5
|
- uses: actions/checkout@v6
|
||||||
|
- uses: actions-rust-lang/setup-rust-toolchain@v1
|
||||||
- name: Install Rust 1.94
|
with:
|
||||||
uses: actions-rs/toolchain@v1
|
toolchain: 1.96.1
|
||||||
with:
|
- uses: Swatinem/rust-cache@v2
|
||||||
toolchain: 1.94
|
- name: Verify Docker Environment
|
||||||
components: clippy, rustfmt
|
run: |
|
||||||
override: true
|
echo "Runner User Info:"
|
||||||
|
id
|
||||||
- name: Cache dependencies
|
echo "Checking Docker Version:"
|
||||||
uses: Swatinem/rust-cache@v2
|
docker --version
|
||||||
|
echo "Checking Docker Daemon Status (info):"
|
||||||
- name: Install libpq
|
docker info
|
||||||
run: sudo apt-get install -y libpq-dev
|
echo "Checking Docker Daemon Status (ps):"
|
||||||
|
docker ps -a
|
||||||
- name: Setup test database
|
echo "Docker environment check complete."
|
||||||
env:
|
- name: Run tests
|
||||||
DATABASE_URL: "postgres://${{ secrets.POSTGRES_USER }}:${{ secrets.POSTGRES_PASSWORD }}@localhost:5432/${{ secrets.POSTGRES_DB }}"
|
env:
|
||||||
run: |
|
# Define DATABASE_URL for tests to use
|
||||||
# Wait for PostgreSQL to be ready
|
DATABASE_URL: postgresql://${{ secrets.DB_TEST_USER || 'testuser' }}:${{ secrets.DB_TEST_PASSWORD || 'testpassword' }}@postgres:5432/${{ secrets.DB_TEST_NAME || 'testdb' }}
|
||||||
for i in {1..10}; do
|
RUST_LOG: info # Optional: configure test log level
|
||||||
pg_isready -U ${{ secrets.POSTGRES_USER }} -d ${{ secrets.POSTGRES_DB }} && break
|
SECRET_MAIN_KEY: ${{ secrets.TOKEN_SECRET_KEY }}
|
||||||
sleep 2
|
SSH_AUTH_SOCK: ${{ env.SSH_AUTH_SOCK }}
|
||||||
done
|
ROOT_DIRECTORY: "/tmp"
|
||||||
|
run: |
|
||||||
# Run database migrations (if you use sqlx migrations)
|
mkdir -p ~/.ssh
|
||||||
cargo install sqlx-cli --no-default-features --features native-tls,postgres
|
echo "${{ secrets.MYREPO_TOKEN }}" > ~/.ssh/icarus_models_deploy_key
|
||||||
sqlx migrate run --database-url $DATABASE_URL
|
chmod 600 ~/.ssh/icarus_models_deploy_key
|
||||||
|
ssh-keyscan ${{ secrets.MYHOST }} >> ~/.ssh/known_hosts
|
||||||
- name: Build
|
|
||||||
run: |
|
eval $(ssh-agent -s)
|
||||||
mkdir -p ~/.ssh
|
ssh-add -v ~/.ssh/icarus_models_deploy_key
|
||||||
echo "${{ secrets.MYREPO_TOKEN }}" > ~/.ssh/gitea_deploy_key
|
|
||||||
chmod 600 ~/.ssh/gitea_deploy_key
|
cargo test
|
||||||
ssh-keyscan ${{ vars.MYHOST }} >> ~/.ssh/known_hosts
|
|
||||||
eval $(ssh-agent -s)
|
fmt:
|
||||||
ssh-add -v ~/.ssh/gitea_deploy_key
|
name: Rustfmt
|
||||||
cargo build --verbose --release
|
runs-on: ubuntu-24.04
|
||||||
|
steps:
|
||||||
- name: Run tests
|
- uses: actions/checkout@v6
|
||||||
env:
|
- uses: actions-rust-lang/setup-rust-toolchain@v1
|
||||||
ROOT_DIRECTORY: "/tmp"
|
with:
|
||||||
DATABASE_URL: "postgres://${{ secrets.POSTGRES_USER }}:${{ secrets.POSTGRES_PASSWORD }}@localhost:5432/${{ secrets.POSTGRES_DB }}"
|
toolchain: 1.96.1
|
||||||
run: |
|
- uses: Swatinem/rust-cache@v2
|
||||||
cat .env.sample | head -6 > .env
|
- run: rustup component add rustfmt
|
||||||
cargo test --verbose --
|
- run: |
|
||||||
|
mkdir -p ~/.ssh
|
||||||
- name: Run clippy
|
echo "${{ secrets.MYREPO_TOKEN }}" > ~/.ssh/icarus_models_deploy_key
|
||||||
run: cargo clippy -- -D warnings
|
chmod 600 ~/.ssh/icarus_models_deploy_key
|
||||||
|
ssh-keyscan ${{ secrets.MYHOST }} >> ~/.ssh/known_hosts
|
||||||
- name: Run rustfmt
|
|
||||||
run: cargo fmt --all -- --check
|
eval $(ssh-agent -s)
|
||||||
|
ssh-add -v ~/.ssh/icarus_models_deploy_key
|
||||||
|
cargo fmt --all -- --check
|
||||||
|
|
||||||
|
clippy:
|
||||||
|
name: Clippy
|
||||||
|
runs-on: ubuntu-24.04
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v6
|
||||||
|
- uses: actions-rust-lang/setup-rust-toolchain@v1
|
||||||
|
with:
|
||||||
|
toolchain: 1.96.1
|
||||||
|
- uses: Swatinem/rust-cache@v2
|
||||||
|
- run: rustup component add clippy
|
||||||
|
- run: |
|
||||||
|
mkdir -p ~/.ssh
|
||||||
|
echo "${{ secrets.MYREPO_TOKEN }}" > ~/.ssh/icarus_models_deploy_key
|
||||||
|
chmod 600 ~/.ssh/icarus_models_deploy_key
|
||||||
|
ssh-keyscan ${{ secrets.MYHOST }} >> ~/.ssh/known_hosts
|
||||||
|
|
||||||
|
eval $(ssh-agent -s)
|
||||||
|
ssh-add -v ~/.ssh/icarus_models_deploy_key
|
||||||
|
cargo clippy -- -D warnings
|
||||||
|
|
||||||
|
build:
|
||||||
|
name: build
|
||||||
|
runs-on: ubuntu-24.04
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v6
|
||||||
|
- uses: actions-rust-lang/setup-rust-toolchain@v1
|
||||||
|
with:
|
||||||
|
toolchain: 1.96.1
|
||||||
|
- uses: Swatinem/rust-cache@v2
|
||||||
|
- run: |
|
||||||
|
mkdir -p ~/.ssh
|
||||||
|
echo "${{ secrets.MYREPO_TOKEN }}" > ~/.ssh/icarus_models_deploy_key
|
||||||
|
chmod 600 ~/.ssh/icarus_models_deploy_key
|
||||||
|
ssh-keyscan ${{ secrets.MYHOST }} >> ~/.ssh/known_hosts
|
||||||
|
|
||||||
|
eval $(ssh-agent -s)
|
||||||
|
ssh-add -v ~/.ssh/icarus_models_deploy_key
|
||||||
|
cargo build --release
|
||||||
|
|||||||
Generated
+383
-566
File diff suppressed because it is too large
Load Diff
+16
-17
@@ -1,33 +1,32 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "icarus"
|
name = "icarus"
|
||||||
version = "0.4.0"
|
version = "0.5.2"
|
||||||
edition = "2024"
|
edition = "2024"
|
||||||
rust-version = "1.94"
|
rust-version = "1.95"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
axum = { version = "0.8.8", features = ["multipart"] }
|
axum = { version = "0.8.9", features = ["multipart"] }
|
||||||
axum-extra = { version = "0.12.5", features = ["cookie"] }
|
axum-extra = { version = "0.12.6", features = ["cookie"] }
|
||||||
|
openssl = { version = "0.10.81", features = ["vendored"] }
|
||||||
serde = { version = "1.0.228", features = ["derive"] }
|
serde = { version = "1.0.228", features = ["derive"] }
|
||||||
serde_json = { version = "1.0.149" }
|
serde_json = { version = "1.0.150" }
|
||||||
tower = { version = "0.5.3", features = ["full"] }
|
tokio = { version = "1.52.3", features = ["full"] }
|
||||||
tokio = { version = "1.51", features = ["full"] }
|
|
||||||
tokio-util = { version = "0.7.18", features = ["io"] }
|
tokio-util = { version = "0.7.18", features = ["io"] }
|
||||||
tower-http = { version = "0.6.8", features = ["cors", "timeout"] }
|
tower = { version = "0.5.3", features = ["full"] }
|
||||||
|
tower-http = { version = "0.7.0", features = ["cors", "timeout"] }
|
||||||
tracing-subscriber = "0.3.23"
|
tracing-subscriber = "0.3.23"
|
||||||
futures = { version = "0.3.32" }
|
futures = { version = "0.3.32" }
|
||||||
mime_guess = { version = "2.0.5" }
|
mime_guess = { version = "2.0.5" }
|
||||||
uuid = { version = "1.23", features = ["v4", "serde"] }
|
uuid = { version = "1.23.4", features = ["v4", "serde"] }
|
||||||
sqlx = { version = "0.8.6", features = ["postgres", "runtime-tokio-native-tls", "time", "uuid"] }
|
sqlx = { version = "0.9.0", features = ["postgres", "runtime-tokio", "tls-native-tls", "time", "uuid"] }
|
||||||
time = { version = "0.3.47", features = ["formatting", "macros", "parsing", "serde"] }
|
time = { version = "0.3.53", features = ["formatting", "macros", "parsing", "serde"] }
|
||||||
thiserror = "2.0.18"
|
|
||||||
base64 = "0.22.1"
|
|
||||||
jsonwebtoken = { version = "10.3.0", features = ["rust_crypto"] }
|
jsonwebtoken = { version = "10.3.0", features = ["rust_crypto"] }
|
||||||
josekit = { version = "0.10.3" }
|
josekit = { version = "0.10.3" }
|
||||||
utoipa = { version = "5.4.0", features = ["axum_extras"] }
|
utoipa = { version = "5.5.0", features = ["axum_extras"] }
|
||||||
utoipa-swagger-ui = { version = "9.0.2", features = ["axum"] }
|
utoipa-swagger-ui = { version = "9.0.2", features = ["axum"] }
|
||||||
icarus_meta = { git = "ssh://git@git.kundeng.us/phoenix/icarus_meta.git", tag = "v0.5.0" }
|
icarus_meta = { git = "ssh://git@git.kundeng.us/phoenix/icarus_meta.git", tag = "v0.6.1" }
|
||||||
icarus_models = { git = "ssh://git@git.kundeng.us/phoenix/icarus_models.git", tag = "v0.10.0" }
|
icarus_models = { git = "ssh://git@git.kundeng.us/phoenix/icarus_models.git", tag = "v0.11.3" }
|
||||||
icarus_envy = { git = "ssh://git@git.kundeng.us/phoenix/icarus_envy.git", tag = "v0.6.0" }
|
icarus_envy = { git = "ssh://git@git.kundeng.us/phoenix/icarus_envy.git", tag = "v0.8.0" }
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
common-multipart-rfc7578 = { version = "0.7.0" }
|
common-multipart-rfc7578 = { version = "0.7.0" }
|
||||||
|
|||||||
+2
-2
@@ -1,5 +1,5 @@
|
|||||||
# Stage 1: Build the application
|
# Stage 1: Build the application
|
||||||
FROM rust:1.94 as builder
|
FROM rust:1.95 as builder
|
||||||
|
|
||||||
# Set the working directory inside the container
|
# Set the working directory inside the container
|
||||||
WORKDIR /usr/src/app
|
WORKDIR /usr/src/app
|
||||||
@@ -45,7 +45,7 @@ RUN --mount=type=ssh \
|
|||||||
|
|
||||||
# Stage 2: Create the final, smaller runtime image
|
# Stage 2: Create the final, smaller runtime image
|
||||||
# Use a minimal base image like debian-slim or even distroless for security/size
|
# Use a minimal base image like debian-slim or even distroless for security/size
|
||||||
FROM ubuntu:24.04
|
FROM debian:trixie-slim
|
||||||
|
|
||||||
# Install runtime dependencies if needed (e.g., SSL certificates)
|
# Install runtime dependencies if needed (e.g., SSL certificates)
|
||||||
RUN apt-get update && apt-get install -y ca-certificates libssl-dev libssl3 && rm -rf /var/lib/apt/lists/*
|
RUN apt-get update && apt-get install -y ca-certificates libssl-dev libssl3 && rm -rf /var/lib/apt/lists/*
|
||||||
|
|||||||
@@ -3,8 +3,8 @@ Web API for the Icarus project.
|
|||||||
|
|
||||||
|
|
||||||
### Requires
|
### Requires
|
||||||
`icarus_auth` v0.7.x
|
`icarus_auth` v0.8.x
|
||||||
`songparser` v0.5.x
|
`songparser` v0.6.x
|
||||||
|
|
||||||
### Compatible with
|
### Compatible with
|
||||||
`icarus-dm` v0.9.x
|
`icarus-dm` v0.9.x
|
||||||
|
|||||||
+14
-23
@@ -3,12 +3,11 @@ version: '3.8' # Use a recent version
|
|||||||
services:
|
services:
|
||||||
# --- Web API ---
|
# --- Web API ---
|
||||||
api:
|
api:
|
||||||
build: # Tells docker-compose to build the Dockerfile in the current directory
|
build:
|
||||||
context: .
|
context: .
|
||||||
ssh: ["default"] # Uses host's SSH agent
|
ssh: ["default"]
|
||||||
container_name: icarus # Optional: Give the container a specific name
|
container_name: icarus
|
||||||
ports:
|
ports:
|
||||||
# Map host port 8000 to container port 3000 (adjust as needed)
|
|
||||||
- "8000:8000"
|
- "8000:8000"
|
||||||
env_file:
|
env_file:
|
||||||
- .env
|
- .env
|
||||||
@@ -17,21 +16,18 @@ services:
|
|||||||
condition: service_healthy
|
condition: service_healthy
|
||||||
networks:
|
networks:
|
||||||
- icarus-network
|
- icarus-network
|
||||||
restart: unless-stopped # Optional: Restart policy
|
restart: unless-stopped
|
||||||
|
|
||||||
# --- Web API auth ---
|
# --- Web API auth ---
|
||||||
auth_api:
|
auth_api:
|
||||||
build:
|
build:
|
||||||
context: ../icarus_auth # IMPORTANT: Relative path to the local checkout of your web API repo (containing the Dockerfile)
|
context: ../icarus_auth # IMPORTANT: Relative path to the local checkout of your web API repo (containing the Dockerfile)
|
||||||
ssh: ["default"] # Uses host's SSH agent
|
ssh: ["default"]
|
||||||
dockerfile: Dockerfile # Optional: Specify if your Dockerfile has a non-standard name
|
dockerfile: Dockerfile # Optional: Specify if your Dockerfile has a non-standard name
|
||||||
container_name: auth_api
|
container_name: auth_api
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
ports:
|
ports:
|
||||||
- "8001:8001" # Map host port 8000 to container port 8000 (adjust container port based on your app's EXPOSE in Dockerfile)
|
- "8001:8001"
|
||||||
# environment:
|
|
||||||
# Environment variables your API needs, e.g., database connection
|
|
||||||
# Add other necessary environment variables
|
|
||||||
env_file:
|
env_file:
|
||||||
- ../icarus_auth/.env
|
- ../icarus_auth/.env
|
||||||
depends_on:
|
depends_on:
|
||||||
@@ -63,10 +59,9 @@ services:
|
|||||||
|
|
||||||
|
|
||||||
# PostgreSQL Database Service
|
# PostgreSQL Database Service
|
||||||
# --- icarus web api db ---
|
|
||||||
main_db:
|
main_db:
|
||||||
image: postgres:18.3-alpine # Use an official Postgres image (Alpine variant is smaller)
|
image: postgres:18.4-alpine
|
||||||
container_name: icarus_db # Optional: Give the container a specific name
|
container_name: icarus_db
|
||||||
environment:
|
environment:
|
||||||
# These MUST match the user, password, and database name in the DATABASE_URL above
|
# These MUST match the user, password, and database name in the DATABASE_URL above
|
||||||
POSTGRES_USER: ${POSTGRES_MAIN_USER:-icarus}
|
POSTGRES_USER: ${POSTGRES_MAIN_USER:-icarus}
|
||||||
@@ -74,9 +69,8 @@ services:
|
|||||||
POSTGRES_DB: ${POSTGRES_MAIN_DB:-icarus_db}
|
POSTGRES_DB: ${POSTGRES_MAIN_DB:-icarus_db}
|
||||||
volumes:
|
volumes:
|
||||||
# Persist database data using a named volume
|
# Persist database data using a named volume
|
||||||
- postgres_data:/var/lib/postgresql/data
|
- postgres_data:/var/lib/postgresql
|
||||||
ports:
|
ports:
|
||||||
# Optional: Expose port 5432 ONLY if you need to connect directly from your host machine (e.g., for debugging)
|
|
||||||
- "5432:5432"
|
- "5432:5432"
|
||||||
healthcheck:
|
healthcheck:
|
||||||
# Checks if Postgres is ready to accept connections
|
# Checks if Postgres is ready to accept connections
|
||||||
@@ -85,14 +79,14 @@ services:
|
|||||||
timeout: 5s
|
timeout: 5s
|
||||||
retries: 5
|
retries: 5
|
||||||
start_period: 10s
|
start_period: 10s
|
||||||
restart: always # Optional: Restart policy
|
restart: always
|
||||||
networks:
|
networks:
|
||||||
- icarus-network
|
- icarus-network
|
||||||
|
|
||||||
# --- icarus web auth api db ---
|
# --- icarus web auth api db ---
|
||||||
auth_db:
|
auth_db:
|
||||||
image: postgres:18.3-alpine # Use an official Postgres image (Alpine variant is smaller)
|
image: postgres:18.4-alpine
|
||||||
container_name: icarus_auth_db # Optional: Give the container a specific name
|
container_name: icarus_auth_db
|
||||||
environment:
|
environment:
|
||||||
# These MUST match the user, password, and database name in the DATABASE_URL above
|
# These MUST match the user, password, and database name in the DATABASE_URL above
|
||||||
POSTGRES_USER: ${POSTGRES_AUTH_USER:-icarus_op}
|
POSTGRES_USER: ${POSTGRES_AUTH_USER:-icarus_op}
|
||||||
@@ -100,9 +94,8 @@ services:
|
|||||||
POSTGRES_DB: ${POSTGRES_AUTH_DB:-icarus_auth_db}
|
POSTGRES_DB: ${POSTGRES_AUTH_DB:-icarus_auth_db}
|
||||||
volumes:
|
volumes:
|
||||||
# Persist database data using a named volume
|
# Persist database data using a named volume
|
||||||
- postgres_data_auth:/var/lib/postgresql/data
|
- postgres_data_auth:/var/lib/postgresql
|
||||||
ports:
|
ports:
|
||||||
# Optional: Expose port 5432 ONLY if you need to connect directly from your host machine (e.g., for debugging)
|
|
||||||
- "5433:5432"
|
- "5433:5432"
|
||||||
healthcheck:
|
healthcheck:
|
||||||
# Checks if Postgres is ready to accept connections
|
# Checks if Postgres is ready to accept connections
|
||||||
@@ -111,18 +104,16 @@ services:
|
|||||||
timeout: 5s
|
timeout: 5s
|
||||||
retries: 5
|
retries: 5
|
||||||
start_period: 10s
|
start_period: 10s
|
||||||
restart: always # Optional: Restart policy
|
restart: always
|
||||||
networks:
|
networks:
|
||||||
- icarus-network
|
- icarus-network
|
||||||
|
|
||||||
# Define the named volume for data persistence
|
|
||||||
volumes:
|
volumes:
|
||||||
postgres_data:
|
postgres_data:
|
||||||
driver: local # Use the default local driver
|
driver: local # Use the default local driver
|
||||||
postgres_data_auth:
|
postgres_data_auth:
|
||||||
driver: local # Use the default local driver
|
driver: local # Use the default local driver
|
||||||
|
|
||||||
# Define the network (optional, but good practice)
|
|
||||||
networks:
|
networks:
|
||||||
icarus-network:
|
icarus-network:
|
||||||
driver: bridge
|
driver: bridge
|
||||||
|
|||||||
+1
-1
@@ -36,7 +36,7 @@ pub async fn auth<B>(
|
|||||||
(StatusCode::UNAUTHORIZED, Json(json_error))
|
(StatusCode::UNAUTHORIZED, Json(json_error))
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
let secret_key = icarus_envy::environment::get_secret_main_key().await.value;
|
let secret_key = icarus_envy::environment::get_secret_main_key().value;
|
||||||
|
|
||||||
let mut validation = Validation::new(jsonwebtoken::Algorithm::HS256);
|
let mut validation = Validation::new(jsonwebtoken::Algorithm::HS256);
|
||||||
validation.set_audience(&["icarus"]); // Must match exactly what's in the token
|
validation.set_audience(&["icarus"]); // Must match exactly what's in the token
|
||||||
|
|||||||
@@ -68,7 +68,7 @@ pub mod endpoint {
|
|||||||
let song_id = payload.song_id;
|
let song_id = payload.song_id;
|
||||||
match crate::repo::song::get_song(&pool, &song_id).await {
|
match crate::repo::song::get_song(&pool, &song_id).await {
|
||||||
Ok(song) => {
|
Ok(song) => {
|
||||||
let directory = icarus_envy::environment::get_root_directory().await.value;
|
let directory = icarus_envy::environment::get_root_directory().value;
|
||||||
let file_type =
|
let file_type =
|
||||||
icarus_meta::detection::coverart::file_type_from_data(&data).unwrap();
|
icarus_meta::detection::coverart::file_type_from_data(&data).unwrap();
|
||||||
let coverart_type = if file_type.file_type
|
let coverart_type = if file_type.file_type
|
||||||
|
|||||||
+1
-1
@@ -139,7 +139,7 @@ pub mod endpoint {
|
|||||||
true,
|
true,
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
song.directory = icarus_envy::environment::get_root_directory().await.value;
|
song.directory = icarus_envy::environment::get_root_directory().value;
|
||||||
|
|
||||||
match repo_queue::song::get_data(&pool, &payload.song_queue_id).await {
|
match repo_queue::song::get_data(&pool, &payload.song_queue_id).await {
|
||||||
Ok(data) => {
|
Ok(data) => {
|
||||||
|
|||||||
+3
-1
@@ -40,7 +40,7 @@ mod cors {
|
|||||||
match std::env::var(icarus_envy::keys::APP_ENV).as_deref() {
|
match std::env::var(icarus_envy::keys::APP_ENV).as_deref() {
|
||||||
Ok("production") => {
|
Ok("production") => {
|
||||||
// In production, allow only your specific, trusted origins
|
// In production, allow only your specific, trusted origins
|
||||||
let allowed_origins_env = icarus_envy::environment::get_allowed_origins().await;
|
let allowed_origins_env = icarus_envy::environment::get_allowed_origins();
|
||||||
match icarus_envy::utility::delimitize(&allowed_origins_env) {
|
match icarus_envy::utility::delimitize(&allowed_origins_env) {
|
||||||
Ok(alwd) => {
|
Ok(alwd) => {
|
||||||
let allowed_origins: Vec<axum::http::HeaderValue> = alwd
|
let allowed_origins: Vec<axum::http::HeaderValue> = alwd
|
||||||
@@ -60,6 +60,8 @@ mod cors {
|
|||||||
cors.allow_origin(vec![
|
cors.allow_origin(vec![
|
||||||
"http://localhost:8000".parse().unwrap(),
|
"http://localhost:8000".parse().unwrap(),
|
||||||
"http://127.0.0.1:8000".parse().unwrap(),
|
"http://127.0.0.1:8000".parse().unwrap(),
|
||||||
|
"http://localhost:8001".parse().unwrap(),
|
||||||
|
"http://127.0.0.1:8001".parse().unwrap(),
|
||||||
"http://localhost:4200".parse().unwrap(),
|
"http://localhost:4200".parse().unwrap(),
|
||||||
"http://127.0.0.1:4200".parse().unwrap(),
|
"http://127.0.0.1:4200".parse().unwrap(),
|
||||||
])
|
])
|
||||||
|
|||||||
+1
-3
@@ -5,7 +5,7 @@ pub mod connection_settings {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub async fn create_pool() -> Result<sqlx::PgPool, sqlx::Error> {
|
pub async fn create_pool() -> Result<sqlx::PgPool, sqlx::Error> {
|
||||||
let database_url = icarus_envy::environment::get_db_url().await.value;
|
let database_url = icarus_envy::environment::get_db_url().value;
|
||||||
println!("Database url: {database_url}");
|
println!("Database url: {database_url}");
|
||||||
|
|
||||||
PgPoolOptions::new()
|
PgPoolOptions::new()
|
||||||
@@ -15,8 +15,6 @@ pub async fn create_pool() -> Result<sqlx::PgPool, sqlx::Error> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub async fn migrations(pool: &sqlx::PgPool) {
|
pub async fn migrations(pool: &sqlx::PgPool) {
|
||||||
// Run migrations using the sqlx::migrate! macro
|
|
||||||
// Assumes your migrations are in a ./migrations folder relative to Cargo.toml
|
|
||||||
sqlx::migrate!("./migrations")
|
sqlx::migrate!("./migrations")
|
||||||
.run(pool)
|
.run(pool)
|
||||||
.await
|
.await
|
||||||
|
|||||||
+16
-8
@@ -38,7 +38,7 @@ mod tests {
|
|||||||
pub const LIMIT: usize = 6;
|
pub const LIMIT: usize = 6;
|
||||||
|
|
||||||
pub async fn get_pool() -> Result<sqlx::PgPool, sqlx::Error> {
|
pub async fn get_pool() -> Result<sqlx::PgPool, sqlx::Error> {
|
||||||
let tm_db_url = icarus_envy::environment::get_db_url().await.value;
|
let tm_db_url = icarus_envy::environment::get_db_url().value;
|
||||||
let tm_options = sqlx::postgres::PgConnectOptions::from_str(&tm_db_url).unwrap();
|
let tm_options = sqlx::postgres::PgConnectOptions::from_str(&tm_db_url).unwrap();
|
||||||
sqlx::PgPool::connect_with(tm_options).await
|
sqlx::PgPool::connect_with(tm_options).await
|
||||||
}
|
}
|
||||||
@@ -51,7 +51,7 @@ mod tests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub async fn connect_to_db(db_name: &str) -> Result<sqlx::PgPool, sqlx::Error> {
|
pub async fn connect_to_db(db_name: &str) -> Result<sqlx::PgPool, sqlx::Error> {
|
||||||
let db_url = icarus_envy::environment::get_db_url().await.value;
|
let db_url = icarus_envy::environment::get_db_url().value;
|
||||||
let options = sqlx::postgres::PgConnectOptions::from_str(&db_url)?.database(db_name);
|
let options = sqlx::postgres::PgConnectOptions::from_str(&db_url)?.database(db_name);
|
||||||
sqlx::PgPool::connect_with(options).await
|
sqlx::PgPool::connect_with(options).await
|
||||||
}
|
}
|
||||||
@@ -61,7 +61,10 @@ mod tests {
|
|||||||
db_name: &str,
|
db_name: &str,
|
||||||
) -> Result<(), sqlx::Error> {
|
) -> Result<(), sqlx::Error> {
|
||||||
let create_query = format!("CREATE DATABASE {}", db_name);
|
let create_query = format!("CREATE DATABASE {}", db_name);
|
||||||
match sqlx::query(&create_query).execute(template_pool).await {
|
match sqlx::query(sqlx::AssertSqlSafe(create_query))
|
||||||
|
.execute(template_pool)
|
||||||
|
.await
|
||||||
|
{
|
||||||
Ok(_) => Ok(()),
|
Ok(_) => Ok(()),
|
||||||
Err(e) => Err(e),
|
Err(e) => Err(e),
|
||||||
}
|
}
|
||||||
@@ -73,12 +76,14 @@ mod tests {
|
|||||||
db_name: &str,
|
db_name: &str,
|
||||||
) -> Result<(), sqlx::Error> {
|
) -> Result<(), sqlx::Error> {
|
||||||
let drop_query = format!("DROP DATABASE IF EXISTS {} WITH (FORCE)", db_name);
|
let drop_query = format!("DROP DATABASE IF EXISTS {} WITH (FORCE)", db_name);
|
||||||
sqlx::query(&drop_query).execute(template_pool).await?;
|
sqlx::query(sqlx::AssertSqlSafe(drop_query))
|
||||||
|
.execute(template_pool)
|
||||||
|
.await?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn get_database_name() -> Result<String, Box<dyn std::error::Error>> {
|
pub async fn get_database_name() -> Result<String, Box<dyn std::error::Error>> {
|
||||||
let database_url = icarus_envy::environment::get_db_url().await.value;
|
let database_url = icarus_envy::environment::get_db_url().value;
|
||||||
let parsed_url = url::Url::parse(&database_url)?;
|
let parsed_url = url::Url::parse(&database_url)?;
|
||||||
|
|
||||||
if parsed_url.scheme() == "postgres" || parsed_url.scheme() == "postgresql" {
|
if parsed_url.scheme() == "postgres" || parsed_url.scheme() == "postgresql" {
|
||||||
@@ -106,13 +111,16 @@ mod tests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
mod init {
|
mod init {
|
||||||
|
use std::time::Duration;
|
||||||
|
|
||||||
pub async fn app(pool: sqlx::PgPool) -> axum::Router {
|
pub async fn app(pool: sqlx::PgPool) -> axum::Router {
|
||||||
crate::config::init::routes()
|
crate::config::init::routes()
|
||||||
.await
|
.await
|
||||||
.layer(axum::Extension(pool))
|
.layer(axum::Extension(pool))
|
||||||
.layer(axum::extract::DefaultBodyLimit::max(1024 * 1024 * 1024))
|
.layer(axum::extract::DefaultBodyLimit::max(1024 * 1024 * 1024))
|
||||||
.layer(tower_http::timeout::TimeoutLayer::new(
|
.layer(tower_http::timeout::TimeoutLayer::with_status_code(
|
||||||
std::time::Duration::from_secs(300),
|
axum::http::StatusCode::OK,
|
||||||
|
Duration::from_secs(300),
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -149,7 +157,7 @@ mod tests {
|
|||||||
pub const TEST_USER_ID: uuid::Uuid = uuid::uuid!("cc938368-615a-4694-b2ca-6e122fa31c52");
|
pub const TEST_USER_ID: uuid::Uuid = uuid::uuid!("cc938368-615a-4694-b2ca-6e122fa31c52");
|
||||||
|
|
||||||
pub async fn test_token() -> Result<String, josekit::JoseError> {
|
pub async fn test_token() -> Result<String, josekit::JoseError> {
|
||||||
let key: String = icarus_envy::environment::get_secret_main_key().await.value;
|
let key: String = icarus_envy::environment::get_secret_main_key().value;
|
||||||
let (message, issuer, audience) = token_fields();
|
let (message, issuer, audience) = token_fields();
|
||||||
|
|
||||||
let token_resource = icarus_models::token::TokenResource {
|
let token_resource = icarus_models::token::TokenResource {
|
||||||
|
|||||||
Reference in New Issue
Block a user