From 7f003d25d93c3c2177f0cc3a6b85ef772869eb79 Mon Sep 17 00:00:00 2001 From: phoenix Date: Fri, 12 Jun 2026 21:25:36 -0400 Subject: [PATCH 1/8] Cleaning up comments --- src/main.rs | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/src/main.rs b/src/main.rs index 94ff489..47a4039 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,19 +1,5 @@ - #[tokio::main] async fn main() { // initialize tracing tracing_subscriber::fmt::init(); - - /* - match tokio::net::TcpListener::bind(config::host::get_full()).await { - Ok(listener) => { - // build our application with routes - let app = config::init::app().await; - axum::serve(listener, app).await.unwrap(); - } - Err(err) => { - eprintln!("Error: {err:?}") - } - } - */ } -- 2.47.3 From 71688e6d59d5ad5077790bd09c991c2a725765ad Mon Sep 17 00:00:00 2001 From: phoenix Date: Fri, 12 Jun 2026 21:26:03 -0400 Subject: [PATCH 2/8] Adding docker files --- .dockerignore | 0 Dockerfile | 0 docker-compose.yml | 0 3 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 .dockerignore create mode 100644 Dockerfile create mode 100644 docker-compose.yml diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..e69de29 diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..e69de29 diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..e69de29 -- 2.47.3 From d9f9e85cc90213eb69b5eb621332862ae1fa3abd Mon Sep 17 00:00:00 2001 From: phoenix Date: Fri, 12 Jun 2026 21:38:22 -0400 Subject: [PATCH 3/8] Fixed workflow --- .gitea/workflows/workflow.yml | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/.gitea/workflows/workflow.yml b/.gitea/workflows/workflow.yml index 2150d5f..f8883a7 100644 --- a/.gitea/workflows/workflow.yml +++ b/.gitea/workflows/workflow.yml @@ -19,11 +19,12 @@ jobs: - uses: actions-rust-lang/setup-rust-toolchain@v1 with: toolchain: 1.95 + - uses: Swatinem/rust-cache@v2 - run: | mkdir -p ~/.ssh echo "${{ secrets.MYREPO_TOKEN }}" > ~/.ssh/textsender-models_deploy_key chmod 600 ~/.ssh/textsender-models_deploy_key - ssh-keyscan ${{ secret.MYHOST }} >> ~/.ssh/known_hosts + ssh-keyscan ${{ secrets.MY_HOST }} >> ~/.ssh/known_hosts eval $(ssh-agent -s) ssh-add -v ~/.ssh/textsender-models_deploy_key @@ -73,7 +74,7 @@ jobs: # 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_KEY: ${{ secrets.TOKEN_SECRET_KEY }} + SECRET_KEY: ${{ secrets.SECRET_KEY }} # Make SSH agent available if tests fetch private dependencies SSH_AUTH_SOCK: ${{ env.SSH_AUTH_SOCK }} ENABLE_REGISTRATION: 'TRUE' @@ -81,7 +82,7 @@ jobs: mkdir -p ~/.ssh echo "${{ secrets.MYREPO_TOKEN }}" > ~/.ssh/textsender-models_deploy_key chmod 600 ~/.ssh/textsender-models_deploy_key - ssh-keyscan ${{ secret.MYHOST }} >> ~/.ssh/known_hosts + ssh-keyscan ${{ secrets.MY_HOST }} >> ~/.ssh/known_hosts eval $(ssh-agent -s) ssh-add -v ~/.ssh/textsender-models_deploy_key @@ -97,11 +98,12 @@ jobs: with: toolchain: 1.95 - run: rustup component add rustfmt + - uses: Swatinem/rust-cache@v2 - run: | mkdir -p ~/.ssh echo "${{ secrets.MYREPO_TOKEN }}" > ~/.ssh/textsender-models_deploy_key chmod 600 ~/.ssh/textsender-models_deploy_key - ssh-keyscan ${{ secret.MYHOST }} >> ~/.ssh/known_hosts + ssh-keyscan ${{ secrets.MY_HOST }} >> ~/.ssh/known_hosts eval $(ssh-agent -s) ssh-add -v ~/.ssh/textsender-models_deploy_key @@ -116,11 +118,12 @@ jobs: with: toolchain: 1.95 - run: rustup component add clippy + - uses: Swatinem/rust-cache@v2 - run: | mkdir -p ~/.ssh echo "${{ secrets.MYREPO_TOKEN }}" > ~/.ssh/textsender-models_deploy_key chmod 600 ~/.ssh/textsender-models_deploy_key - ssh-keyscan ${{ secret.MYHOST }} >> ~/.ssh/known_hosts + ssh-keyscan ${{ secrets.MY_HOST }} >> ~/.ssh/known_hosts eval $(ssh-agent -s) ssh-add -v ~/.ssh/textsender-models_deploy_key @@ -134,13 +137,13 @@ jobs: - uses: actions-rust-lang/setup-rust-toolchain@v1 with: toolchain: 1.95 + - uses: Swatinem/rust-cache@v2 - run: | mkdir -p ~/.ssh echo "${{ secrets.MYREPO_TOKEN }}" > ~/.ssh/textsender-models_deploy_key chmod 600 ~/.ssh/textsender-models_deploy_key - ssh-keyscan ${{ secret.MYHOST }} >> ~/.ssh/known_hosts + ssh-keyscan ${{ secrets.MY_HOST }} >> ~/.ssh/known_hosts eval $(ssh-agent -s) ssh-add -v ~/.ssh/textsender-models_deploy_key cargo build --release - -- 2.47.3 From c5e3cee62a25ddecbb23dc34602934cb05132af3 Mon Sep 17 00:00:00 2001 From: phoenix Date: Fri, 12 Jun 2026 21:41:22 -0400 Subject: [PATCH 4/8] bump: textsender_models --- Cargo.lock | 73 +++++++++++++----------------------------------------- Cargo.toml | 2 +- 2 files changed, 18 insertions(+), 57 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index c92f42c..ca377b8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -204,17 +204,6 @@ version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801" -[[package]] -name = "chacha20" -version = "0.10.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6f8d983286843e49675a4b7a2d174efe136dc93a18d69130dd18198a6c167601" -dependencies = [ - "cfg-if", - "cpufeatures 0.3.0", - "rand_core 0.10.1", -] - [[package]] name = "common-multipart-rfc7578" version = "0.7.0" @@ -227,7 +216,7 @@ dependencies = [ "http", "mime", "mime_guess", - "rand 0.8.6", + "rand", "thiserror 1.0.69", ] @@ -303,15 +292,6 @@ dependencies = [ "libc", ] -[[package]] -name = "cpufeatures" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8b2a41393f66f16b0823bb79094d54ac5fbd34ab292ddafb9a0456ac9f87d201" -dependencies = [ - "libc", -] - [[package]] name = "crc" version = "3.4.0" @@ -358,7 +338,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0dc92fb57ca44df6db8059111ab3af99a63d5d0f8375d9972e319a379c6bab76" dependencies = [ "generic-array", - "rand_core 0.6.4", + "rand_core", "subtle", "zeroize", ] @@ -380,7 +360,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "97fb8b7c4503de7d6ae7b42ab72a5a59857b4c937ec27a3d4539dba95b5ab2be" dependencies = [ "cfg-if", - "cpufeatures 0.2.17", + "cpufeatures", "curve25519-dalek-derive", "digest", "fiat-crypto", @@ -523,7 +503,7 @@ dependencies = [ "hkdf", "pem-rfc7468", "pkcs8", - "rand_core 0.6.4", + "rand_core", "sec1", "subtle", "zeroize", @@ -588,7 +568,7 @@ version = "0.13.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c0b50bfb653653f9ca9095b427bed08ab8d75a137839d9ad64eb11810d5b6393" dependencies = [ - "rand_core 0.6.4", + "rand_core", "subtle", ] @@ -786,7 +766,6 @@ dependencies = [ "cfg-if", "libc", "r-efi", - "rand_core 0.10.1", "wasip2", "wasip3", ] @@ -798,7 +777,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f0f9ef7462f7c099f518d754361858f86d8a07af53ba9af0fe635bbccb151a63" dependencies = [ "ff", - "rand_core 0.6.4", + "rand_core", "subtle", ] @@ -1127,7 +1106,7 @@ dependencies = [ "p256", "p384", "pem", - "rand 0.8.6", + "rand", "rsa", "serde", "serde_json", @@ -1351,7 +1330,7 @@ dependencies = [ "num-integer", "num-iter", "num-traits", - "rand 0.8.6", + "rand", "smallvec", "zeroize", ] @@ -1633,18 +1612,7 @@ checksum = "5ca0ecfa931c29007047d1bc58e623ab12e5590e8c7cc53200d5202b69266d8a" dependencies = [ "libc", "rand_chacha", - "rand_core 0.6.4", -] - -[[package]] -name = "rand" -version = "0.10.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d2e8e8bcc7961af1fdac401278c6a831614941f6164ee3bf4ce61b7edb162207" -dependencies = [ - "chacha20", - "getrandom 0.4.2", - "rand_core 0.10.1", + "rand_core", ] [[package]] @@ -1654,7 +1622,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" dependencies = [ "ppv-lite86", - "rand_core 0.6.4", + "rand_core", ] [[package]] @@ -1666,12 +1634,6 @@ dependencies = [ "getrandom 0.2.17", ] -[[package]] -name = "rand_core" -version = "0.10.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "63b8176103e19a2643978565ca18b50549f6101881c443590420e4dc998a3c69" - [[package]] name = "redox_syscall" version = "0.5.18" @@ -1742,7 +1704,7 @@ dependencies = [ "num-traits", "pkcs1", "pkcs8", - "rand_core 0.6.4", + "rand_core", "signature", "spki", "subtle", @@ -1958,7 +1920,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e3bf829a2d51ab4a5ddf1352d8470c140cadc8301b2ae1789db023f01cedd6ba" dependencies = [ "cfg-if", - "cpufeatures 0.2.17", + "cpufeatures", "digest", ] @@ -1969,7 +1931,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a7507d819769d01a365ab707794a4084392c824f54a7a6a7862f8c3d0892b283" dependencies = [ "cfg-if", - "cpufeatures 0.2.17", + "cpufeatures", "digest", ] @@ -2005,7 +1967,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "77549399552de45a898a580c1b41d445bf730df867cc44e6c0233bbc4b8329de" dependencies = [ "digest", - "rand_core 0.6.4", + "rand_core", ] [[package]] @@ -2187,7 +2149,7 @@ dependencies = [ "memchr", "once_cell", "percent-encoding", - "rand 0.8.6", + "rand", "rsa", "serde", "sha1", @@ -2227,7 +2189,7 @@ dependencies = [ "md-5", "memchr", "once_cell", - "rand 0.8.6", + "rand", "serde", "serde_json", "sha2", @@ -2364,12 +2326,11 @@ dependencies = [ [[package]] name = "textsender_models" version = "0.3.0" -source = "git+ssh://git@git.kundeng.us/phoenix/textsender-models.git?tag=v0.3.0-v0.3.0-migrate-2be0337da0-111#2be0337da008f1018692234e8043220f6812377d" +source = "git+ssh://git@git.kundeng.us/phoenix/textsender-models.git?tag=v0.3.0#d504108745b7b97a02eac24e16763cdb5e731f2b" dependencies = [ "const_format", "dotenvy", "josekit", - "rand 0.10.1", "serde", "serde_json", "time", diff --git a/Cargo.toml b/Cargo.toml index da1718f..4f27564 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -25,7 +25,7 @@ jsonwebtoken = { version = "10.3.0", features = ["rust_crypto"] } josekit = { version = "0.10.3" } utoipa = { version = "5.5.0", features = ["axum_extras"] } utoipa-swagger-ui = { version = "9.0.2", features = ["axum"] } -textsender_models = { git = "ssh://git@git.kundeng.us/phoenix/textsender-models.git", tag = "v0.3.0-v0.3.0-migrate-2be0337da0-111" } +textsender_models = { git = "ssh://git@git.kundeng.us/phoenix/textsender-models.git", tag = "v0.3.0" } [dev-dependencies] common-multipart-rfc7578 = { version = "0.7.0" } -- 2.47.3 From d6aae30c6fcab3fbcebdae900f7beeb3e773d8d3 Mon Sep 17 00:00:00 2001 From: phoenix Date: Fri, 12 Jun 2026 21:53:50 -0400 Subject: [PATCH 5/8] Saving docker files --- .dockerignore | 1 + Dockerfile | 70 +++++++++++++++++++++++++ docker-compose.yml | 128 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 199 insertions(+) diff --git a/.dockerignore b/.dockerignore index e69de29..81a38be 100644 --- a/.dockerignore +++ b/.dockerignore @@ -0,0 +1 @@ +.env* diff --git a/Dockerfile b/Dockerfile index e69de29..f611bc8 100644 --- a/Dockerfile +++ b/Dockerfile @@ -0,0 +1,70 @@ +# Stage 1: Build the application +FROM rust:1.95 as builder + +# Set the working directory inside the container +WORKDIR /usr/src/app + +# Install build dependencies if needed (e.g., git for cloning) +RUN apt-get update && apt-get install -y --no-install-recommends \ + pkg-config libssl3 \ + ca-certificates \ + openssh-client git \ + && rm -rf /var/lib/apt/lists/* + +# Create .ssh/ directory for internal dependencies +RUN mkdir -p -m 0700 ~/.ssh && \ + echo "Host git.kundeng.us" >> ~/.ssh/config && \ + 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/textsender_api* # Clean up dummy build artifacts (replace textsender_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 + +# << --- 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 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/* + +# Set the working directory +WORKDIR /usr/local/bin + +# Copy the compiled binary from the builder stage +# Replace 'textsender_api' with the actual name of your binary (usually the crate name) +COPY --from=builder /usr/src/app/target/release/textsender_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 9081 + +# Set the command to run your application +# Ensure this matches the binary name copied above +CMD ["./textsender_api"] diff --git a/docker-compose.yml b/docker-compose.yml index e69de29..74ea8b9 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -0,0 +1,128 @@ +version: '3.8' # Use a recent version + +services: + # --- Web API --- + api: + build: # Tells docker-compose to build the Dockerfile in the current directory + context: . + ssh: ["default"] # Uses host's SSH agent + container_name: textsender_api # Optional: Give the container a specific name + ports: + # Map host port 8000 to container port 3000 (adjust as needed) + - "9081:9081" + env_file: + - .env + depends_on: + main_db: + condition: service_healthy + networks: + - textsender_api-network + restart: unless-stopped # Optional: Restart policy + + # --- Web API auth --- + auth_api: + build: + context: ../textsender_auth # IMPORTANT: Relative path to the local checkout of your web API repo (containing the Dockerfile) + ssh: ["default"] # Uses host's SSH agent + dockerfile: Dockerfile # Optional: Specify if your Dockerfile has a non-standard name + container_name: auth_api + restart: unless-stopped + ports: + - "9080:9080" + # environment: + # Environment variables your API needs, e.g., database connection + # Add other necessary environment variables + env_file: + - ../textsender_auth/.env + depends_on: + auth_db: + condition: service_healthy + networks: + - textsender_api-network + # Optional: Mount local code for development (live reload) + # volumes: + # - ./path/to/your/web-api-repo:/app + + # --- songparser service --- + catapult: + build: + context: ../catapult + ssh: ["default"] + dockerfile: Dockerfile + container_name: catapult + restart: unless-stopped + env_file: + - ../catapult/.env + depends_on: + - api + - main_db + - auth_api + - auth_db + networks: + - textsender_api-network + + + # PostgreSQL Database Service + # --- textsender_api web api db --- + main_db: + image: postgres:18.3-alpine # Use an official Postgres image (Alpine variant is smaller) + container_name: textsender_api_db # Optional: Give the container a specific name + environment: + # These MUST match the user, password, and database name in the DATABASE_URL above + POSTGRES_USER: ${POSTGRES_MAIN_USER:-textsender_api} + POSTGRES_PASSWORD: ${POSTGRES_MAIN_PASSWORD:-password} + POSTGRES_DB: ${POSTGRES_MAIN_DB:-textsender_api_db} + volumes: + # Persist database data using a named volume + - 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 + test: ["CMD-SHELL", "pg_isready -U $$POSTGRES_USER -d $$POSTGRES_DB"] + interval: 10s + timeout: 5s + retries: 5 + start_period: 10s + restart: always # Optional: Restart policy + networks: + - textsender_api-network + + # --- textsender_api web auth api db --- + auth_db: + image: postgres:18.4-alpine # Use an official Postgres image (Alpine variant is smaller) + container_name: textsender_api_auth_db # Optional: Give the container a specific name + environment: + # These MUST match the user, password, and database name in the DATABASE_URL above + POSTGRES_USER: ${POSTGRES_AUTH_USER:-textsender_api_op} + POSTGRES_PASSWORD: ${POSTGRES_AUTH_PASSWORD:-password} + POSTGRES_DB: ${POSTGRES_AUTH_DB:-textsender_api_auth_db} + volumes: + # Persist database data using a named volume + - 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 + test: ["CMD-SHELL", "pg_isready -U $$POSTGRES_USER -d $$POSTGRES_DB"] + interval: 10s + timeout: 5s + retries: 5 + start_period: 10s + restart: always # Optional: Restart policy + networks: + - textsender_api-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 + +# Define the network (optional, but good practice) +networks: + textsender_api-network: + driver: bridge -- 2.47.3 From ede943bf29e8fef89dcfefbfecc5b006890b849a Mon Sep 17 00:00:00 2001 From: phoenix Date: Fri, 12 Jun 2026 22:03:14 -0400 Subject: [PATCH 6/8] Don't need this --- .dockerignore | 1 - 1 file changed, 1 deletion(-) delete mode 100644 .dockerignore diff --git a/.dockerignore b/.dockerignore deleted file mode 100644 index 81a38be..0000000 --- a/.dockerignore +++ /dev/null @@ -1 +0,0 @@ -.env* -- 2.47.3 From bc3643a44f5ef57732f0959f88a55f3de980d516 Mon Sep 17 00:00:00 2001 From: phoenix Date: Fri, 12 Jun 2026 22:03:32 -0400 Subject: [PATCH 7/8] Fixing Docker --- docker-compose.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 74ea8b9..0f0221a 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -22,7 +22,8 @@ services: # --- Web API auth --- auth_api: build: - context: ../textsender_auth # IMPORTANT: Relative path to the local checkout of your web API repo (containing the Dockerfile) + # Might want to change the naming convention at some point for the repo names. textsender-models, textsender-auth, textesender-api, etc + context: ../textsender-auth # IMPORTANT: Relative path to the local checkout of your web API repo (containing the Dockerfile) ssh: ["default"] # Uses host's SSH agent dockerfile: Dockerfile # Optional: Specify if your Dockerfile has a non-standard name container_name: auth_api @@ -33,7 +34,7 @@ services: # Environment variables your API needs, e.g., database connection # Add other necessary environment variables env_file: - - ../textsender_auth/.env + - ../textsender-auth/.env depends_on: auth_db: condition: service_healthy -- 2.47.3 From 20345cc902e2dd1c4a98d26f9cb1b9a794257649 Mon Sep 17 00:00:00 2001 From: phoenix Date: Fri, 12 Jun 2026 22:03:43 -0400 Subject: [PATCH 8/8] Renaming app --- Cargo.lock | 2 +- Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index ca377b8..649fe00 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2294,7 +2294,7 @@ dependencies = [ ] [[package]] -name = "textsender" +name = "textsender_api" version = "0.5.0" dependencies = [ "axum", diff --git a/Cargo.toml b/Cargo.toml index 4f27564..4d327e3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "textsender" +name = "textsender_api" version = "0.5.0" edition = "2024" rust-version = "1.95" -- 2.47.3