this should do it
This commit is contained in:
@@ -34,7 +34,13 @@ func run() error {
|
|||||||
logger.Info("deployer service starting",
|
logger.Info("deployer service starting",
|
||||||
"log_level", cfg.LogLevel)
|
"log_level", cfg.LogLevel)
|
||||||
|
|
||||||
database, err := db.OpenDB(cfg.DBPath)
|
dbConfig := &db.DBConfig{
|
||||||
|
JournalMode: cfg.DBJournalMode,
|
||||||
|
Synchronous: cfg.DBSynchronous,
|
||||||
|
BusyTimeout: cfg.DBBusyTimeout,
|
||||||
|
}
|
||||||
|
|
||||||
|
database, err := db.OpenDB(cfg.DBPath, dbConfig)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to open database: %w", err)
|
return fmt.Errorf("failed to open database: %w", err)
|
||||||
}
|
}
|
||||||
|
|||||||
40
docker-compose.prod.yml
Normal file
40
docker-compose.prod.yml
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
# Production Docker Compose configuration
|
||||||
|
# This configuration is optimized for production environments
|
||||||
|
# and addresses common SQLite issues in containerized deployments
|
||||||
|
|
||||||
|
version: "3.8"
|
||||||
|
|
||||||
|
services:
|
||||||
|
server:
|
||||||
|
container_name: tingz-server
|
||||||
|
env_file: .env
|
||||||
|
build:
|
||||||
|
context: .
|
||||||
|
args:
|
||||||
|
UID: ${UID}
|
||||||
|
GID: ${GID}
|
||||||
|
environment:
|
||||||
|
# Database configuration for production
|
||||||
|
DB_JOURNAL_MODE: "DELETE" # Use DELETE mode instead of WAL for better volume mount compatibility
|
||||||
|
DB_SYNCHRONOUS: "FULL" # Full synchronous mode for data integrity
|
||||||
|
DB_BUSY_TIMEOUT: "30000" # 30 second timeout for busy database
|
||||||
|
|
||||||
|
# Optional: Override other settings for production
|
||||||
|
# LOG_LEVEL: "warn" # Reduce log verbosity in production
|
||||||
|
# MAX_UPLOAD_SIZE: "52428800" # 50MB limit for production
|
||||||
|
volumes:
|
||||||
|
- ./data:/data
|
||||||
|
- ./docs:/var/www/docs
|
||||||
|
- ./deploys:/var/www/deploys
|
||||||
|
ports:
|
||||||
|
- "${HOST}:${PORT}:8080"
|
||||||
|
user: "${UID}:${GID}"
|
||||||
|
restart: unless-stopped
|
||||||
|
|
||||||
|
# Health check to ensure service is running
|
||||||
|
healthcheck:
|
||||||
|
test: ["CMD", "wget", "--quiet", "--tries=1", "--spider", "http://localhost:8080/api/v1/status"]
|
||||||
|
interval: 30s
|
||||||
|
timeout: 10s
|
||||||
|
retries: 3
|
||||||
|
start_period: 40s
|
||||||
@@ -11,6 +11,9 @@ type Config struct {
|
|||||||
DeployRoot string
|
DeployRoot string
|
||||||
ReleaseRoot string
|
ReleaseRoot string
|
||||||
DBPath string
|
DBPath string
|
||||||
|
DBJournalMode string
|
||||||
|
DBSynchronous string
|
||||||
|
DBBusyTimeout int
|
||||||
MaxUploadSize int64
|
MaxUploadSize int64
|
||||||
LogLevel string
|
LogLevel string
|
||||||
ReleasesToKeep int
|
ReleasesToKeep int
|
||||||
@@ -25,6 +28,9 @@ func LoadConfig() (*Config, error) {
|
|||||||
DeployRoot: getEnvOrDefault("DEPLOY_ROOT", "/var/www/docs"),
|
DeployRoot: getEnvOrDefault("DEPLOY_ROOT", "/var/www/docs"),
|
||||||
ReleaseRoot: getEnvOrDefault("RELEASE_ROOT", "/var/www/deploys"),
|
ReleaseRoot: getEnvOrDefault("RELEASE_ROOT", "/var/www/deploys"),
|
||||||
DBPath: getEnvOrDefault("DB_PATH", "/data/deployer.db"),
|
DBPath: getEnvOrDefault("DB_PATH", "/data/deployer.db"),
|
||||||
|
DBJournalMode: getEnvOrDefault("DB_JOURNAL_MODE", "DELETE"),
|
||||||
|
DBSynchronous: getEnvOrDefault("DB_SYNCHRONOUS", "FULL"),
|
||||||
|
DBBusyTimeout: getEnvAsInt("DB_BUSY_TIMEOUT", 10000),
|
||||||
MaxUploadSize: getEnvAsInt64("MAX_UPLOAD_SIZE", 104857600),
|
MaxUploadSize: getEnvAsInt64("MAX_UPLOAD_SIZE", 104857600),
|
||||||
LogLevel: getEnvOrDefault("LOG_LEVEL", "info"),
|
LogLevel: getEnvOrDefault("LOG_LEVEL", "info"),
|
||||||
ReleasesToKeep: getEnvAsInt("RELEASES_TO_KEEP", 5),
|
ReleasesToKeep: getEnvAsInt("RELEASES_TO_KEEP", 5),
|
||||||
|
|||||||
@@ -5,16 +5,29 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"syscall"
|
||||||
|
|
||||||
_ "modernc.org/sqlite"
|
_ "modernc.org/sqlite"
|
||||||
)
|
)
|
||||||
|
|
||||||
func OpenDB(path string) (*sql.DB, error) {
|
type DBConfig struct {
|
||||||
|
JournalMode string
|
||||||
|
Synchronous string
|
||||||
|
BusyTimeout int
|
||||||
|
}
|
||||||
|
|
||||||
|
func OpenDB(path string, config *DBConfig) (*sql.DB, error) {
|
||||||
dir := filepath.Dir(path)
|
dir := filepath.Dir(path)
|
||||||
if err := os.MkdirAll(dir, 0755); err != nil {
|
if err := os.MkdirAll(dir, 0755); err != nil {
|
||||||
return nil, fmt.Errorf("failed to create database directory: %w", err)
|
return nil, fmt.Errorf("failed to create database directory: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Check if database file exists and get file info for diagnostics
|
||||||
|
var fileInfo os.FileInfo
|
||||||
|
if info, err := os.Stat(path); err == nil {
|
||||||
|
fileInfo = info
|
||||||
|
}
|
||||||
|
|
||||||
db, err := sql.Open("sqlite", path)
|
db, err := sql.Open("sqlite", path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("failed to open database: %w", err)
|
return nil, fmt.Errorf("failed to open database: %w", err)
|
||||||
@@ -22,14 +35,46 @@ func OpenDB(path string) (*sql.DB, error) {
|
|||||||
|
|
||||||
if err := db.Ping(); err != nil {
|
if err := db.Ping(); err != nil {
|
||||||
db.Close()
|
db.Close()
|
||||||
return nil, fmt.Errorf("failed to ping database: %w", err)
|
|
||||||
|
// Enhanced error diagnostics
|
||||||
|
diag := fmt.Sprintf("database path: %s", path)
|
||||||
|
if fileInfo != nil {
|
||||||
|
diag += fmt.Sprintf(", file size: %d bytes, mode: %s", fileInfo.Size(), fileInfo.Mode())
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check directory permissions
|
||||||
|
if dirInfo, err := os.Stat(dir); err == nil {
|
||||||
|
diag += fmt.Sprintf(", dir mode: %s", dirInfo.Mode())
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if it's a file system issue
|
||||||
|
if pathErr, ok := err.(*os.PathError); ok {
|
||||||
|
if pathErr.Err == syscall.ENOSPC {
|
||||||
|
diag += ", filesystem full"
|
||||||
|
} else if pathErr.Err == syscall.EACCES {
|
||||||
|
diag += ", permission denied"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil, fmt.Errorf("failed to ping database: %w (%s)", err, diag)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set default config if not provided
|
||||||
|
if config == nil {
|
||||||
|
config = &DBConfig{
|
||||||
|
JournalMode: "DELETE",
|
||||||
|
Synchronous: "FULL",
|
||||||
|
BusyTimeout: 10000,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pragmas := []string{
|
pragmas := []string{
|
||||||
"PRAGMA journal_mode=WAL",
|
fmt.Sprintf("PRAGMA journal_mode=%s", config.JournalMode),
|
||||||
"PRAGMA foreign_keys=ON",
|
"PRAGMA foreign_keys=ON",
|
||||||
"PRAGMA synchronous=NORMAL",
|
fmt.Sprintf("PRAGMA synchronous=%s", config.Synchronous),
|
||||||
"PRAGMA busy_timeout=5000",
|
fmt.Sprintf("PRAGMA busy_timeout=%d", config.BusyTimeout),
|
||||||
|
"PRAGMA temp_store=MEMORY",
|
||||||
|
"PRAGMA mmap_size=268435456",
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, pragma := range pragmas {
|
for _, pragma := range pragmas {
|
||||||
|
|||||||
Reference in New Issue
Block a user