Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .env.docker
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Database URL for connecting from the API container to the Postgres container
# The hostname 'postgres' matches the service name in docker-compose.yml
DATABASE_URL=postgres://user:password@postgres:5432/rustforms_db

# We can also move our other secrets here to keep them all in one place for Docker
FORM_SECRET=your-super-secret-unguessable-token
RECIPIENT_EMAIL=your-email@example.com
SMTP_HOST=smtp.example.com
SMTP_USERNAME=your-smtp-username
SMTP_PASSWORD=your-smtp-password
29 changes: 29 additions & 0 deletions apps/api/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# ---- Stage 1: The Builder ----
# Use the official Rust image as a build environment.
FROM rust:1.79-slim as builder

# Set the working directory
WORKDIR /usr/src/rustforms

# Copy the entire monorepo context to leverage Nx caching
COPY . .

# Build the API in release mode using Nx's runner
# This creates an optimized binary.
RUN npx nx run api:build --skip-nx-cache

# ---- Stage 2: The Final Image ----
# Use a minimal, secure base image for the final container.
FROM debian:12-slim

# Set the working directory
WORKDIR /usr/src/rustforms

# Copy the compiled binary from the 'builder' stage.
COPY --from=builder /usr/src/rustforms/dist/apps/api/api .

# Expose the port the app runs on.
EXPOSE 3001

# The command to run when the container starts.
CMD ["./api"]
38 changes: 38 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# File: docker-compose.yml

version: '3.8'

services:
# 1. The PostgreSQL Database Service
postgres:
image: postgres:16-alpine
container_name: rustforms-db
ports:
- "5432:5432" # Expose the database port to your local machine
environment:
# These are the credentials your Rust app will use to connect.
# You can change these, but make sure they match your .env file.
POSTGRES_USER: user
POSTGRES_PASSWORD: password
POSTGRES_DB: rustforms_db
volumes:
- rustforms-data:/var/lib/postgresql/data # This saves your DB data even if the container stops
restart: unless-stopped

# 2. The Rust API Service (we will create its Dockerfile next)
api:
container_name: rustforms-api
build:
context: .
dockerfile: apps/api/Dockerfile
ports:
- "3001:3001" # Expose the API port
depends_on:
- postgres # Tells Docker to start the database before starting the API
environment:
# We will create this .env.docker file next
- .env.docker
restart: unless-stopped

volumes:
rustforms-data: # Defines the persistent volume for the database