8.2 KiB
8.2 KiB
Deployment Guide for Akiyama Manga
Deployment Options
1. Local Development
# Install dependencies
go mod download
# Setup database (see DATABASE_SETUP.md)
# Setup S3 (see S3_SETUP.md)
# Create .env file
cp .env.example .env
# Edit .env with your configuration
# Run the application
go run cmd/server/main.go
The application will be available at http://localhost:8080
2. Docker Deployment (Recommended)
Prerequisites
- Docker
- Docker Compose
Quick Start
# Clone repository
git clone <repo-url>
cd akiyama-manga
# Create .env file
cp .env.example .env
# Edit .env with your configuration
# Start services
docker-compose up -d
# View logs
docker-compose logs -f app
Services will be available at:
- Application:
http://localhost:8080 - PgAdmin:
http://localhost:5050(admin@example.com / admin)
Useful Docker Commands
# Stop services
docker-compose down
# Rebuild without cache
docker-compose build --no-cache
# Remove volumes (WARNING: deletes data)
docker-compose down -v
# Scale services
docker-compose up -d --scale app=3
# View logs
docker-compose logs -f [service-name]
# Execute command in container
docker-compose exec app /bin/sh
3. Server Deployment (Linux)
Requirements
- Ubuntu 20.04 LTS or similar
- Git
- PostgreSQL 12+
- AWS S3 bucket
Installation Steps
- SSH into server
ssh ubuntu@your-server-ip
- Install system dependencies
sudo apt-get update
sudo apt-get install -y git postgresql postgresql-contrib curl
# Install Go
wget https://go.dev/dl/go1.21.0.linux-amd64.tar.gz
sudo tar -C /usr/local -xzf go1.21.0.linux-amd64.tar.gz
export PATH=$PATH:/usr/local/go/bin
echo 'export PATH=$PATH:/usr/local/go/bin' >> ~/.bashrc
- Clone repository
cd /opt
sudo git clone <repo-url> akiyama-manga
cd akiyama-manga
- Setup environment
cp .env.example .env
sudo nano .env
# Configure all variables
- Install dependencies
go mod download
- Build application
mkdir -p build
go build -o build/akiyama-manga cmd/server/main.go
- Create systemd service
sudo tee /etc/systemd/system/akiyama-manga.service > /dev/null <<EOF
[Unit]
Description=Akiyama Manga Service
After=network.target postgresql.service
[Service]
Type=simple
User=ubuntu
WorkingDirectory=/opt/akiyama-manga
EnvironmentFile=/opt/akiyama-manga/.env
ExecStart=/opt/akiyama-manga/build/akiyama-manga
Restart=on-failure
RestartSec=5s
[Install]
WantedBy=multi-user.target
EOF
sudo systemctl daemon-reload
sudo systemctl enable akiyama-manga
sudo systemctl start akiyama-manga
- Verify service
sudo systemctl status akiyama-manga
curl http://localhost:8080
4. Kubernetes Deployment
Prerequisites
- kubectl configured
- Kubernetes cluster
- Docker image registry
Create Kubernetes Manifests
namespace.yaml:
apiVersion: v1
kind: Namespace
metadata:
name: akiyama
deployment.yaml:
apiVersion: apps/v1
kind: Deployment
metadata:
name: akiyama-app
namespace: akiyama
spec:
replicas: 3
selector:
matchLabels:
app: akiyama-app
template:
metadata:
labels:
app: akiyama-app
spec:
containers:
- name: app
image: your-registry/akiyama-manga:latest
ports:
- containerPort: 8080
env:
- name: DB_HOST
value: postgres-service
- name: DB_PORT
value: "5432"
- name: DB_NAME
valueFrom:
configMapKeyRef:
name: app-config
key: db-name
envFrom:
- secretRef:
name: app-secrets
livenessProbe:
httpGet:
path: /
port: 8080
initialDelaySeconds: 30
periodSeconds: 10
readinessProbe:
httpGet:
path: /
port: 8080
initialDelaySeconds: 5
periodSeconds: 5
service.yaml:
apiVersion: v1
kind: Service
metadata:
name: akiyama-service
namespace: akiyama
spec:
selector:
app: akiyama-app
ports:
- protocol: TCP
port: 80
targetPort: 8080
type: LoadBalancer
Deploy
kubectl apply -f namespace.yaml
kubectl apply -f deployment.yaml
kubectl apply -f service.yaml
# Check status
kubectl -n akiyama get pods
kubectl -n akiyama get svc
5. Cloud Platforms
Heroku
# Install Heroku CLI
# Login
heroku login
# Create app
heroku create akiyama-manga
# Add PostgreSQL addon
heroku addons:create heroku-postgresql:standard-0
# Set environment variables
heroku config:set JWT_SECRET=your_secret
heroku config:set AWS_ACCESS_KEY_ID=your_key
heroku config:set AWS_SECRET_ACCESS_KEY=your_secret
heroku config:set S3_BUCKET_NAME=your_bucket
# Deploy
git push heroku main
Railway
- Connect GitHub repository
- Add PostgreSQL service
- Set environment variables
- Deploy
DigitalOcean App Platform
- Create new app from GitHub
- Set environment variables
- Deploy
Nginx Reverse Proxy (Production)
upstream akiyama_app {
server localhost:8080;
}
server {
listen 80;
server_name yourdomain.com;
# Redirect to HTTPS
return 301 https://$server_name$request_uri;
}
server {
listen 443 ssl http2;
server_name yourdomain.com;
ssl_certificate /etc/letsencrypt/live/yourdomain.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/yourdomain.com/privkey.pem;
# Security headers
add_header Strict-Transport-Security "max-age=31536000" always;
add_header X-Content-Type-Options "nosniff" always;
add_header X-Frame-Options "SAMEORIGIN" always;
add_header X-XSS-Protection "1; mode=block" always;
# Gzip compression
gzip on;
gzip_types text/plain text/css application/json application/javascript;
location / {
proxy_pass http://akiyama_app;
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;
# Timeouts
proxy_connect_timeout 60s;
proxy_send_timeout 60s;
proxy_read_timeout 60s;
}
# Static files caching
location ~* \.(jpg|jpeg|png|gif|ico|css|js|svg|woff|woff2|ttf|eot)$ {
expires 1y;
add_header Cache-Control "public, immutable";
}
}
SSL/TLS with Let's Encrypt
sudo apt-get install certbot python3-certbot-nginx
sudo certbot certonly --nginx -d yourdomain.com
sudo certbot renew --dry-run
Monitoring and Logging
Application Logs
# View service logs
sudo journalctl -u akiyama-manga -f
# Docker logs
docker-compose logs -f app
Monitoring with Prometheus
Add to docker-compose.yml:
prometheus:
image: prom/prometheus:latest
volumes:
- ./prometheus.yml:/etc/prometheus/prometheus.yml
- prometheus_data:/prometheus
ports:
- "9090:9090"
Health Checks
The application exposes health check endpoints:
GET /health- Basic health checkGET /health/ready- Readiness probeGET /health/live- Liveness probe
Backup and Recovery
Database Backup
# Docker
docker-compose exec postgres pg_dump -U manga_user akiyama_manga > backup.sql
# Manual
pg_dump -U manga_user -d akiyama_manga > backup.sql
Restore from Backup
psql -U manga_user -d akiyama_manga < backup.sql
S3 Backup
Use AWS Backup or S3 cross-region replication.
Performance Tuning
Application Optimization
- Enable caching in production (GIN default)
- Database connection pooling with PgBouncer
- CDN for static assets (CloudFront, Cloudflare)
- Database query optimization with indexes
Load Testing
ab -n 1000 -c 100 http://localhost:8080/
Troubleshooting
Connection refused
- Check firewall rules
- Verify service is running
- Check port bindings
Database connection errors
- Verify PostgreSQL is running
- Check credentials in .env
- Test with psql client
S3 upload failures
- Verify AWS credentials
- Check bucket exists and is accessible
- Verify CORS configuration
High memory usage
- Check for goroutine leaks
- Monitor database connections
- Review application logs