Skip to content
Draft
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
37 changes: 37 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Rust build artifacts
/target/
Cargo.lock

# IDE files
.vscode/
.idea/
*.swp
*.swo
*~

# OS generated files
.DS_Store
.DS_Store?
._*
.Spotlight-V100
.Trashes
ehthumbs.db
Thumbs.db

# Environment files
.env
.env.local
.env.production
.env.staging

# Logs
*.log
logs/

# Docker
.dockerignore

# Temporary files
/tmp/
*.tmp
*.temp
5 changes: 1 addition & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
[workspace]
resolver = "2"
members = [
"apps/*",
"services/*",
"packages/*",
"trainer",
]
exclude = [
"vendor/*",
Expand All @@ -27,7 +24,7 @@ tokio-util = "0.7"
# Web framework
axum = "0.7"
tower = "0.5"
tower-http = { version = "0.6", features = ["cors", "trace", "compression"] }
tower-http = { version = "0.6", features = ["cors", "trace", "compression-br", "compression-gzip"] }

# Serialization
serde = { version = "1.0", features = ["derive"] }
Expand Down
2 changes: 0 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
version: '3.9'

services:
api-gateway:
build:
Expand Down
61 changes: 61 additions & 0 deletions services/api/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# Multi-stage build for optimal Docker image size
FROM rust:1.81-slim as builder

# Install system dependencies needed for building
RUN apt-get update && apt-get install -y \
pkg-config \
libssl-dev \
&& rm -rf /var/lib/apt/lists/*

# Set working directory
WORKDIR /app

# Copy workspace files
COPY Cargo.toml ./
COPY services/api/Cargo.toml ./services/api/

# Create dummy source files to build dependencies first (for better caching)
RUN mkdir -p services/api/src && \
echo "fn main() {}" > services/api/src/main.rs

# Build dependencies (this layer will be cached)
RUN cargo build --bin api-gateway --release
RUN rm services/api/src/main.rs

# Copy actual source code
COPY services/api/src ./services/api/src

# Build the actual application
RUN touch services/api/src/main.rs && \
cargo build --bin api-gateway --release

# Runtime stage
FROM debian:bookworm-slim

# Install runtime dependencies
RUN apt-get update && apt-get install -y \
ca-certificates \
curl \
&& rm -rf /var/lib/apt/lists/*

# Create non-root user for security
RUN groupadd -r appuser && useradd -r -g appuser appuser

# Copy the binary from builder stage
COPY --from=builder /app/target/release/api-gateway /usr/local/bin/api-gateway

# Change ownership to non-root user
RUN chown appuser:appuser /usr/local/bin/api-gateway

# Switch to non-root user
USER appuser

# Expose the port that the app runs on
EXPOSE 3000

# Health check
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
CMD curl -f http://localhost:3000/health || exit 1

# Run the binary
CMD ["api-gateway"]