Compare commits

..
16 Commits
Author SHA1 Message Date
phoenix e2a5e02aad Trying
soaricarus_api CI / Rustfmt (pull_request) Successful in 2m21s
soaricarus_api CI / Test Suite (pull_request) Successful in 3m55s
soaricarus_api CI / Check (pull_request) Successful in 4m15s
soaricarus_api CI / Clippy (pull_request) Successful in 4m22s
soaricarus_api CI / build (pull_request) Successful in 3m48s
2026-07-24 19:12:19 -04:00
phoenix 6574d0ee8f I am tired boss
soaricarus_api CI / Rustfmt (pull_request) Successful in 2m26s
soaricarus_api CI / Check (pull_request) Successful in 3m24s
soaricarus_api CI / Clippy (pull_request) Successful in 3m43s
soaricarus_api CI / Test Suite (pull_request) Successful in 6m32s
soaricarus_api CI / build (pull_request) Successful in 3m25s
2026-07-24 15:33:18 -04:00
phoenix 75f4d9fa76 Saving changes. No real progress yet
soaricarus_api CI / Test Suite (pull_request) Successful in 3m36s
soaricarus_api CI / Check (pull_request) Successful in 4m3s
soaricarus_api CI / Rustfmt (pull_request) Successful in 5m49s
soaricarus_api CI / Clippy (pull_request) Successful in 2m24s
soaricarus_api CI / build (pull_request) Successful in 4m32s
2026-07-24 12:23:48 -04:00
phoenix 3de818f280 Saving changes
soaricarus_api CI / Rustfmt (pull_request) Successful in 3m50s
soaricarus_api CI / Check (pull_request) Successful in 5m0s
soaricarus_api CI / Test Suite (pull_request) Successful in 6m7s
soaricarus_api CI / Clippy (pull_request) Successful in 3m28s
soaricarus_api CI / build (pull_request) Successful in 3m42s
2026-07-23 17:19:29 -04:00
phoenix f116adffdb Saving changes. Nothing yet 2026-07-23 16:26:14 -04:00
phoenix 3965d86d54 Saving script 2026-07-23 16:21:40 -04:00
phoenix 8fae71b086 Getting somewhere. Object Storage is initialized but not initializing hangs 2026-07-23 16:05:21 -04:00
phoenix 2bfb8c6aee Got garage to run in docker
soaricarus_api CI / Rustfmt (pull_request) Successful in 2m13s
soaricarus_api CI / Check (pull_request) Successful in 4m13s
soaricarus_api CI / Test Suite (pull_request) Successful in 5m55s
soaricarus_api CI / Clippy (pull_request) Successful in 4m30s
soaricarus_api CI / build (pull_request) Successful in 4m57s
2026-07-23 15:31:41 -04:00
phoenix 327d04e8a9 Revert "Removing garage.toml"
soaricarus_api CI / Clippy (pull_request) Canceled after 0s
soaricarus_api CI / build (pull_request) Canceled after 0s
soaricarus_api CI / Check (pull_request) Canceled after 2m22s
soaricarus_api CI / Rustfmt (pull_request) Canceled after 2m10s
soaricarus_api CI / Test Suite (pull_request) Canceled after 4m15s
This reverts commit 7a209eeb5e.
2026-07-23 15:28:58 -04:00
phoenix 7a209eeb5e Removing garage.toml 2026-07-23 15:15:11 -04:00
phoenix 7460f0d157 Updating some of the sample env
soaricarus_api CI / Rustfmt (pull_request) Successful in 3m17s
soaricarus_api CI / Check (pull_request) Successful in 4m30s
soaricarus_api CI / Test Suite (pull_request) Successful in 4m38s
soaricarus_api CI / Clippy (pull_request) Successful in 3m58s
soaricarus_api CI / build (pull_request) Successful in 3m8s
2026-07-22 17:20:58 -04:00
phoenix 4b7816e117 Adding image to store data 2026-07-22 17:20:37 -04:00
phoenix 59a7e31641 Updating name (#253)
soaricarus_api CI / Check (push) Successful in 3m21s
soaricarus_api CI / Test Suite (push) Successful in 4m25s
soaricarus_api CI / Rustfmt (push) Successful in 3m8s
soaricarus_api CI / Clippy (push) Successful in 3m56s
soaricarus_api CI / build (push) Successful in 3m3s
Reviewed-on: #253
2026-07-21 15:28:48 -04:00
phoenix 8a64a71339 Update postgres (#252)
Rust CI / Test Suite (push) Successful in 3m43s
Rust CI / Rustfmt (push) Successful in 2m2s
Rust CI / Check (push) Successful in 3m9s
Rust CI / build (push) Successful in 2m58s
Rust CI / Clippy (push) Successful in 4m28s
Reviewed-on: phoenix/icarus#252
2026-07-09 11:05:12 -04:00
phoenix 7ca4c655a4 Update (#251)
Rust CI / build (push) Failing after 2m53s
Reviewed-on: phoenix/icarus#251
2026-07-07 23:25:45 -04:00
phoenixandGitHub 50d0ea630f Update rust (#250)
Rust CI / build (pull_request) Failing after 2m21s
* bump: rust Cargo.toml

* bump: rust docker

* bump: rust ci

* bump: axum

* bump: axum-extra

* bump: tokio

* bump: tower-http

* bump: uuid

* bump: utoipa

* bump: icarus_meta

* bump: icarus_models

* bump: icarus_envy

* bump: icarus

* Updated base image in dockerfile

* Adding sample local env file

* Fixing postgresql volume issue in docker
2026-05-22 11:29:38 -04:00
25 changed files with 1246 additions and 961 deletions
+21 -4
View File
@@ -4,9 +4,26 @@ 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
ROOT_DIRECTORY=/home/soaricarus/mydata
POSTGRES_MAIN_USER=soaricarus
POSTGRES_MAIN_PASSWORD=password
POSTGRES_MAIN_DB=icarus_db
POSTGRES_MAIN_DB=soaricarus_db
POSTGRES_MAIN_HOST=main_db
DATABASE_URL=postgres://${POSTGRES_MAIN_USER}:${POSTGRES_MAIN_PASSWORD}@${POSTGRES_MAIN_HOST}:5432/${POSTGRES_MAIN_DB}
POSTGRES_MAIN_PORT=5432
DATABASE_URL=postgres://${POSTGRES_MAIN_USER}:${POSTGRES_MAIN_PASSWORD}@${POSTGRES_MAIN_HOST}:${POSTGRES_MAIN_PORT}/${POSTGRES_MAIN_DB}
GARAGE_RPC_SECRET=c2bde5c3f9c04116a7563e25ea5ba6fab25319daa2fe8a952ad57d0b8159b590
GARAGE_METADATA_DIR=/var/lib/garage/meta
GARAGE_DATA_DIR=/var/lib/garage/data
GARAGE_DB_ENGINE=sqlite
GARAGE_REPLICATION_FACTOR=1
GARAGE_RPC_BIND_ADDR=[::]:3901
GARAGE_S3_API_BIND_ADDR=[::]:3900
GARAGE_S3_WEB_BIND_ADDR=[::]:3902
GARAGE_S3_REGION=maze
GARAGE_ROOT_DOMAIN=.localhost
AWS_DEFAULT_REGION=maze
AWS_SECRET_ACCESS_KEY=3o4n7yfo34985yrfcq9238765ry3928475rcy349857ty394578cy
AWS_ACCESS_KEY_ID=2q39fnoy59q2347yfdrc327894ryfc0q2834rcyq023897
S3_BUCKET_NAME=soaricarus-storage
+8 -7
View File
@@ -1,12 +1,13 @@
APP_ENV=production
APP_ENV=development
BACKEND_PORT=8000
FRONTEND_URL=http://localhost:4200
RUST_LOG=debug
ALLOWED_ORIGINS=https://soaricarus.com,https://www.soaricarus.com,http://localhost:8000,http://127.0.0.1:8000
ALLOWED_ORIGINS=https://soaricarus.com,https://www.soaricarus.com
SECRET_MAIN_KEY=refero34o8rfhfjn983thf39fhc943rf923n3h
ROOT_DIRECTORY=/home/icarus/mydata
POSTGRES_MAIN_USER=icarus
ROOT_DIRECTORY=/home/soaricarus/mydata
POSTGRES_MAIN_USER=soaricarus
POSTGRES_MAIN_PASSWORD=password
POSTGRES_MAIN_DB=icarus_db
POSTGRES_MAIN_HOST=localhost
DATABASE_URL=postgres://${POSTGRES_MAIN_USER}:${POSTGRES_MAIN_PASSWORD}@${POSTGRES_MAIN_HOST}:5432/${POSTGRES_MAIN_DB}
POSTGRES_MAIN_DB=soaricarus_db
POSTGRES_MAIN_HOST=main_db
POSTGRES_MAIN_PORT=5432
DATABASE_URL=postgres://${POSTGRES_MAIN_USER}:${POSTGRES_MAIN_PASSWORD}@${POSTGRES_MAIN_HOST}:${POSTGRES_MAIN_PORT}/${POSTGRES_MAIN_DB}
+2 -2
View File
@@ -9,14 +9,14 @@ jobs:
runs-on: ubuntu-24.04
steps:
- name: Checkout code
uses: actions/checkout@v5
uses: actions/checkout@v6
with:
fetch-depth: 0 # Important for git describe --tags
- name: Install Rust
uses: actions-rs/toolchain@v1
with:
toolchain: 1.94
toolchain: 1.97
components: cargo
- name: Extract Version from Cargo.toml
+125 -60
View File
@@ -1,4 +1,4 @@
name: Rust CI
name: soaricarus_api CI
on:
push:
@@ -6,18 +6,42 @@ on:
pull_request:
branches: [ "main" ]
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
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.97
- uses: Swatinem/rust-cache@v2
- run: |
mkdir -p ~/.ssh
echo "${{ secrets.MYREPO_TOKEN }}" > ~/.ssh/soaricarus_models_deploy_key
chmod 600 ~/.ssh/soaricarus_models_deploy_key
ssh-keyscan ${{ secrets.MYHOST }} >> ~/.ssh/known_hosts
eval $(ssh-agent -s)
ssh-add -v ~/.ssh/soaricarus_models_deploy_key
cargo check
test:
name: Test Suite
runs-on: ubuntu-24.04
services:
postgres:
image: postgres:18.3-alpine
image: postgres:18.4-alpine
env:
POSTGRES_PASSWORD: ${{ secrets.POSTGRES_PASSWORD }}
POSTGRES_USER: ${{ secrets.POSTGRES_USER }}
POSTGRES_DB: ${{ secrets.POSTGRES_DB }}
ports:
- 5432:5432
POSTGRES_USER: ${{ secrets.DB_TEST_USER || 'testuser' }}
POSTGRES_PASSWORD: ${{ secrets.DB_TEST_PASSWORD || 'testpassword' }}
POSTGRES_DB: ${{ secrets.DB_TEST_NAME || 'testdb' }}
options: >-
--health-cmd pg_isready
--health-interval 10s
@@ -25,55 +49,96 @@ jobs:
--health-retries 5
steps:
- uses: actions/checkout@v5
- name: Install Rust 1.94
uses: actions-rs/toolchain@v1
with:
toolchain: 1.94
components: clippy, rustfmt
override: true
- name: Cache dependencies
uses: Swatinem/rust-cache@v2
- name: Install libpq
run: sudo apt-get install -y libpq-dev
- name: Setup test database
env:
DATABASE_URL: "postgres://${{ secrets.POSTGRES_USER }}:${{ secrets.POSTGRES_PASSWORD }}@localhost:5432/${{ secrets.POSTGRES_DB }}"
run: |
# Wait for PostgreSQL to be ready
for i in {1..10}; do
pg_isready -U ${{ secrets.POSTGRES_USER }} -d ${{ secrets.POSTGRES_DB }} && break
sleep 2
done
# Run database migrations (if you use sqlx migrations)
cargo install sqlx-cli --no-default-features --features native-tls,postgres
sqlx migrate run --database-url $DATABASE_URL
- name: Build
run: |
mkdir -p ~/.ssh
echo "${{ secrets.MYREPO_TOKEN }}" > ~/.ssh/gitea_deploy_key
chmod 600 ~/.ssh/gitea_deploy_key
ssh-keyscan ${{ vars.MYHOST }} >> ~/.ssh/known_hosts
eval $(ssh-agent -s)
ssh-add -v ~/.ssh/gitea_deploy_key
cargo build --verbose --release
- name: Run tests
env:
ROOT_DIRECTORY: "/tmp"
DATABASE_URL: "postgres://${{ secrets.POSTGRES_USER }}:${{ secrets.POSTGRES_PASSWORD }}@localhost:5432/${{ secrets.POSTGRES_DB }}"
run: |
cat .env.sample | head -6 > .env
cargo test --verbose --
- name: Run clippy
run: cargo clippy -- -D warnings
- name: Run rustfmt
run: cargo fmt --all -- --check
- uses: actions/checkout@v6
- uses: actions-rust-lang/setup-rust-toolchain@v1
with:
toolchain: 1.97
- uses: Swatinem/rust-cache@v2
- name: Verify Docker Environment
run: |
echo "Runner User Info:"
id
echo "Checking Docker Version:"
docker --version
echo "Checking Docker Daemon Status (info):"
docker info
echo "Checking Docker Daemon Status (ps):"
docker ps -a
echo "Docker environment check complete."
- name: Run tests
env:
# Define DATABASE_URL for tests to use
DATABASE_URL: postgresql://${{ secrets.DB_TEST_USER || 'testuser' }}:${{ secrets.DB_TEST_PASSWORD || 'testpassword' }}@postgres:5432/${{ secrets.DB_TEST_NAME || 'testdb' }}
RUST_LOG: info # Optional: configure test log level
SECRET_MAIN_KEY: ${{ secrets.TOKEN_SECRET_KEY }}
SSH_AUTH_SOCK: ${{ env.SSH_AUTH_SOCK }}
ROOT_DIRECTORY: "/tmp"
run: |
mkdir -p ~/.ssh
echo "${{ secrets.MYREPO_TOKEN }}" > ~/.ssh/soaricarus_models_deploy_key
chmod 600 ~/.ssh/soaricarus_models_deploy_key
ssh-keyscan ${{ secrets.MYHOST }} >> ~/.ssh/known_hosts
eval $(ssh-agent -s)
ssh-add -v ~/.ssh/soaricarus_models_deploy_key
cargo test
fmt:
name: Rustfmt
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v6
- uses: actions-rust-lang/setup-rust-toolchain@v1
with:
toolchain: 1.97
- uses: Swatinem/rust-cache@v2
- run: rustup component add rustfmt
- run: |
mkdir -p ~/.ssh
echo "${{ secrets.MYREPO_TOKEN }}" > ~/.ssh/soaricarus_models_deploy_key
chmod 600 ~/.ssh/soaricarus_models_deploy_key
ssh-keyscan ${{ secrets.MYHOST }} >> ~/.ssh/known_hosts
eval $(ssh-agent -s)
ssh-add -v ~/.ssh/soaricarus_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.97
- uses: Swatinem/rust-cache@v2
- run: rustup component add clippy
- run: |
mkdir -p ~/.ssh
echo "${{ secrets.MYREPO_TOKEN }}" > ~/.ssh/soaricarus_models_deploy_key
chmod 600 ~/.ssh/soaricarus_models_deploy_key
ssh-keyscan ${{ secrets.MYHOST }} >> ~/.ssh/known_hosts
eval $(ssh-agent -s)
ssh-add -v ~/.ssh/soaricarus_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.97
- uses: Swatinem/rust-cache@v2
- run: |
mkdir -p ~/.ssh
echo "${{ secrets.MYREPO_TOKEN }}" > ~/.ssh/soaricarus_models_deploy_key
chmod 600 ~/.ssh/soaricarus_models_deploy_key
ssh-keyscan ${{ secrets.MYHOST }} >> ~/.ssh/known_hosts
eval $(ssh-agent -s)
ssh-add -v ~/.ssh/soaricarus_models_deploy_key
cargo build --release
Generated
+494 -669
View File
File diff suppressed because it is too large Load Diff
+19 -18
View File
@@ -1,33 +1,34 @@
[package]
name = "icarus"
version = "0.4.0"
name = "soaricarus_api"
version = "0.5.2"
edition = "2024"
rust-version = "1.94"
rust-version = "1.95"
license = "MIT"
description = "Core API for interacting with soaricarus"
[dependencies]
axum = { version = "0.8.8", features = ["multipart"] }
axum-extra = { version = "0.12.5", features = ["cookie"] }
axum = { version = "0.8.9", features = ["multipart"] }
axum-extra = { version = "0.12.6", features = ["cookie"] }
openssl = { version = "0.10.81", features = ["vendored"] }
serde = { version = "1.0.228", features = ["derive"] }
serde_json = { version = "1.0.149" }
tower = { version = "0.5.3", features = ["full"] }
tokio = { version = "1.51", features = ["full"] }
serde_json = { version = "1.0.150" }
tokio = { version = "1.52.3", features = ["full"] }
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"
futures = { version = "0.3.32" }
mime_guess = { version = "2.0.5" }
uuid = { version = "1.23", features = ["v4", "serde"] }
sqlx = { version = "0.8.6", features = ["postgres", "runtime-tokio-native-tls", "time", "uuid"] }
time = { version = "0.3.47", features = ["formatting", "macros", "parsing", "serde"] }
thiserror = "2.0.18"
base64 = "0.22.1"
uuid = { version = "1.23.5", features = ["v4", "serde"] }
sqlx = { version = "0.9.0", features = ["postgres", "runtime-tokio", "tls-native-tls", "time", "uuid"] }
time = { version = "0.3.53", features = ["formatting", "macros", "parsing", "serde"] }
jsonwebtoken = { version = "10.3.0", features = ["rust_crypto"] }
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"] }
icarus_meta = { git = "ssh://git@git.kundeng.us/phoenix/icarus_meta.git", tag = "v0.5.0" }
icarus_models = { git = "ssh://git@git.kundeng.us/phoenix/icarus_models.git", tag = "v0.10.0" }
icarus_envy = { git = "ssh://git@git.kundeng.us/phoenix/icarus_envy.git", tag = "v0.6.0" }
simeta = { git = "ssh://git@git.kundeng.us/phoenix/simeta.git", tag = "v0.6.1-main-b690995806-680" }
simodels = { git = "ssh://git@git.kundeng.us/phoenix/simodels.git", tag = "v0.11.3-main-fe9d101bd0-111" }
sienvy = { git = "ssh://git@git.kundeng.us/phoenix/sienvy.git", tag = "v0.8.0-main-d06c8fdf49-006" }
[dev-dependencies]
common-multipart-rfc7578 = { version = "0.7.0" }
+9 -23
View File
@@ -1,5 +1,4 @@
# Stage 1: Build the application
FROM rust:1.94 as builder
FROM rust:1.97 as builder
# Set the working directory inside the container
WORKDIR /usr/src/app
@@ -17,35 +16,29 @@ RUN mkdir -p -m 0700 ~/.ssh && \
echo " User git" >> ~/.ssh/config && \
chmod 600 ~/.ssh/config
# << --- ADD HOST KEY HERE --- >>
RUN ssh-keyscan git.kundeng.us >> ~/.ssh/known_hosts
# Copy Cargo manifests
COPY Cargo.toml Cargo.lock ./
# Build *only* dependencies to leverage Docker cache
# This dummy build caches dependencies as a separate layer
RUN --mount=type=ssh mkdir src && \
echo "fn main() {println!(\"if you see this, the build broke\")}" > src/main.rs && \
cargo build --release --quiet && \
rm -rf src target/release/deps/icarus* # Clean up dummy build artifacts (replace icarus)
rm -rf src target/release/deps/soaricarus_api*
# Copy the actual source code
COPY src ./src
# If you have other directories like `templates` or `static`, copy them too
COPY .env ./.env
COPY migrations ./migrations
COPY scripts/init-garage.sh /scripts/init-garage.sh
# Make it executable
RUN chmod +x /scripts/init-garage.sh
# << --- SSH MOUNT ADDED HERE --- >>
# Build *only* dependencies to leverage Docker cache
# This dummy build caches dependencies as a separate layer
# Mount the SSH agent socket for this command
RUN --mount=type=ssh \
cargo build --release --quiet
# Stage 2: Create the final, smaller runtime image
# 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)
RUN apt-get update && apt-get install -y ca-certificates libssl-dev libssl3 && rm -rf /var/lib/apt/lists/*
@@ -53,18 +46,11 @@ RUN apt-get update && apt-get install -y ca-certificates libssl-dev libssl3 && r
# Set the working directory
WORKDIR /usr/local/bin
# Copy the compiled binary from the builder stage
# Replace 'icarus' with the actual name of your binary (usually the crate name)
COPY --from=builder /usr/src/app/target/release/icarus .
COPY --from=builder /usr/src/app/target/release/soaricarus_api .
# Copy other necessary files like .env (if used for runtime config) or static assets
# It's generally better to configure via environment variables in Docker though
COPY --from=builder /usr/src/app/.env .
COPY --from=builder /usr/src/app/migrations ./migrations
# Expose the port your Axum app listens on (e.g., 3000 or 8000)
EXPOSE 8000
# Set the command to run your application
# Ensure this matches the binary name copied above
CMD ["./icarus"]
CMD ["./soaricarus_api"]
+7 -7
View File
@@ -1,19 +1,19 @@
# Icarus
Web API for the Icarus project.
# soaricarus_api
Core web API for the soaricarus project.
### Requires
`icarus_auth` v0.7.x
`songparser` v0.5.x
`soaricarus_auth` v0.8.x
`songparser` v0.6.x
### Compatible with
`icarus-dm` v0.9.x
`sidm` v0.10.x
## Getting Started
Quickest way to get started is with docker. Make sure `icarus_auth` and `songparser` repositories
Quickest way to get started is with docker. Make sure `soaricarus_auth` and `songparser` repositories
are located in the root of the parent directory. Check the respective repositories to ensure they
are setup correctly before configuring `Icarus`.
are setup correctly before configuring `soaricarus_api`.
Copy the `.env.docker.sample` file to `.env`. Ensure that the `ROOT_DIRECTORY` variable is populated
and exists on the docker image's filesystem. The credentials for the database doesn't need to be
+71 -36
View File
@@ -3,42 +3,40 @@ version: '3.8' # Use a recent version
services:
# --- Web API ---
api:
build: # Tells docker-compose to build the Dockerfile in the current directory
build:
context: .
ssh: ["default"] # Uses host's SSH agent
container_name: icarus # Optional: Give the container a specific name
ssh: ["default"]
container_name: soaricarus
ports:
# Map host port 8000 to container port 3000 (adjust as needed)
- "8000:8000"
env_file:
- .env
volumes:
- shared_credentials:/shared:ro # Mount as read-only
depends_on:
main_db:
condition: service_healthy
networks:
- icarus-network
restart: unless-stopped # Optional: Restart policy
- soaricarus-network
restart: unless-stopped
# --- Web API auth ---
auth_api:
build:
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
context: ../soaricarus_auth # IMPORTANT: Relative path to the local checkout of your web API repo (containing the Dockerfile)
ssh: ["default"]
dockerfile: Dockerfile # Optional: Specify if your Dockerfile has a non-standard name
container_name: auth_api
restart: unless-stopped
ports:
- "8001:8001" # Map host port 8000 to container port 8000 (adjust container port based on your app's EXPOSE in Dockerfile)
# environment:
# Environment variables your API needs, e.g., database connection
# Add other necessary environment variables
- "8001:8001"
env_file:
- ../icarus_auth/.env
- ../soaricarus_auth/.env
depends_on:
auth_db:
condition: service_healthy
networks:
- icarus-network
- soaricarus-network
# Optional: Mount local code for development (live reload)
# volumes:
# - ./path/to/your/web-api-repo:/app
@@ -59,24 +57,60 @@ services:
- auth_api
- auth_db
networks:
- icarus-network
- soaricarus-network
# --- storage service ---
maze:
build:
context: ./garage
dockerfile: Dockerfile
container_name: maze
restart: unless-stopped
ports:
- "3900:3900" # S3 API
- "3901:3901" # RPC for cluster communication
- "3902:3902" # S3 web interface
- "3903:3903" # Admin API
volumes:
- ./garage.toml:/etc/garage.toml:ro
- ./garage/entrypoint.sh:/entrypoint.sh:ro
- shared_credentials:/shared
- object_data:/var/lib/garage
# - ./scripts:/scripts:ro # ← ADD THIS - mount the scripts directory
env_file:
- .env
environment:
- AWS_ACCESS_KEY_ID=${AWS_ACCESS_KEY_ID}
- AWS_SECRET_ACCESS_KEY=${AWS_SECRET_ACCESS_KEY}
- GARAGE_RPC_SECRET=${GARAGE_RPC_SECRET}
- BUCKET_NAME=${S3_BUCKET_NAME}
# entrypoint: ["/entrypoint.sh"]
# command: []
healthcheck:
test: ["CMD-SHELL", "curl -f http://localhost:3901/v0/status || exit 1"]
# test: ["CMD-SHELL", "echo 'What is to be done?'"]
# test: ["CMD-SHELL", "nc -z localhost 3900 || exit 1"]
# test: ["CMD-SHELL", "/garage status | grep -q 'Health: ok' || exit 1"]
interval: 10s
timeout: 5s
retries: 5
start_period: 30s
networks:
- soaricarus-network
# PostgreSQL Database Service
# --- icarus web api db ---
main_db:
image: postgres:18.3-alpine # Use an official Postgres image (Alpine variant is smaller)
container_name: icarus_db # Optional: Give the container a specific name
image: postgres:18.4-alpine
container_name: soaricarus_db
environment:
# 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:-soaricarus}
POSTGRES_PASSWORD: ${POSTGRES_MAIN_PASSWORD:-password}
POSTGRES_DB: ${POSTGRES_MAIN_DB:-icarus_db}
POSTGRES_DB: ${POSTGRES_MAIN_DB:-soaricarus_db}
volumes:
# Persist database data using a named volume
- postgres_data:/var/lib/postgresql/data
- postgres_data:/var/lib/postgresql
ports:
# Optional: Expose port 5432 ONLY if you need to connect directly from your host machine (e.g., for debugging)
- "5432:5432"
healthcheck:
# Checks if Postgres is ready to accept connections
@@ -85,24 +119,23 @@ services:
timeout: 5s
retries: 5
start_period: 10s
restart: always # Optional: Restart policy
restart: always
networks:
- icarus-network
- soaricarus-network
# --- icarus web auth api db ---
# --- soaricarus web auth api db ---
auth_db:
image: postgres:18.3-alpine # Use an official Postgres image (Alpine variant is smaller)
container_name: icarus_auth_db # Optional: Give the container a specific name
image: postgres:18.4-alpine
container_name: soaricarus_auth_db
environment:
# 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:-soaricarus_op}
POSTGRES_PASSWORD: ${POSTGRES_AUTH_PASSWORD:-password}
POSTGRES_DB: ${POSTGRES_AUTH_DB:-icarus_auth_db}
POSTGRES_DB: ${POSTGRES_AUTH_DB:-soaricarus_auth_db}
volumes:
# Persist database data using a named volume
- postgres_data_auth:/var/lib/postgresql/data
- postgres_data_auth:/var/lib/postgresql
ports:
# Optional: Expose port 5432 ONLY if you need to connect directly from your host machine (e.g., for debugging)
- "5433:5432"
healthcheck:
# Checks if Postgres is ready to accept connections
@@ -111,18 +144,20 @@ services:
timeout: 5s
retries: 5
start_period: 10s
restart: always # Optional: Restart policy
restart: always
networks:
- icarus-network
- soaricarus-network
# Define the named volume for data persistence
volumes:
postgres_data:
driver: local # Use the default local driver
postgres_data_auth:
driver: local # Use the default local driver
object_data:
driver: local # Use the default local driver
shared_credentials: # New shared volume
driver: local
# Define the network (optional, but good practice)
networks:
icarus-network:
soaricarus-network:
driver: bridge
+16
View File
@@ -0,0 +1,16 @@
metadata_dir = "/var/lib/garage/meta"
data_dir = "/var/lib/garage/data"
db_engine = "sqlite"
replication_factor = 1
rpc_bind_addr = "[::]:3901"
rpc_secret = "${GARAGE_RPC_SECRET}"
[s3_api]
s3_region = "maze"
api_bind_addr = "[::]:3900"
root_domain = ".localhost"
[s3_web]
bind_addr = "[::]:3902"
root_domain = ".localhost"
+18
View File
@@ -0,0 +1,18 @@
# Use a base image with a shell (Alpine)
FROM alpine:latest
# Install necessary tools
RUN apk add --no-cache curl
# Copy the Garage binary from the official image
COPY --from=dxflrs/garage:v2.3.0 /garage /usr/local/bin/garage
# Copy the entrypoint script
COPY entrypoint.sh /entrypoint.sh
RUN chmod +x /entrypoint.sh
# Set the entrypoint
ENTRYPOINT ["/entrypoint.sh"]
# Pass through any arguments to Garage
CMD []
+103
View File
@@ -0,0 +1,103 @@
#!/bin/sh
set -e
BUCKET_NAME="${BUCKET_NAME:-soaricarus-storage}"
CREDENTIALS_FILE="/shared/garage-credentials.env"
SETUP_DONE="/shared/setup.done"
GARAGE_BIN="/usr/local/bin/garage"
# Function to write credentials
write_credentials() {
local access_key="$1"
local secret_key="$2"
mkdir -p "$(dirname "$CREDENTIALS_FILE")"
cat > "$CREDENTIALS_FILE" << EOF
GARAGE_ACCESS_KEY_ID=$access_key
GARAGE_SECRET_ACCESS_KEY=$secret_key
GARAGE_BUCKET_NAME=$BUCKET_NAME
GARAGE_ENDPOINT=http://localhost:3900
EOF
touch "$SETUP_DONE"
echo "✅ Credentials saved to $CREDENTIALS_FILE"
}
# Check if setup already completed
if [ -f "$SETUP_DONE" ]; then
echo "️ Setup already completed. Starting Garage..."
exec $GARAGE_BIN "$@"
fi
echo "🔧 First-time setup - initializing Garage..."
# Start Garage in background for setup (just the binary, no daemon subcommand)
echo "⏳ Starting Garage in background..."
$GARAGE_BIN "$@" &
GARAGE_PID=$!
# Wait for Garage to be ready
echo "⏳ Waiting for Garage API..."
until curl -s -f "http://localhost:3901/v0/status" > /dev/null 2>&1; do
echo " Not ready yet, sleeping 2s..."
sleep 2
done
echo "✅ Garage API is responding!"
# Apply cluster layout
if ! $GARAGE_BIN layout show 2>/dev/null | grep -q "Current cluster layout"; then
echo "📦 Applying cluster layout..."
NODE_ID=$($GARAGE_BIN node id | head -n1)
$GARAGE_BIN layout assign --version 1 "$NODE_ID"
$GARAGE_BIN layout apply --version 1
echo " ✅ Layout applied"
sleep 2
else
echo "️ Layout already applied"
fi
# Create bucket
if ! $GARAGE_BIN bucket info "$BUCKET_NAME" 2>/dev/null; then
echo "📦 Creating bucket: $BUCKET_NAME"
$GARAGE_BIN bucket create "$BUCKET_NAME"
else
echo "️ Bucket $BUCKET_NAME already exists"
fi
# Handle key
if [ -n "$AWS_ACCESS_KEY_ID" ] && [ -n "$AWS_SECRET_ACCESS_KEY" ]; then
echo "🔑 Using pre-defined credentials from .env"
if ! $GARAGE_BIN key info "$AWS_ACCESS_KEY_ID" 2>/dev/null; then
$GARAGE_BIN key import "$AWS_ACCESS_KEY_ID" "$AWS_SECRET_ACCESS_KEY" "app-key"
echo " ✅ Key imported: $AWS_ACCESS_KEY_ID"
else
echo " ️ Key already exists: $AWS_ACCESS_KEY_ID"
fi
ACCESS_KEY="$AWS_ACCESS_KEY_ID"
SECRET_KEY="$AWS_SECRET_ACCESS_KEY"
else
echo "🔑 Generating new key..."
KEY_OUTPUT=$($GARAGE_BIN key create --name "app-key")
echo "$KEY_OUTPUT"
ACCESS_KEY=$(echo "$KEY_OUTPUT" | grep 'Key ID:' | awk '{print $3}')
SECRET_KEY=$(echo "$KEY_OUTPUT" | grep 'Secret key:' | awk '{print $3}')
echo " ✅ Key generated: $ACCESS_KEY"
fi
# Grant permissions
$GARAGE_BIN bucket allow --read --write --owner "$BUCKET_NAME" --key "$ACCESS_KEY"
echo " ✅ Permissions granted"
# Save credentials
write_credentials "$ACCESS_KEY" "$SECRET_KEY"
echo "🎉 Setup complete!"
echo " Bucket: $BUCKET_NAME"
echo " Access Key: $ACCESS_KEY"
# Stop background Garage
echo "⏹️ Stopping background Garage..."
kill "$GARAGE_PID"
wait "$GARAGE_PID" 2>/dev/null || true
# Start Garage in foreground
echo "🚀 Starting Garage in foreground..."
exec $GARAGE_BIN "$@"
+109
View File
@@ -0,0 +1,109 @@
#!/bin/sh
set -e
BUCKET_NAME="${BUCKET_NAME:-soaricarus-storage}"
CREDENTIALS_FILE="/shared/garage-credentials.env"
SETUP_DONE="/shared/setup.done"
# Function to write credentials to shared volume
write_credentials() {
local access_key="$1"
local secret_key="$2"
mkdir -p "$(dirname "$CREDENTIALS_FILE")"
cat > "$CREDENTIALS_FILE" << EOF
GARAGE_ACCESS_KEY_ID=$access_key
GARAGE_SECRET_ACCESS_KEY=$secret_key
GARAGE_BUCKET_NAME=$BUCKET_NAME
GARAGE_ENDPOINT=http://maze:3900
EOF
touch "$SETUP_DONE"
echo "✅ Credentials saved to $CREDENTIALS_FILE"
}
# Check if setup already done
if [ -f "$SETUP_DONE" ]; then
echo "️ Setup already completed. Starting Garage..."
# Source credentials if needed for the main Garage process
# shellcheck source=/dev/null
[ -f "$CREDENTIALS_FILE" ] && . "$CREDENTIALS_FILE"
exec /usr/local/bin/garage "$@"
fi
echo "🔧 Running initial setup..."
# Start Garage in background for setup
echo "⏳ Starting Garage in background..."
/usr/local/bin/garage "$@" &
GARAGE_PID=$!
# Wait for Garage API to be ready
echo "⏳ Waiting for Garage API..."
# until curl -s -f "http://localhost:3900/v0/status" > /dev/null 2>&1; do
# echo " Not ready yet, sleeping 2s..."
# sleep 2
#done
echo "✅ Garage API is responding!"
# Apply layout if not already applied
if ! /usr/local/bin/garage layout show 2>/dev/null | grep -q "Current cluster layout"; then
echo "📦 Applying cluster layout..."
NODE_ID=$(/usr/local/bin/garage node id | head -n1)
/usr/local/bin/garage layout assign --version 1 "$NODE_ID"
/usr/local/bin/garage layout apply --version 1
echo " ✅ Layout applied"
sleep 3
else
echo "️ Layout already applied"
fi
echo "Laid out"
# Create bucket if it doesn't exist
if ! /usr/local/bin/garage bucket info "$BUCKET_NAME" 2>/dev/null; then
echo "📦 Creating bucket: $BUCKET_NAME"
/usr/local/bin/garage bucket create "$BUCKET_NAME"
else
echo "️ Bucket $BUCKET_NAME already exists"
fi
# Create or import key
# We'll use the credentials from .env if provided, otherwise generate new ones
if [ -n "$AWS_ACCESS_KEY_ID" ] && [ -n "$AWS_SECRET_ACCESS_KEY" ]; then
echo "🔑 Using pre-defined AWS credentials from .env"
if ! /usr/local/bin/garage key info "$AWS_ACCESS_KEY_ID" 2>/dev/null; then
# Key doesn't exist, import it
/usr/local/bin/garage key import "$AWS_ACCESS_KEY_ID" "$AWS_SECRET_ACCESS_KEY" "app-key"
echo " ✅ Key imported: $AWS_ACCESS_KEY_ID"
else
echo " ️ Key already exists: $AWS_ACCESS_KEY_ID"
fi
ACCESS_KEY="$AWS_ACCESS_KEY_ID"
SECRET_KEY="$AWS_SECRET_ACCESS_KEY"
else
echo "🔑 Generating new key..."
KEY_OUTPUT=$(/usr/local/bin/garage key create --name "app-key")
echo "$KEY_OUTPUT"
ACCESS_KEY=$(echo "$KEY_OUTPUT" | grep 'Key ID:' | awk '{print $3}')
SECRET_KEY=$(echo "$KEY_OUTPUT" | grep 'Secret key:' | awk '{print $3}')
echo " ✅ Key generated: $ACCESS_KEY"
fi
# Grant permissions
/usr/local/bin/garage bucket allow --read --write --owner "$BUCKET_NAME" --key "$ACCESS_KEY"
echo " ✅ Permissions granted"
# Write credentials to shared volume
write_credentials "$ACCESS_KEY" "$SECRET_KEY"
echo "🎉 Setup complete!"
echo " Bucket: $BUCKET_NAME"
echo " Access Key: $ACCESS_KEY"
# Stop the background Garage process
echo "⏹️ Stopping background Garage process..."
kill "$GARAGE_PID"
wait "$GARAGE_PID" 2>/dev/null || true
echo "🚀 Starting Garage in foreground..."
exec /usr/local/bin/garage "$@"
+36
View File
@@ -0,0 +1,36 @@
#!/bin/sh
set -e
BUCKET_NAME="${BUCKET_NAME:-soaricarus-storage}"
CREDENTIALS_FILE="/shared/garage-credentials.env"
SETUP_DONE="/shared/setup.done"
echo "🔧 Running initial setup..."
# Start Garage in background for setup
echo "⏳ Starting Garage in background..."
/usr/local/bin/garage "$@" &
GARAGE_PID=$!
# Wait for Garage API to be ready
echo "⏳ Waiting for Garage API..."
# until curl -s -f "http://localhost:3900/v0/status" > /dev/null 2>&1; do
# echo " Not ready yet, sleeping 2s..."
# sleep 2
#done
echo "✅ Garage API is responding!"
# Apply layout if not already applied
#if ! /usr/local/bin/garage layout show 2>/dev/null | grep -q "Current cluster layout"; then
# echo "📦 Applying cluster layout..."
# NODE_ID=$(/usr/local/bin/garage node id | head -n1)
# echo $NODE_ID
# /usr/local/bin/garage layout assign --version 1 "$NODE_ID"
# /usr/local/bin/garage layout apply --version 1
# echo " ✅ Layout applied"
# sleep 3
#else
# echo "️ Layout already applied"
# fi
echo "Laid out"
+84
View File
@@ -0,0 +1,84 @@
#!/bin/sh
set -e
BUCKET_NAME="soaricarus-storage"
echo "⏳ Waiting for Garage to be ready..."
# until docker exec maze curl -s -f "http://localhost:3901/v0/status" > /dev/null 2>&1; do
until docker exec maze nc -z "localhost 3900" > /dev/null 2>&1; do
echo " Garage not ready yet, retrying in 2s..."
sleep 2
done
echo "✅ Garage API is responding!"
sleep 3
# Check if layout is already applied
if docker exec maze garage layout show 2>/dev/null | grep -q "Current cluster layout"; then
echo "️ Layout already applied, checking bucket..."
else
echo "📦 Applying cluster layout..."
# Get node ID
MAX_RETRIES=10
RETRY_COUNT=0
NODE_ID=""
while [ $RETRY_COUNT -lt $MAX_RETRIES ]; do
NODE_ID=$(docker exec maze garage node id 2>/dev/null | head -n1)
if [ -n "$NODE_ID" ]; then
break
fi
RETRY_COUNT=$((RETRY_COUNT + 1))
echo " Waiting for node ID (attempt $RETRY_COUNT/$MAX_RETRIES)..."
sleep 2
done
if [ -z "$NODE_ID" ]; then
echo "❌ Failed to get node ID after $MAX_RETRIES attempts"
exit 1
fi
echo " Node ID: $NODE_ID"
docker exec maze garage layout assign --version 1 "$NODE_ID"
docker exec maze garage layout apply --version 1
echo " ✅ Layout applied"
sleep 3
fi
# Check if bucket exists
if docker exec maze garage bucket info "${BUCKET_NAME}" 2>/dev/null; then
echo "️ Bucket '${BUCKET_NAME}' already exists. Skipping setup."
exit 0
fi
echo "📦 Creating bucket and configuring permissions..."
# Create the bucket
docker exec maze garage bucket create "${BUCKET_NAME}"
echo " ✅ Bucket created: ${BUCKET_NAME}"
# Check if key exists
if docker exec maze garage key info "${AWS_ACCESS_KEY_ID}" 2>/dev/null; then
echo " ️ Key already exists: ${AWS_ACCESS_KEY_ID}"
else
docker exec maze garage key create \
--name "app-key" \
"${AWS_ACCESS_KEY_ID}" \
"${AWS_SECRET_ACCESS_KEY}"
echo " ✅ Key created: ${AWS_ACCESS_KEY_ID}"
fi
# Grant permissions
docker exec maze garage bucket allow \
--read \
--write \
--owner \
"${BUCKET_NAME}" \
--key "${AWS_ACCESS_KEY_ID}"
echo " ✅ Permissions granted"
echo "🎉 Setup complete!"
echo " Bucket: ${BUCKET_NAME}"
echo " Access Key: ${AWS_ACCESS_KEY_ID}"
echo " Endpoint: http://maze:3900"
+3 -3
View File
@@ -36,11 +36,11 @@ pub async fn auth<B>(
(StatusCode::UNAUTHORIZED, Json(json_error))
})?;
let secret_key = icarus_envy::environment::get_secret_main_key().await.value;
let secret_key = sienvy::environment::get_secret_main_key().value;
let mut validation = Validation::new(jsonwebtoken::Algorithm::HS256);
validation.set_audience(&["icarus"]); // Must match exactly what's in the token
let _claims = decode::<icarus_models::token::UserClaims>(
validation.set_audience(&["soaricarus"]);
let _claims = decode::<simodels::token::UserClaims>(
&token,
&DecodingKey::from_secret(secret_key.as_ref()),
&validation,
+23 -26
View File
@@ -20,7 +20,7 @@ pub mod response {
#[derive(Debug, Default, serde::Deserialize, serde::Serialize, utoipa::ToSchema)]
pub struct Response {
pub message: String,
pub data: Vec<icarus_models::coverart::CoverArt>,
pub data: Vec<simodels::coverart::CoverArt>,
}
}
@@ -28,7 +28,7 @@ pub mod response {
#[derive(Debug, Default, serde::Deserialize, serde::Serialize, utoipa::ToSchema)]
pub struct Response {
pub message: String,
pub data: Vec<icarus_models::coverart::CoverArt>,
pub data: Vec<simodels::coverart::CoverArt>,
}
}
}
@@ -68,21 +68,21 @@ pub mod endpoint {
let song_id = payload.song_id;
match crate::repo::song::get_song(&pool, &song_id).await {
Ok(song) => {
let directory = icarus_envy::environment::get_root_directory().await.value;
let directory = sienvy::environment::get_root_directory().value;
let file_type =
icarus_meta::detection::coverart::file_type_from_data(&data).unwrap();
simeta::detection::coverart::file_type_from_data(&data).unwrap();
let coverart_type = if file_type.file_type
== icarus_meta::detection::coverart::constants::JPEG_TYPE
== simeta::detection::coverart::constants::JPEG_TYPE
{
icarus_models::types::CoverArtType::JpegExtension
simodels::types::CoverArtType::JpegExtension
} else if file_type.file_type
== icarus_meta::detection::coverart::constants::JPG_TYPE
== simeta::detection::coverart::constants::JPG_TYPE
{
icarus_models::types::CoverArtType::JpgExtension
simodels::types::CoverArtType::JpgExtension
} else if file_type.file_type
== icarus_meta::detection::coverart::constants::PNG_TYPE
== simeta::detection::coverart::constants::PNG_TYPE
{
icarus_models::types::CoverArtType::PngExtension
simodels::types::CoverArtType::PngExtension
} else {
response.message = String::from("Invalid CoverArt type");
return (
@@ -91,13 +91,11 @@ pub mod endpoint {
);
};
let filename =
icarus_models::coverart::generate_filename(coverart_type, true)
.unwrap();
simodels::coverart::generate_filename(coverart_type, true).unwrap();
let mut coverart =
icarus_models::coverart::init::init_coverart_dir_and_filename(
&directory, &filename,
);
let mut coverart = simodels::coverart::init::init_coverart_dir_and_filename(
&directory, &filename,
);
coverart.title = song.album.clone();
coverart.file_type = file_type.file_type;
coverart.data = data;
@@ -200,23 +198,23 @@ pub mod endpoint {
axum::extract::Path(id): axum::extract::Path<uuid::Uuid>,
) -> (axum::http::StatusCode, axum::response::Response) {
match repo::coverart::get_coverart(&pool, &id).await {
Ok(coverart) => match icarus_models::coverart::io::to_data(&coverart) {
Ok(coverart) => match simodels::coverart::io::to_data(&coverart) {
Ok(data) => {
let (file_type, img_type) =
match icarus_meta::detection::coverart::file_type_from_data(&data) {
match simeta::detection::coverart::file_type_from_data(&data) {
Ok(file_type) => {
if file_type.file_type
== icarus_meta::detection::coverart::constants::JPEG_TYPE
== simeta::detection::coverart::constants::JPEG_TYPE
{
(file_type, icarus_models::types::CoverArtType::JpegExtension)
(file_type, simodels::types::CoverArtType::JpegExtension)
} else if file_type.file_type
== icarus_meta::detection::coverart::constants::JPG_TYPE
== simeta::detection::coverart::constants::JPG_TYPE
{
(file_type, icarus_models::types::CoverArtType::JpgExtension)
(file_type, simodels::types::CoverArtType::JpgExtension)
} else if file_type.file_type
== icarus_meta::detection::coverart::constants::PNG_TYPE
== simeta::detection::coverart::constants::PNG_TYPE
{
(file_type, icarus_models::types::CoverArtType::PngExtension)
(file_type, simodels::types::CoverArtType::PngExtension)
} else {
return (
axum::http::StatusCode::INTERNAL_SERVER_ERROR,
@@ -235,8 +233,7 @@ pub mod endpoint {
let bytes = axum::body::Bytes::from(data);
let mut response = bytes.into_response();
let headers = response.headers_mut();
let filename =
icarus_models::coverart::generate_filename(img_type, true).unwrap();
let filename = simodels::coverart::generate_filename(img_type, true).unwrap();
headers.insert(
axum::http::header::CONTENT_TYPE,
file_type.mime.parse().unwrap(),
+22 -29
View File
@@ -102,9 +102,9 @@ pub mod response {
mod helper {
pub fn is_coverart_file_type_valid(file_type: &String) -> bool {
let valid_file_types = vec![
String::from(icarus_meta::detection::coverart::constants::JPEG_TYPE),
String::from(icarus_meta::detection::coverart::constants::JPG_TYPE),
String::from(icarus_meta::detection::coverart::constants::PNG_TYPE),
String::from(simeta::detection::coverart::constants::JPEG_TYPE),
String::from(simeta::detection::coverart::constants::JPG_TYPE),
String::from(simeta::detection::coverart::constants::PNG_TYPE),
];
for valid_file_type in valid_file_types {
@@ -150,18 +150,17 @@ pub mod endpoint {
let content_type = field.content_type().unwrap().to_string();
let data = field.bytes().await.unwrap();
let raw_data = data.to_vec();
let file_type =
match icarus_meta::detection::coverart::file_type_from_data(&raw_data) {
Ok(file_type) => file_type,
Err(err) => {
eprintln!("Error: {err:?}");
response.message = err.to_string();
return (
axum::http::StatusCode::INTERNAL_SERVER_ERROR,
axum::Json(response),
);
}
};
let file_type = match simeta::detection::coverart::file_type_from_data(&raw_data) {
Ok(file_type) => file_type,
Err(err) => {
eprintln!("Error: {err:?}");
response.message = err.to_string();
return (
axum::http::StatusCode::INTERNAL_SERVER_ERROR,
axum::Json(response),
);
}
};
if !super::helper::is_coverart_file_type_valid(&file_type.file_type) {
response.message = format!("CoverArt file type not supported: {file_type:?}");
@@ -318,8 +317,7 @@ pub mod endpoint {
) -> (axum::http::StatusCode, axum::response::Response) {
match repo::coverart::get_coverart_queue_data_with_id(&pool, &id).await {
Ok(data) => {
let file_type =
icarus_meta::detection::coverart::file_type_from_data(&data).unwrap();
let file_type = simeta::detection::coverart::file_type_from_data(&data).unwrap();
let bytes = axum::body::Bytes::from(data);
let mut response = bytes.into_response();
let headers = response.headers_mut();
@@ -329,25 +327,20 @@ pub mod endpoint {
);
let coverart_type = if file_type.file_type
== icarus_meta::detection::coverart::constants::JPEG_TYPE
== simeta::detection::coverart::constants::JPEG_TYPE
{
icarus_models::types::CoverArtType::JpegExtension
} else if file_type.file_type
== icarus_meta::detection::coverart::constants::JPG_TYPE
{
icarus_models::types::CoverArtType::JpgExtension
} else if file_type.file_type
== icarus_meta::detection::coverart::constants::PNG_TYPE
{
icarus_models::types::CoverArtType::PngExtension
simodels::types::CoverArtType::JpegExtension
} else if file_type.file_type == simeta::detection::coverart::constants::JPG_TYPE {
simodels::types::CoverArtType::JpgExtension
} else if file_type.file_type == simeta::detection::coverart::constants::PNG_TYPE {
simodels::types::CoverArtType::PngExtension
} else {
return (
axum::http::StatusCode::INTERNAL_SERVER_ERROR,
axum::response::Response::default(),
);
};
let filename =
icarus_models::coverart::generate_filename(coverart_type, true).unwrap();
let filename = simodels::coverart::generate_filename(coverart_type, true).unwrap();
headers.insert(
axum::http::header::CONTENT_DISPOSITION,
format!("attachment; filename=\"{filename}\"")
+2 -2
View File
@@ -97,9 +97,9 @@ pub mod response {
}
pub async fn is_song_valid(data: &[u8]) -> Result<bool, std::io::Error> {
match icarus_meta::detection::song::file_type_from_data(data) {
match simeta::detection::song::file_type_from_data(data) {
Ok(file_type) => {
if file_type.file_type == icarus_meta::detection::song::constants::FLAC_TYPE {
if file_type.file_type == simeta::detection::song::constants::FLAC_TYPE {
Ok(true)
} else {
Ok(false)
+11 -13
View File
@@ -36,8 +36,8 @@ pub mod request {
|| !self.song_queue_id.is_nil()
}
pub fn to_song(&self) -> icarus_models::song::Song {
icarus_models::song::Song {
pub fn to_song(&self) -> simodels::song::Song {
simodels::song::Song {
id: uuid::Uuid::nil(),
title: self.title.clone(),
artist: self.artist.clone(),
@@ -71,7 +71,7 @@ pub mod response {
#[derive(Debug, Default, serde::Deserialize, serde::Serialize, utoipa::ToSchema)]
pub struct Response {
pub message: String,
pub data: Vec<icarus_models::song::Song>,
pub data: Vec<simodels::song::Song>,
}
}
@@ -79,15 +79,15 @@ pub mod response {
#[derive(Debug, Default, serde::Deserialize, serde::Serialize, utoipa::ToSchema)]
pub struct Response {
pub message: String,
pub data: Vec<icarus_models::song::Song>,
pub data: Vec<simodels::song::Song>,
}
}
pub mod delete_song {
#[derive(Debug, Default, serde::Deserialize, serde::Serialize, utoipa::ToSchema)]
pub struct SongAndCoverArt {
pub song: icarus_models::song::Song,
pub coverart: icarus_models::coverart::CoverArt,
pub song: simodels::song::Song,
pub coverart: simodels::coverart::CoverArt,
}
#[derive(Debug, Default, serde::Deserialize, serde::Serialize, utoipa::ToSchema)]
@@ -134,12 +134,10 @@ pub mod endpoint {
if payload.is_valid() {
let mut song = payload.to_song();
song.filename = icarus_models::song::generate_filename(
icarus_models::types::MusicType::FlacExtension,
true,
)
.unwrap();
song.directory = icarus_envy::environment::get_root_directory().await.value;
song.filename =
simodels::song::generate_filename(simodels::types::MusicType::FlacExtension, true)
.unwrap();
song.directory = sienvy::environment::get_root_directory().value;
match repo_queue::song::get_data(&pool, &payload.song_queue_id).await {
Ok(data) => {
@@ -340,7 +338,7 @@ pub mod endpoint {
axum::extract::Path(id): axum::extract::Path<uuid::Uuid>,
) -> (axum::http::StatusCode, axum::response::Response) {
match repo::song::get_song(&pool, &id).await {
Ok(song) => match icarus_models::song::io::to_data(&song) {
Ok(song) => match simodels::song::io::to_data(&song) {
Ok(data) => {
let bytes = axum::body::Bytes::from(data);
let mut response = bytes.into_response();
+15 -18
View File
@@ -28,20 +28,18 @@ mod cors {
axum::http::Method::POST,
axum::http::Method::PUT,
axum::http::Method::DELETE,
]) // Specify allowed methods:cite[2]
])
.allow_headers([
axum::http::header::CONTENT_TYPE,
axum::http::header::AUTHORIZATION,
]) // Specify allowed headers:cite[2]
.allow_credentials(true) // If you need to send cookies or authentication headers:cite[2]
])
.allow_credentials(true)
.max_age(std::time::Duration::from_secs(3600)); // Cache the preflight response for 1 hour:cite[2]
// Dynamically set the allowed origin based on the environment
match std::env::var(icarus_envy::keys::APP_ENV).as_deref() {
match std::env::var(sienvy::keys::APP_ENV).as_deref() {
Ok("production") => {
// In production, allow only your specific, trusted origins
let allowed_origins_env = icarus_envy::environment::get_allowed_origins().await;
match icarus_envy::utility::delimitize(&allowed_origins_env) {
let allowed_origins_env = sienvy::environment::get_allowed_origins();
match sienvy::utility::delimitize(&allowed_origins_env) {
Ok(alwd) => {
let allowed_origins: Vec<axum::http::HeaderValue> = alwd
.into_iter()
@@ -55,15 +53,14 @@ mod cors {
}
}
}
_ => {
// Development (default): Allow localhost origins
cors.allow_origin(vec![
"http://localhost:8000".parse().unwrap(),
"http://127.0.0.1:8000".parse().unwrap(),
"http://localhost:4200".parse().unwrap(),
"http://127.0.0.1:4200".parse().unwrap(),
])
}
_ => cors.allow_origin(vec![
"http://localhost: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://127.0.0.1:4200".parse().unwrap(),
]),
}
}
}
@@ -84,7 +81,7 @@ mod cors {
coverart_queue_responses::wipe_data_from_coverart_queue::Response, coverart_responses::get_coverart::Response,
metadata_queue_responses::queue_metadata::Response, metadata_queue_responses::fetch_metadata::Response)),
tags(
(name = "Icarus API", description = "Web API to manage music")
(name = "soaricarus API", description = "Web API to manage music")
)
)]
struct ApiDoc;
+1 -3
View File
@@ -5,7 +5,7 @@ pub mod connection_settings {
}
pub async fn create_pool() -> Result<sqlx::PgPool, sqlx::Error> {
let database_url = icarus_envy::environment::get_db_url().await.value;
let database_url = sienvy::environment::get_db_url().value;
println!("Database url: {database_url}");
PgPoolOptions::new()
@@ -15,8 +15,6 @@ pub async fn create_pool() -> Result<sqlx::PgPool, sqlx::Error> {
}
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")
.run(pool)
.await
+31 -23
View File
@@ -38,7 +38,7 @@ mod tests {
pub const LIMIT: usize = 6;
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 = sienvy::environment::get_db_url().value;
let tm_options = sqlx::postgres::PgConnectOptions::from_str(&tm_db_url).unwrap();
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> {
let db_url = icarus_envy::environment::get_db_url().await.value;
let db_url = sienvy::environment::get_db_url().value;
let options = sqlx::postgres::PgConnectOptions::from_str(&db_url)?.database(db_name);
sqlx::PgPool::connect_with(options).await
}
@@ -61,7 +61,10 @@ mod tests {
db_name: &str,
) -> Result<(), sqlx::Error> {
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(()),
Err(e) => Err(e),
}
@@ -73,12 +76,14 @@ mod tests {
db_name: &str,
) -> Result<(), sqlx::Error> {
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(())
}
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 = sienvy::environment::get_db_url().value;
let parsed_url = url::Url::parse(&database_url)?;
if parsed_url.scheme() == "postgres" || parsed_url.scheme() == "postgresql" {
@@ -106,13 +111,16 @@ mod tests {
}
mod init {
use std::time::Duration;
pub async fn app(pool: sqlx::PgPool) -> axum::Router {
crate::config::init::routes()
.await
.layer(axum::Extension(pool))
.layer(axum::extract::DefaultBodyLimit::max(1024 * 1024 * 1024))
.layer(tower_http::timeout::TimeoutLayer::new(
std::time::Duration::from_secs(300),
.layer(tower_http::timeout::TimeoutLayer::with_status_code(
axum::http::StatusCode::OK,
Duration::from_secs(300),
))
}
}
@@ -141,25 +149,25 @@ mod tests {
pub fn token_fields() -> (String, String, String) {
(
String::from("What a twist!"),
String::from("icarus_test"),
String::from("icarus"),
String::from("soaricarus_test"),
String::from("soaricarus"),
)
}
pub const TEST_USER_ID: uuid::Uuid = uuid::uuid!("cc938368-615a-4694-b2ca-6e122fa31c52");
pub async fn test_token() -> Result<String, josekit::JoseError> {
let key: String = icarus_envy::environment::get_secret_main_key().await.value;
let key: String = sienvy::environment::get_secret_main_key().value;
let (message, issuer, audience) = token_fields();
let token_resource = icarus_models::token::TokenResource {
let token_resource = simodels::token::TokenResource {
message: message,
issuer: issuer,
audiences: vec![audience],
id: TEST_USER_ID,
};
match icarus_models::token::create_token(&key, &token_resource, time::Duration::hours(1)) {
match simodels::token::create_token(&key, &token_resource, time::Duration::hours(1)) {
Ok((access_token, _some_time)) => Ok(access_token),
Err(err) => Err(err),
}
@@ -281,7 +289,7 @@ mod tests {
.uri(uri)
.header(
axum::http::header::CONTENT_TYPE,
icarus_meta::detection::song::constants::mime::FLAC,
simeta::detection::song::constants::mime::FLAC,
)
.header(
axum::http::header::AUTHORIZATION,
@@ -298,7 +306,7 @@ mod tests {
) -> Result<axum::response::Response, std::convert::Infallible> {
let mut form = MultipartForm::default();
let _ = form.add_file(
icarus_meta::detection::coverart::constants::JPEG_TYPE,
simeta::detection::coverart::constants::JPEG_TYPE,
"tests/I/Coverart-1.jpg",
);
@@ -905,10 +913,10 @@ mod tests {
let temp_file =
tempfile::tempdir().expect("Could not create test directory");
let test_dir = String::from(temp_file.path().to_str().unwrap());
let song = icarus_models::song::Song {
let song = simodels::song::Song {
directory: test_dir,
filename: icarus_models::song::generate_filename(
icarus_models::types::MusicType::FlacExtension,
filename: simodels::song::generate_filename(
simodels::types::MusicType::FlacExtension,
true,
)
.unwrap(),
@@ -2211,20 +2219,20 @@ mod tests {
coverart_directory: &String,
coverart_filename: &String,
) -> Result<(Vec<u8>, Vec<u8>), std::io::Error> {
let song = icarus_models::song::Song {
let song = simodels::song::Song {
directory: song_directory.clone(),
filename: song_filename.clone(),
..Default::default()
};
let coverart = icarus_models::coverart::CoverArt {
let coverart = simodels::coverart::CoverArt {
directory: coverart_directory.clone(),
filename: coverart_filename.clone(),
..Default::default()
};
match icarus_models::song::io::to_data(&song) {
Ok(song_data) => match icarus_models::coverart::io::to_data(&coverart) {
match simodels::song::io::to_data(&song) {
Ok(song_data) => match simodels::coverart::io::to_data(&coverart) {
Ok(coverart_data) => Ok((song_data, coverart_data)),
Err(err) => Err(err),
},
@@ -2240,14 +2248,14 @@ mod tests {
coverart_filename: &String,
coverart_data: Vec<u8>,
) -> Result<(), std::io::Error> {
let song = icarus_models::song::Song {
let song = simodels::song::Song {
directory: song_directory.clone(),
filename: song_filename.clone(),
data: song_data,
..Default::default()
};
let coverart = icarus_models::coverart::CoverArt {
let coverart = simodels::coverart::CoverArt {
directory: coverart_directory.clone(),
filename: coverart_filename.clone(),
data: coverart_data,
+7 -7
View File
@@ -2,7 +2,7 @@ use sqlx::Row;
pub async fn create(
pool: &sqlx::PgPool,
coverart: &icarus_models::coverart::CoverArt,
coverart: &simodels::coverart::CoverArt,
song_id: &uuid::Uuid,
) -> Result<uuid::Uuid, sqlx::Error> {
let result = sqlx::query(
@@ -36,7 +36,7 @@ pub async fn create(
pub async fn get_coverart(
pool: &sqlx::PgPool,
id: &uuid::Uuid,
) -> Result<icarus_models::coverart::CoverArt, sqlx::Error> {
) -> Result<simodels::coverart::CoverArt, sqlx::Error> {
let result = sqlx::query(
r#"
SELECT id, title, directory, filename, file_type, song_id FROM "coverart" WHERE id = $1;
@@ -50,7 +50,7 @@ pub async fn get_coverart(
});
match result {
Ok(row) => Ok(icarus_models::coverart::CoverArt {
Ok(row) => Ok(simodels::coverart::CoverArt {
id: row
.try_get("id")
.map_err(|_e| sqlx::Error::RowNotFound)
@@ -84,7 +84,7 @@ pub async fn get_coverart(
pub async fn get_coverart_with_song_id(
pool: &sqlx::PgPool,
song_id: &uuid::Uuid,
) -> Result<icarus_models::coverart::CoverArt, sqlx::Error> {
) -> Result<simodels::coverart::CoverArt, sqlx::Error> {
let result = sqlx::query(
r#"
SELECT id, title, directory, filename, file_type, song_id FROM "coverart" WHERE song_id = $1;
@@ -98,7 +98,7 @@ pub async fn get_coverart_with_song_id(
});
match result {
Ok(row) => Ok(icarus_models::coverart::CoverArt {
Ok(row) => Ok(simodels::coverart::CoverArt {
id: row
.try_get("id")
.map_err(|_e| sqlx::Error::RowNotFound)
@@ -132,7 +132,7 @@ pub async fn get_coverart_with_song_id(
pub async fn delete_coverart(
pool: &sqlx::PgPool,
id: &uuid::Uuid,
) -> Result<icarus_models::coverart::CoverArt, sqlx::Error> {
) -> Result<simodels::coverart::CoverArt, sqlx::Error> {
let result = sqlx::query(
r#"
DELETE FROM "coverart"
@@ -148,7 +148,7 @@ pub async fn delete_coverart(
});
match result {
Ok(row) => Ok(icarus_models::coverart::CoverArt {
Ok(row) => Ok(simodels::coverart::CoverArt {
id: row
.try_get("id")
.map_err(|_e| sqlx::Error::RowNotFound)
+9 -11
View File
@@ -2,7 +2,7 @@ use sqlx::Row;
pub async fn insert(
pool: &sqlx::PgPool,
song: &icarus_models::song::Song,
song: &simodels::song::Song,
) -> Result<(time::OffsetDateTime, uuid::Uuid), sqlx::Error> {
let result = sqlx::query(
r#"
@@ -52,7 +52,7 @@ pub async fn insert(
pub async fn get_song(
pool: &sqlx::PgPool,
id: &uuid::Uuid,
) -> Result<icarus_models::song::Song, sqlx::Error> {
) -> Result<simodels::song::Song, sqlx::Error> {
let result = sqlx::query(
r#"
SELECT * FROM "song" WHERE id = $1
@@ -72,7 +72,7 @@ pub async fn get_song(
.map_err(|_e| sqlx::Error::RowNotFound)
.unwrap();
Ok(icarus_models::song::Song {
Ok(simodels::song::Song {
id: row
.try_get("id")
.map_err(|_e| sqlx::Error::RowNotFound)
@@ -145,9 +145,7 @@ pub async fn get_song(
}
}
pub async fn get_all_songs(
pool: &sqlx::PgPool,
) -> Result<Vec<icarus_models::song::Song>, sqlx::Error> {
pub async fn get_all_songs(pool: &sqlx::PgPool) -> Result<Vec<simodels::song::Song>, sqlx::Error> {
let result = sqlx::query(
r#"
SELECT * FROM "song";
@@ -161,7 +159,7 @@ pub async fn get_all_songs(
match result {
Ok(rows) => {
let mut songs: Vec<icarus_models::song::Song> = Vec::new();
let mut songs: Vec<simodels::song::Song> = Vec::new();
for row in rows {
let date_created_time: time::OffsetDateTime = row
@@ -169,7 +167,7 @@ pub async fn get_all_songs(
.map_err(|_e| sqlx::Error::RowNotFound)
.unwrap();
let song = icarus_models::song::Song {
let song = simodels::song::Song {
id: row
.try_get("id")
.map_err(|_e| sqlx::Error::RowNotFound)
@@ -250,9 +248,9 @@ pub async fn get_all_songs(
pub async fn delete_song(
pool: &sqlx::PgPool,
id: &uuid::Uuid,
) -> Result<icarus_models::song::Song, sqlx::Error> {
) -> Result<simodels::song::Song, sqlx::Error> {
let result = sqlx::query(
// icarus_models::song::Song,
// simodels::song::Song,
r#"
DELETE FROM "song"
WHERE id = $1
@@ -273,7 +271,7 @@ pub async fn delete_song(
.map_err(|_e| sqlx::Error::RowNotFound)
.unwrap();
Ok(icarus_models::song::Song {
Ok(simodels::song::Song {
id: row
.try_get("id")
.map_err(|_e| sqlx::Error::RowNotFound)