Deployment
This guide covers how to deploy your Pagode application to production environments.
Preparing for Production
Before deploying your Pagode application, ensure you've taken the following steps:
-
Update Configuration
- Modify
config/config.yaml
with production-appropriate settings - Set a secure, random value for
App.EncryptionKey
- Configure database settings properly
- Modify
-
Build for Production
- Use the production build command:
make build
- This creates an optimized binary in the
./bin
directory
- Use the production build command:
-
Environment Variables
- Set the
PAGODA_APP_ENVIRONMENT
variable toproduction
- Override other config settings as needed using environment variables
- Set the
Deployment Options
Docker Deployment
Pagode works well in containerized environments:
FROM golang:1.21-alpine as builder
WORKDIR /app
COPY . .
RUN go build -o pagode ./cmd/pagode
FROM alpine:latest
WORKDIR /app
COPY --from=builder /app/pagode .
COPY --from=builder /app/config ./config
COPY --from=builder /app/public ./public
EXPOSE 8000
CMD ["./pagode"]
Build and run the Docker image:
docker build -t pagode-app .
docker run -p 8000:8000 -e PAGODA_APP_ENVIRONMENT=production pagode-app
Traditional Hosting
For traditional hosting:
- Build the binary on your development machine
- Transfer the binary, configuration files, and static assets to your server
- Set up a service manager (systemd, supervisor, etc.) to keep the application running
Example systemd service file:
[Unit]
Description=Pagode Web Application
After=network.target
[Service]
Type=simple
User=pagode
WorkingDirectory=/path/to/pagode
ExecStart=/path/to/pagode/bin/pagode
Restart=on-failure
Environment=PAGODA_APP_ENVIRONMENT=production
[Install]
WantedBy=multi-user.target
Using a Reverse Proxy
In production, it's recommended to use Pagode behind a reverse proxy like Nginx:
server {
listen 80;
server_name yourdomain.com;
location / {
proxy_pass http://localhost:8000;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
# Handle static files directly
location /static/ {
alias /path/to/pagode/public/;
expires 7d;
}
}
HTTPS Configuration
For secure communication, enable HTTPS in your configuration:
http:
https: true
cert: /path/to/cert.pem
key: /path/to/key.pem
If you're using a reverse proxy like Nginx, you can handle HTTPS termination there instead.
Database Considerations
For production deployments, consider the following for your SQLite database:
- Backup Strategy: Set up regular backups of your
dbs
directory - File Permissions: Ensure proper permissions for the database files
- Disk I/O: Place the database on SSD storage for better performance
- Concurrent Access: Monitor and tune for concurrent access patterns
If you need to scale beyond what SQLite offers, consider switching to PostgreSQL or another database system supported by Ent.
Monitoring
For production monitoring:
- Logging: Configure appropriate log levels and consider forwarding logs to a central system
- Health Checks: Implement
/health
endpoints for monitoring services - Metrics: Consider adding Prometheus metrics for more detailed monitoring
Security Recommendations
- Update the Encryption Key: Always change the default encryption key in production
- Review Middleware: Ensure security middleware is properly configured
- Rate Limiting: Consider adding rate limiting for login and registration pages
- Security Headers: Configure appropriate security headers in your reverse proxy or directly in Go