diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..43795d7 --- /dev/null +++ b/.gitignore @@ -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 \ No newline at end of file diff --git a/Cargo.toml b/Cargo.toml index 1a08943..3bffc3d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,10 +1,7 @@ [workspace] resolver = "2" members = [ - "apps/*", "services/*", - "packages/*", - "trainer", ] exclude = [ "vendor/*", @@ -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"] } diff --git a/docker-compose.yml b/docker-compose.yml index 23cb7e2..c59700d 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,5 +1,3 @@ -version: '3.9' - services: api-gateway: build: diff --git a/services/api/Dockerfile b/services/api/Dockerfile new file mode 100644 index 0000000..8be0725 --- /dev/null +++ b/services/api/Dockerfile @@ -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"] \ No newline at end of file