Swift on Miren
Swift isn't auto-detected, so you deploy it with a Dockerfile.miren that compiles your
app and runs the binary. This guide uses Vapor, the main
server-side Swift framework.
Ask your AI coding agent to "set up this Vapor app on Miren" after installing the
Miren agent skills. It adds the Dockerfile.miren, binds the server to
0.0.0.0:$PORT, and deploys — using this page as its reference.
Do you need a Dockerfile?
Yes. Miren doesn't auto-detect Swift, so add a Dockerfile.miren to your project root.
Miren builds from it instead of guessing the stack — see
Using Dockerfile.miren.
Miren auto-detects and builds common stacks (Python, Node, Bun, Go, Ruby, Rust) without a Dockerfile. This language isn't one of them yet — if you'd like first-class support, request it.
Bind to the injected port
Miren injects PORT and routes traffic to it, so set Vapor's server hostname to
0.0.0.0 and the port from the environment:
import Vapor
var env = try Environment.detect()
let app = Application(env)
defer { app.shutdown() }
app.get { req in "Hello from Swift on Miren!\n" }
app.http.server.configuration.hostname = "0.0.0.0"
app.http.server.configuration.port = Int(Environment.get("PORT") ?? "8080") ?? 8080
try app.run()
A Package.swift declaring Vapor and an executable target:
// swift-tools-version:5.10
import PackageDescription
let package = Package(
name: "swift-bench",
platforms: [.macOS(.v13)],
dependencies: [
.package(url: "https://github.com/vapor/vapor.git", from: "4.106.0"),
],
targets: [
.executableTarget(
name: "App",
dependencies: [.product(name: "Vapor", package: "vapor")]
),
]
)
The Dockerfile
Create Dockerfile.miren in your project root. --static-swift-stdlib links the Swift
runtime into the binary so the runtime image stays small:
# ----- Build stage -----
FROM swift:5.10-jammy AS build
WORKDIR /app
COPY . .
RUN swift build -c release --static-swift-stdlib
# ----- Runtime stage -----
FROM ubuntu:jammy
RUN apt-get update -y && apt-get install -y ca-certificates libcurl4 && rm -rf /var/lib/apt/lists/*
WORKDIR /app
COPY --from=build /app/.build/release/App /app/App
EXPOSE 8080
CMD ["/app/App"]
Vapor pulls in swift-crypto, which compiles BoringSSL from C/C++ — the first build takes several minutes. Miren caches image layers, so rebuilds that don't change dependencies are faster.
.dockerignore
.git
.build
Set up the app
Even with a Dockerfile.miren, Miren needs at least one service defined — it
doesn't use the image's CMD as the start command. The executable target App compiles
to /app/App:
web: /app/App
Then create .miren/app.toml naming your app and deploy from your project root:
name = "swift-bench"
miren deploy
If no service is defined, the build succeeds but the deploy stops with
no services defined: please define at least one service in a Procfile or .miren/app.toml.
Environment variables
Set variables with miren env set — -e for plain values, -s for secrets (masked in
output and logs). Read them with Environment.get("KEY"):
miren env set -e LOG_LEVEL=info
miren env set -s DATABASE_URL
You can also declare variables in .miren/app.toml:
[[env]]
key = "DATABASE_URL"
value = ""
required = true
sensitive = true
See App Configuration — Environment Variables.
Agent quick reference
- Detection: none — requires
Dockerfile.miren - Build:
swift build -c release --static-swift-stdlibonswift:5.10-jammy(slow — BoringSSL) - Runtime:
ubuntu:jammy+ca-certificates libcurl4; binary at.build/release/<target> - Service is required: define a
Procfile(web: /app/App) — the imageCMDis not used - Port:
Environment.get("PORT"); setapp.http.server.configuration.hostname = "0.0.0.0" - Env vars:
miren env set -e/-s; read withEnvironment.get
Next steps
- Using Dockerfile.miren — how custom builds work
- App Configuration — customize
.miren/app.toml - Deployment — how deploys build and activate