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/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