Deploying to Fly.io
Deploy your EreoJS application to Fly.io for globally distributed hosting.
Prerequisites
- A Fly.io account
- The Fly CLI installed:
curl -L https://fly.io/install.sh | sh - Authenticate:
fly auth login
Dockerfile
Create a Dockerfile in your project root:
FROM oven/bun:1-slim AS deps
WORKDIR /app
COPY package.json bun.lockb ./
RUN bun install --frozen-lockfile --production
FROM oven/bun:1 AS builder
WORKDIR /app
COPY --from=deps /app/node_modules ./node_modules
COPY . .
RUN bun run build
FROM oven/bun:1-slim AS runner
WORKDIR /app
ENV NODE_ENV=production
RUN addgroup --system --gid 1001 app && \
adduser --system --uid 1001 --ingroup app app
COPY --from=builder --chown=app:app /app/dist ./dist
COPY --from=builder --chown=app:app /app/node_modules ./node_modules
COPY --from=builder --chown=app:app /app/package.json ./
USER app
EXPOSE 3000
CMD ["bun", "ereo", "start"]Fly Configuration
Create a fly.toml configuration file:
# fly.toml
app = "my-ereo-app"
primary_region = "iad"
[build]
[http_service]
internal_port = 3000
force_https = true
auto_stop_machines = "stop"
auto_start_machines = true
min_machines_running = 1
[checks]
[checks.health]
type = "http"
port = 3000
path = "/api/health"
interval = "30s"
timeout = "5s"Launch and Deploy
Initialize the Fly app:
fly launchThis detects the Dockerfile, creates the app on Fly.io, and prompts for configuration. Review the settings and confirm.
Deploy:
fly deployFly builds the Docker image remotely and deploys it. Subsequent deploys only rebuild changed layers.
Secrets Management
Set environment variables as Fly secrets (encrypted, not stored in fly.toml):
fly secrets set DATABASE_URL="postgres://user:pass@host:5432/db"
fly secrets set SESSION_SECRET="your-secret-here"List current secrets:
fly secrets listSecrets are injected as environment variables at runtime and are available via process.env.
Scaling Across Regions
Deploy to multiple regions for lower latency:
# Add a region
fly scale count 2 --region iad,cdg
# List current machines
fly statusCommon regions:
iad--- Ashburn, Virginia (US East)lax--- Los Angeles (US West)cdg--- Paris (Europe)nrt--- Tokyo (Asia)
Database with Fly Postgres
Create a Fly Postgres database:
fly postgres create --name my-ereo-db
fly postgres attach my-ereo-dbThis automatically sets the DATABASE_URL secret on your app.
Volumes for Persistent Storage
If your app needs persistent file storage (uploads, SQLite):
fly volumes create data --size 1 --region iadMount it in fly.toml:
[mounts]
source = "data"
destination = "/app/data"Monitoring
View application logs:
fly logsCheck deployment status:
fly statusOpen the deployed app in your browser:
fly openContinuous Deployment
See the CI/CD guide for setting up automatic deploys from GitHub Actions when pushing to main.