diff --git a/.gitea/workflows/pr.yml b/.gitea/workflows/pr.yml index 1d3da27..fdb429b 100644 --- a/.gitea/workflows/pr.yml +++ b/.gitea/workflows/pr.yml @@ -17,7 +17,7 @@ jobs: - uses: actions/checkout@v6 - uses: actions-rust-lang/setup-rust-toolchain@v1 with: - toolchain: 1.96.1 + toolchain: 1.97 - uses: Swatinem/rust-cache@v2 - run: | mkdir -p ~/.ssh @@ -37,7 +37,7 @@ jobs: - uses: actions/checkout@v6 - uses: actions-rust-lang/setup-rust-toolchain@v1 with: - toolchain: 1.96.1 + toolchain: 1.97 - run: rustup component add rustfmt - uses: Swatinem/rust-cache@v2 - run: | @@ -57,7 +57,7 @@ jobs: - uses: actions/checkout@v6 - uses: actions-rust-lang/setup-rust-toolchain@v1 with: - toolchain: 1.96.1 + toolchain: 1.97 - run: rustup component add clippy - uses: Swatinem/rust-cache@v2 - run: | diff --git a/.gitea/workflows/tests.yml b/.gitea/workflows/tests.yml index cc80642..9aa1477 100644 --- a/.gitea/workflows/tests.yml +++ b/.gitea/workflows/tests.yml @@ -1,4 +1,4 @@ -name: Rust Build +name: textsender_api Test on: pull_request: @@ -35,7 +35,7 @@ jobs: - uses: actions/checkout@v6 - uses: actions-rust-lang/setup-rust-toolchain@v1 with: - toolchain: 1.96.1 + toolchain: 1.97 # --- Add this step for explicit verification --- - name: Verify Docker Environment run: | @@ -77,7 +77,7 @@ jobs: - uses: actions/checkout@v6 - uses: actions-rust-lang/setup-rust-toolchain@v1 with: - toolchain: 1.96.1 + toolchain: 1.97 - run: rustup component add rustfmt - uses: Swatinem/rust-cache@v2 - run: | diff --git a/.gitea/workflows/workflow.yml b/.gitea/workflows/workflow.yml index 680e84d..13621fc 100644 --- a/.gitea/workflows/workflow.yml +++ b/.gitea/workflows/workflow.yml @@ -1,4 +1,4 @@ -name: Rust Build +name: textsender_api Build on: push: @@ -18,7 +18,7 @@ jobs: - uses: actions/checkout@v6 - uses: actions-rust-lang/setup-rust-toolchain@v1 with: - toolchain: 1.96.1 + toolchain: 1.97 - uses: Swatinem/rust-cache@v2 - run: | mkdir -p ~/.ssh @@ -55,7 +55,7 @@ jobs: - uses: actions/checkout@v6 - uses: actions-rust-lang/setup-rust-toolchain@v1 with: - toolchain: 1.96.1 + toolchain: 1.97 # --- Add this step for explicit verification --- - name: Verify Docker Environment run: | @@ -97,7 +97,7 @@ jobs: - uses: actions/checkout@v6 - uses: actions-rust-lang/setup-rust-toolchain@v1 with: - toolchain: 1.96.1 + toolchain: 1.97 - run: rustup component add rustfmt - uses: Swatinem/rust-cache@v2 - run: | @@ -117,7 +117,7 @@ jobs: - uses: actions/checkout@v6 - uses: actions-rust-lang/setup-rust-toolchain@v1 with: - toolchain: 1.96.1 + toolchain: 1.97 - run: rustup component add clippy - uses: Swatinem/rust-cache@v2 - run: | @@ -137,7 +137,7 @@ jobs: - uses: actions/checkout@v6 - uses: actions-rust-lang/setup-rust-toolchain@v1 with: - toolchain: 1.96.1 + toolchain: 1.97 - uses: Swatinem/rust-cache@v2 - run: | mkdir -p ~/.ssh diff --git a/Cargo.lock b/Cargo.lock index 4165ab3..b0a1aff 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -171,9 +171,9 @@ checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" [[package]] name = "base64-ng" -version = "1.3.5" +version = "1.3.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2b87dbd7e45c4885ad3432a2d125ddb155c5ee87046ab23bad043dfe84fedfa2" +checksum = "78dbdaa3c8250efc13282f483f2ae92733e407c9cf6ffc2fe7918ce1ee420724" [[package]] name = "base64ct" @@ -222,9 +222,9 @@ checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" [[package]] name = "bytes" -version = "1.12.0" +version = "1.12.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ae3f5d315924270530207e2a68396c3cc547f6dca3fbdca317cfb1a51edb593" +checksum = "fc652a48c352aef3ea3aed32080501cf3ef6ed5da78602a020c991775b0aff04" [[package]] name = "cc" @@ -301,6 +301,12 @@ version = "0.9.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c2459377285ad874054d797f3ccebf984978aa39129f6eafde5cdc8315b612f8" +[[package]] +name = "const-oid" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a6ef517f0926dd24a1582492c791b6a4818a4d94e789a334894aa15b0d12f55c" + [[package]] name = "const_format" version = "0.2.36" @@ -489,7 +495,7 @@ version = "0.7.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e7c1832837b905bbfb5101e07cc24c8deddf52f93225eee6ead5f4d63d53ddcb" dependencies = [ - "const-oid", + "const-oid 0.9.6", "pem-rfc7468", "zeroize", ] @@ -521,7 +527,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" dependencies = [ "block-buffer 0.10.4", - "const-oid", + "const-oid 0.9.6", "crypto-common 0.1.6", "subtle", ] @@ -533,6 +539,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f1dd6dbb5841937940781866fa1281a1ff7bd3bf827091440879f9994983d5c2" dependencies = [ "block-buffer 0.12.1", + "const-oid 0.10.2", "crypto-common 0.2.2", "ctutils", ] @@ -1452,9 +1459,9 @@ dependencies = [ [[package]] name = "memchr" -version = "2.8.2" +version = "2.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "88904434abc2901f197fe8cc55f0445e7ded921dba5911dad2e2b39b48e663c4" +checksum = "cf8baf1c55e62ffcace7a9f06f4bd9cd3f0c4beb022d3b367256b91b87513d98" [[package]] name = "mime" @@ -1579,11 +1586,10 @@ dependencies = [ [[package]] name = "num-iter" -version = "0.1.45" +version = "0.1.46" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1429034a0490724d0075ebb2bc9e875d6503c3cf69e235a8941aa757d83ef5bf" +checksum = "c92800bd69a1eac91786bcfe9da64a897eb72911b8dc3095decbd07429e8048b" dependencies = [ - "autocfg", "num-integer", "num-traits", ] @@ -1939,9 +1945,9 @@ dependencies = [ [[package]] name = "regex" -version = "1.12.4" +version = "1.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f1292b7759ae1cb9ec195452d1390a074f0cd8541ab7a5a8c31cd6db45d4a6ba" +checksum = "2a0e75113e14dc5acb068cd0786884f214f1312650a3d36d269f5c4f3cdee8a2" dependencies = [ "aho-corasick", "memchr", @@ -1951,9 +1957,9 @@ dependencies = [ [[package]] name = "regex-automata" -version = "0.4.14" +version = "0.4.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6e1dd4122fc1595e8162618945476892eefca7b88c52820e74af6262213cae8f" +checksum = "1f388202e4b80542a0921078cc23b6333bcf1409c1e3f86404cae4766a6131db" dependencies = [ "aho-corasick", "memchr", @@ -2042,7 +2048,7 @@ version = "0.9.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b8573f03f5883dcaebdfcf4725caa1ecb9c15b2ef50c43a07b816e06799bb12d" dependencies = [ - "const-oid", + "const-oid 0.9.6", "digest 0.10.7", "num-bigint-dig", "num-integer", @@ -2058,9 +2064,9 @@ dependencies = [ [[package]] name = "rust-embed" -version = "8.11.0" +version = "8.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "04113cb9355a377d83f06ef1f0a45b8ab8cd7d8b1288160717d66df5c7988d27" +checksum = "e9e7760e252aaba7b09f4be00e36476cf585bdb68a53552ac954cdf504ab4bc9" dependencies = [ "rust-embed-impl", "rust-embed-utils", @@ -2069,10 +2075,11 @@ dependencies = [ [[package]] name = "rust-embed-impl" -version = "8.11.0" +version = "8.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "da0902e4c7c8e997159ab384e6d0fc91c221375f6894346ae107f47dd0f3ccaa" +checksum = "3bcfc4d6f53af43755f7a723e4b6b8794fcce052a178dd8c6c1dadc5f5343097" dependencies = [ + "mime_guess", "proc-macro2", "quote", "rust-embed-utils", @@ -2082,11 +2089,11 @@ dependencies = [ [[package]] name = "rust-embed-utils" -version = "8.11.0" +version = "8.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5bcdef0be6fe7f6fa333b1073c949729274b05f123a0ad7efcb8efd878e5c3b1" +checksum = "42ffa149f6aa81b58a5b3011d01a857c4ed12c7a732d2c51947a4c7c692185f0" dependencies = [ - "sha2 0.10.9", + "sha2 0.11.0", "walkdir", ] @@ -2690,8 +2697,8 @@ checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" [[package]] name = "swoosh" -version = "0.5.2" -source = "git+ssh://git@git.kundeng.us/phoenix/swoosh.git?tag=v0.5.2#50e4b209f521d8985d73a33b4a8f1db69334100a" +version = "0.5.3" +source = "git+ssh://git@git.kundeng.us/phoenix/swoosh.git?tag=v0.5.3#1c49242bdfe8fe487ea751c89bcbf545c4b8ac3f" dependencies = [ "base64-ng", "reqwest", @@ -2768,7 +2775,7 @@ dependencies = [ [[package]] name = "textsender_api" -version = "0.2.3" +version = "0.2.4" dependencies = [ "axum", "axum-extra", @@ -2792,8 +2799,8 @@ dependencies = [ [[package]] name = "textsender_models" -version = "0.5.1" -source = "git+ssh://git@git.kundeng.us/phoenix/textsender_models.git?tag=v0.5.1#151eeaacf64e255bde56a48df03f4c46ec77c235" +version = "0.5.2" +source = "git+ssh://git@git.kundeng.us/phoenix/textsender_models.git?tag=v0.5.2#02061bf7a380657b7bc76d64d1824388bef8e55a" dependencies = [ "const_format", "dotenvy", @@ -2828,9 +2835,9 @@ dependencies = [ [[package]] name = "thread_local" -version = "1.1.9" +version = "1.1.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f60246a4944f24f6e018aa17cdeffb7818b76356965d03b07d6a9886e8962185" +checksum = "1ad99c4c6d32803332c548b1af0540b357b3f5fc0be8f6c6bfe8b2e6ae784070" dependencies = [ "cfg-if", ] @@ -2877,9 +2884,9 @@ dependencies = [ [[package]] name = "tinyvec" -version = "1.11.0" +version = "1.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3e61e67053d25a4e82c844e8424039d9745781b3fc4f32b8d55ed50f5f667ef3" +checksum = "bb4ebadaa0af04fab11ae01eb5f9fdb5f9c5b875506e210e71c07873528baa7f" dependencies = [ "tinyvec_macros", ] @@ -3510,18 +3517,18 @@ dependencies = [ [[package]] name = "zerocopy" -version = "0.8.53" +version = "0.8.54" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "75726053136156d419e285b9b7eddaaea9e3fea6ce32eed44a89901f0bd98de1" +checksum = "b7cbbc0a705a0fd05cc3676525980d2bf5a9bc4adac6d6475209a7887cf59d19" dependencies = [ "zerocopy-derive", ] [[package]] name = "zerocopy-derive" -version = "0.8.53" +version = "0.8.54" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4714fd92cf900833d49538023a9b3915155210801d1c1169eba513b2addefd71" +checksum = "e2e817b7b52d0c7358d3246da9d69935ebb18116b2b102b4230dac079b4862f5" dependencies = [ "proc-macro2", "quote", @@ -3618,9 +3625,9 @@ dependencies = [ [[package]] name = "zlib-rs" -version = "0.6.5" +version = "0.6.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5431d5661c32445236631278f27946e444ddafe4684cac70b185272d4f9c52d5" +checksum = "b142a20ec14a91d5bc708c1dc21b080c550113d8aa77afa29635673a65dd02c5" [[package]] name = "zmij" diff --git a/Cargo.toml b/Cargo.toml index c3f8006..a28efa2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,8 +1,8 @@ [package] name = "textsender_api" -version = "0.2.3" +version = "0.2.4" edition = "2024" -rust-version = "1.96.1" +rust-version = "1.97" [dependencies] axum = { version = "0.8.9", features = ["multipart"] } @@ -12,14 +12,14 @@ serde_json = { version = "1.0.150" } tokio = { version = "1.52.3", features = ["full"] } tower-http = { version = "0.7.0", features = ["cors", "timeout"] } tracing-subscriber = "0.3.23" -uuid = { version = "1.23.3", features = ["v4", "serde"] } +uuid = { version = "1.23.4", features = ["v4", "serde"] } sqlx = { version = "0.9.0", features = ["runtime-tokio", "tls-native-tls", "postgres", "time", "uuid"] } time = { version = "0.3.53", features = ["formatting", "macros", "parsing", "serde"] } jsonwebtoken = { version = "10.4.0", features = ["rust_crypto"] } 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.5.1" } -swoosh = { git = "ssh://git@git.kundeng.us/phoenix/swoosh.git", tag = "v0.5.2" } +textsender_models = { git = "ssh://git@git.kundeng.us/phoenix/textsender_models.git", tag = "v0.5.2" } +swoosh = { git = "ssh://git@git.kundeng.us/phoenix/swoosh.git", tag = "v0.5.3" } [dev-dependencies] tower = { version = "0.5.3", features = ["full"] } diff --git a/Dockerfile b/Dockerfile index 3a86044..7986c13 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,50 +1,36 @@ -# Stage 1: Build the application -FROM rust:1.96.1 as builder +FROM rust:1.97 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) + rm -rf src target/release/deps/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) @@ -53,18 +39,12 @@ 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 '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/README.md b/README.md new file mode 100644 index 0000000..3153136 --- /dev/null +++ b/README.md @@ -0,0 +1,42 @@ +# Getting started +Fastest way to get started is with docker. Make sure that is installed before moving forward. + +This application requires `textsender_auth` and `catapult` repositories to be located in the +parent directory. + +``` +. +.. +- textsender_auth/ +- textsender_api/ +- catapult/ +``` + +Make sure the othe repositories are configured as it is required to operate successfully. + +Copy over the `.env.docker.sample` to `.env` to get started. + +### Token service +The `JWT_SECRET` environment variable should be the same variable as `SECRET_MAIN_KEY` in +`textsender_auth`. + +### Messaging configuration +textsender uses `twilio` as the service to send the messages. You will need to sign up with +them and be provided an account SID, service SID, auth token, and phone number. Update the +corresponding `TWILIO_*` variables. + + +### Database configuration +Make sure to provide values for the `DB_MAIN_*` variables. For the sake of development, it +can be left as it is. + + +Build the container +``` +docker build +``` + +Run the container +``` +docker compose up +``` diff --git a/docker-compose.yml b/docker-compose.yml index 6dcd817..bf5112b 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -3,12 +3,11 @@ 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: textsender_api # Optional: Give the container a specific name + ssh: ["default"] + container_name: textsender_api ports: - # Map host port 8000 to container port 3000 (adjust as needed) - "9081:9081" env_file: - .env @@ -17,22 +16,18 @@ services: condition: service_healthy networks: - textsender_api-network - restart: unless-stopped # Optional: Restart policy + restart: unless-stopped # --- Auth API --- auth_api: build: - # 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 + context: ../textsender_auth + ssh: ["default"] + dockerfile: Dockerfile 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: @@ -40,9 +35,6 @@ services: condition: service_healthy networks: - textsender_api-network - # Optional: Mount local code for development (live reload) - # volumes: - # - ./path/to/your/web-api-repo:/app # --- catapult service --- catapult: @@ -64,20 +56,17 @@ services: # PostgreSQL Database Service - # --- textsender_api web api db --- main_db: - image: postgres:18.4-alpine # Use an official Postgres image (Alpine variant is smaller) - container_name: textsender_api_db # Optional: Give the container a specific name + image: postgres:18.4-alpine + container_name: textsender_api_db environment: # These MUST match the user, password, and database name in the DATABASE_URL above POSTGRES_USER: ${DB_MAIN_USER:-textsender_api} POSTGRES_PASSWORD: ${DB_MAIN_PASSWORD:-password} POSTGRES_DB: ${DB_MAIN_NAME:-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 @@ -86,14 +75,14 @@ services: timeout: 5s retries: 5 start_period: 10s - restart: always # Optional: Restart policy + restart: always 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 + image: postgres:18.4-alpine + container_name: textsender_api_auth_db environment: # These MUST match the user, password, and database name in the DATABASE_URL above POSTGRES_USER: ${DB_AUTH_USER:-textsender_auth} @@ -103,7 +92,6 @@ services: # 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 @@ -112,18 +100,16 @@ services: timeout: 5s retries: 5 start_period: 10s - restart: always # Optional: Restart policy + restart: always networks: - textsender_api-network -# Define the named volume for data persistence volumes: postgres_data: - driver: local # Use the default local driver + driver: local postgres_data_auth: - driver: local # Use the default local driver + driver: local -# Define the network (optional, but good practice) networks: textsender_api-network: driver: bridge