Repository navigation
Deployment and Operations
Rajesh Mani edited this page Sep 13, 2026
·
1 revision
StudentAppBackend is engineered for continuous deployment across modern containerized infrastructure (Render, Kubernetes, AWS ECS, GCP Cloud Run) and standalone Linux virtual machines.
The project features an optimized multi-stage Dockerfile:
graph LR
subgraph BuildStage["Stage 1: Build (swift:6.0-noble)"]
Source[Swift Source + Package.swift] --> Resolve[Resolve Dependencies Cache Layer]
Resolve --> Compile[swift build -c release --static-swift-stdlib -Xlinker -ljemalloc]
Compile --> StagingArea[/staging: Binary + Resources]
end
subgraph RuntimeStage["Stage 2: Run (ubuntu:noble)"]
Base[Minimal Ubuntu Noble] --> Deps[Install libjemalloc2 & ca-certificates]
Deps --> User[Create unprivileged user: vapor:vapor]
User --> Copy[Copy /staging -> /app]
Copy --> Run[ENTRYPOINT ./StudentAppBackend serve --port 8080]
end
StagingArea --> Copy
-
Memory Allocation (
jemalloc): Replaces standard glibcmallocwith jemalloc to mitigate fragmentation during long-running async event loops. -
Static Linking: Builds with
--static-swift-stdlibto minimize runtime shared library dependencies. -
Least-Privilege Security: Runs as an unprivileged system user (
vapor:vapor, UID 1000) rather thanroot. -
Crash Reporting: Injects
SWIFT_BACKTRACEconfiguration for detailed symbolic crash traces.
The workflow defined in .github/workflows/swift.yml automates quality checks and container distribution:
graph TD
Push[Push to main / tags / PR] --> TestJob[Job: Build & Test (postgres)]
subgraph TestJobPipeline["Test Environment"]
PostgresContainer[postgres:16-alpine Service Container]
HealthCheck[Wait for pg_isready Healthcheck]
SwiftTest[swift test -v]
PostgresContainer --> HealthCheck --> SwiftTest
end
TestJob --> DockerBuildJob[Job: Build Docker Image (Dry Run)]
DockerBuildJob -->|PR Only| PRComplete[PR Verification Passed]
DockerBuildJob -->|Push to main or tag v*| DockerPublishJob[Job: Publish to GHCR]
DockerPublishJob --> GHCRRegistry[(ghcr.io/rajeshm20/studentappbackend)]
Published container images are stored in GitHub Packages:
-
ghcr.io/rajeshm20/studentappbackend:latest(tracksmain) -
ghcr.io/rajeshm20/studentappbackend:v2.0.0(version release) -
ghcr.io/rajeshm20/studentappbackend:sha-<commit>(commit SHA tag)
For environments requiring direct host execution (systemd, bare metal, EC2) without Docker virtualization:
# 1. Install jemalloc performance headers
sudo apt-get update && sudo apt-get install -y libjemalloc-dev
# 2. Build release binary
swift build -c release \
--product StudentAppBackend \
--static-swift-stdlib \
-Xlinker -ljemalloc
# Executable is generated at: .build/release/StudentAppBackend# Compile inside official Swift 6.0 Linux container
docker run --rm \
-v "$PWD":/workspace \
-w /workspace \
swift:6.0-noble \
swift build -c release --product StudentAppBackend --static-swift-stdlib
# Or extract the optimized binary from the multi-stage Docker build:
docker build --target build -t studentapp-builder .
docker run --rm studentapp-builder cat /staging/StudentAppBackend > ./StudentAppBackend-linux
chmod +x ./StudentAppBackend-linuxStudentAppBackend exposes dedicated probe endpoints:
-
GET /health/live: Fast liveness probe returning{"status":"ok"}. Verifies that the HTTP server event loop is actively accepting sockets. -
GET /health/ready: Readiness probe executingSELECT 1against PostgreSQL. Returns200 OK({"status":"ready"}) if the connection pool is healthy, or503 Service Unavailableif database connectivity is lost.
livenessProbe:
httpGet:
path: /health/live
port: 8080
initialDelaySeconds: 5
periodSeconds: 10
readinessProbe:
httpGet:
path: /health/ready
port: 8080
initialDelaySeconds: 10
periodSeconds: 15