Skip to main content
Deploying a Mizu app is straightforward: build a single binary, upload it, and run it. This guide covers common deployment methods from simple server deployments to Docker containers.

Building for production

Go compiles your entire application into a single binary with no external dependencies. This makes deployment simple.

Basic build

This creates an executable named app for your current operating system.

Cross-compile for Linux

If you’re building on macOS or Windows for a Linux server:
For ARM servers (like AWS Graviton or Raspberry Pi):

Method 1: Direct server deployment

The simplest approachβ€”upload and run.

Upload the binary

Run manually (testing)

Your app starts on port 3000 (or whatever you configured). Press Ctrl+C to stop.

Run with systemd (production)

To keep your app running after logout and auto-restart on crashes, create a systemd service. Create /etc/systemd/system/myapp.service:
Enable and start the service:
Common commands:

Method 2: Docker deployment

Docker packages your app with its runtime environment for consistent deployments.

Dockerfile

Create a Dockerfile in your project root:
This creates a ~10MB image using distroless (no shell, minimal attack surface).

Build and run

Docker Compose

For apps with dependencies (databases, etc.), use docker-compose.yml:

HTTPS with reverse proxy

Don’t expose your Go app directly to the internet. Use a reverse proxy for:
  • Automatic HTTPS certificates
  • Load balancing
  • Rate limiting
  • Static file serving

Caddy (easiest)

Caddy automatically obtains and renews TLS certificates. Install Caddy, then create /etc/caddy/Caddyfile:
Your app is now available at https://myapp.example.com.

Nginx

For more control, use Nginx with certbot for certificates. /etc/nginx/sites-available/myapp:

Health checks

Mizu provides health check handlers for load balancers and orchestrators.
Configure your load balancer to check /readyz. During graceful shutdown, it returns 503, allowing the load balancer to drain traffic before the server stops.

Graceful shutdown

Mizu handles graceful shutdown automatically. When your app receives SIGINT (Ctrl+C) or SIGTERM (from systemd, Docker, or Kubernetes):
  1. New connections are refused
  2. Active requests complete (up to timeout)
  3. Server exits cleanly
Configure the timeout:

Environment variables

Read configuration from environment variables for different environments:
Set environment variables in your deployment:

Checklist

Before deploying to production:
  • Build with -ldflags="-s -w" for smaller binary
  • Set up a reverse proxy (Caddy or Nginx) for HTTPS
  • Configure systemd or Docker for auto-restart
  • Set up health check endpoints
  • Configure graceful shutdown timeout
  • Set up log aggregation
  • Test graceful shutdown locally