bump: rust docker

This commit is contained in:
2026-07-10 17:45:37 -04:00
parent b60f626178
commit 28d2602927
2 changed files with 17 additions and 51 deletions
+2 -22
View File
@@ -1,50 +1,36 @@
# Stage 1: Build the application FROM rust:1.97 as builder
FROM rust:1.96.1 as builder
# Set the working directory inside the container # Set the working directory inside the container
WORKDIR /usr/src/app 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 \ RUN apt-get update && apt-get install -y --no-install-recommends \
pkg-config libssl3 \ pkg-config libssl3 \
ca-certificates \ ca-certificates \
openssh-client git \ openssh-client git \
&& rm -rf /var/lib/apt/lists/* && rm -rf /var/lib/apt/lists/*
# Create .ssh/ directory for internal dependencies
RUN mkdir -p -m 0700 ~/.ssh && \ RUN mkdir -p -m 0700 ~/.ssh && \
echo "Host git.kundeng.us" >> ~/.ssh/config && \ echo "Host git.kundeng.us" >> ~/.ssh/config && \
echo " User git" >> ~/.ssh/config && \ echo " User git" >> ~/.ssh/config && \
chmod 600 ~/.ssh/config chmod 600 ~/.ssh/config
# << --- ADD HOST KEY HERE --- >>
RUN ssh-keyscan git.kundeng.us >> ~/.ssh/known_hosts RUN ssh-keyscan git.kundeng.us >> ~/.ssh/known_hosts
# Copy Cargo manifests
COPY Cargo.toml Cargo.lock ./ 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 && \ RUN --mount=type=ssh mkdir src && \
echo "fn main() {println!(\"if you see this, the build broke\")}" > src/main.rs && \ echo "fn main() {println!(\"if you see this, the build broke\")}" > src/main.rs && \
cargo build --release --quiet && \ 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 the actual source code
COPY src ./src COPY src ./src
# If you have other directories like `templates` or `static`, copy them too
COPY .env ./.env COPY .env ./.env
COPY migrations ./migrations 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 \ RUN --mount=type=ssh \
cargo build --release --quiet 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 FROM debian:trixie-slim
# Install runtime dependencies if needed (e.g., SSL certificates) # 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 # Set the working directory
WORKDIR /usr/local/bin 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 --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/.env .
COPY --from=builder /usr/src/app/migrations ./migrations COPY --from=builder /usr/src/app/migrations ./migrations
# Expose the port your Axum app listens on (e.g., 3000 or 8000)
EXPOSE 9081 EXPOSE 9081
# Set the command to run your application # Set the command to run your application
# Ensure this matches the binary name copied above
CMD ["./textsender_api"] CMD ["./textsender_api"]
+15 -29
View File
@@ -3,12 +3,11 @@ version: '3.8' # Use a recent version
services: services:
# --- Web API --- # --- Web API ---
api: api:
build: # Tells docker-compose to build the Dockerfile in the current directory build:
context: . context: .
ssh: ["default"] # Uses host's SSH agent ssh: ["default"]
container_name: textsender_api # Optional: Give the container a specific name container_name: textsender_api
ports: ports:
# Map host port 8000 to container port 3000 (adjust as needed)
- "9081:9081" - "9081:9081"
env_file: env_file:
- .env - .env
@@ -17,22 +16,18 @@ services:
condition: service_healthy condition: service_healthy
networks: networks:
- textsender_api-network - textsender_api-network
restart: unless-stopped # Optional: Restart policy restart: unless-stopped
# --- Auth API --- # --- Auth API ---
auth_api: auth_api:
build: 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
context: ../textsender_auth # IMPORTANT: Relative path to the local checkout of your web API repo (containing the Dockerfile) ssh: ["default"]
ssh: ["default"] # Uses host's SSH agent dockerfile: Dockerfile
dockerfile: Dockerfile # Optional: Specify if your Dockerfile has a non-standard name
container_name: auth_api container_name: auth_api
restart: unless-stopped restart: unless-stopped
ports: ports:
- "9080:9080" - "9080:9080"
# environment:
# Environment variables your API needs, e.g., database connection
# Add other necessary environment variables
env_file: env_file:
- ../textsender_auth/.env - ../textsender_auth/.env
depends_on: depends_on:
@@ -40,9 +35,6 @@ services:
condition: service_healthy condition: service_healthy
networks: networks:
- textsender_api-network - textsender_api-network
# Optional: Mount local code for development (live reload)
# volumes:
# - ./path/to/your/web-api-repo:/app
# --- catapult service --- # --- catapult service ---
catapult: catapult:
@@ -64,20 +56,17 @@ services:
# PostgreSQL Database Service # PostgreSQL Database Service
# --- textsender_api web api db ---
main_db: main_db:
image: postgres:18.4-alpine # Use an official Postgres image (Alpine variant is smaller) image: postgres:18.4-alpine
container_name: textsender_api_db # Optional: Give the container a specific name container_name: textsender_api_db
environment: environment:
# These MUST match the user, password, and database name in the DATABASE_URL above # These MUST match the user, password, and database name in the DATABASE_URL above
POSTGRES_USER: ${DB_MAIN_USER:-textsender_api} POSTGRES_USER: ${DB_MAIN_USER:-textsender_api}
POSTGRES_PASSWORD: ${DB_MAIN_PASSWORD:-password} POSTGRES_PASSWORD: ${DB_MAIN_PASSWORD:-password}
POSTGRES_DB: ${DB_MAIN_NAME:-textsender_api_db} POSTGRES_DB: ${DB_MAIN_NAME:-textsender_api_db}
volumes: volumes:
# Persist database data using a named volume
- postgres_data:/var/lib/postgresql - postgres_data:/var/lib/postgresql
ports: ports:
# Optional: Expose port 5432 ONLY if you need to connect directly from your host machine (e.g., for debugging)
- "5432:5432" - "5432:5432"
healthcheck: healthcheck:
# Checks if Postgres is ready to accept connections # Checks if Postgres is ready to accept connections
@@ -86,14 +75,14 @@ services:
timeout: 5s timeout: 5s
retries: 5 retries: 5
start_period: 10s start_period: 10s
restart: always # Optional: Restart policy restart: always
networks: networks:
- textsender_api-network - textsender_api-network
# --- textsender_api web auth api db --- # --- textsender_api web auth api db ---
auth_db: auth_db:
image: postgres:18.4-alpine # Use an official Postgres image (Alpine variant is smaller) image: postgres:18.4-alpine
container_name: textsender_api_auth_db # Optional: Give the container a specific name container_name: textsender_api_auth_db
environment: environment:
# These MUST match the user, password, and database name in the DATABASE_URL above # These MUST match the user, password, and database name in the DATABASE_URL above
POSTGRES_USER: ${DB_AUTH_USER:-textsender_auth} POSTGRES_USER: ${DB_AUTH_USER:-textsender_auth}
@@ -103,7 +92,6 @@ services:
# Persist database data using a named volume # Persist database data using a named volume
- postgres_data_auth:/var/lib/postgresql - postgres_data_auth:/var/lib/postgresql
ports: ports:
# Optional: Expose port 5432 ONLY if you need to connect directly from your host machine (e.g., for debugging)
- "5433:5432" - "5433:5432"
healthcheck: healthcheck:
# Checks if Postgres is ready to accept connections # Checks if Postgres is ready to accept connections
@@ -112,18 +100,16 @@ services:
timeout: 5s timeout: 5s
retries: 5 retries: 5
start_period: 10s start_period: 10s
restart: always # Optional: Restart policy restart: always
networks: networks:
- textsender_api-network - textsender_api-network
# Define the named volume for data persistence
volumes: volumes:
postgres_data: postgres_data:
driver: local # Use the default local driver driver: local
postgres_data_auth: postgres_data_auth:
driver: local # Use the default local driver driver: local
# Define the network (optional, but good practice)
networks: networks:
textsender_api-network: textsender_api-network:
driver: bridge driver: bridge