fix path in container

This commit is contained in:
d34dscene
2025-02-25 16:50:13 +01:00
parent ac85f2902d
commit 09ac7779f4
6 changed files with 32 additions and 25 deletions
+2 -2
View File
@@ -36,9 +36,9 @@ build-agent:
go build $(LDFLAGS) -o $(BIN_AGENT) agent/cmd/main.go
docker-local:
go generate ./...
# go generate ./...
KO_DOCKER_REPO=ko.local/mantrae ko build . --bare
KO_DOCKER_REPO=ko.local/mantrae-agent ko build ./agent/cmd --bare
# KO_DOCKER_REPO=ko.local/mantrae-agent ko build ./agent/cmd --bare
docker-release:
go generate ./...
+1 -1
View File
@@ -9,7 +9,7 @@ services:
- ADMIN_PASSWORD=<super secret password>
- SECRET=<secret> # generate a secret with openssl rand -hex 32
volumes:
- ./mantrae:/app
- ./mantrae:/data # base directory used
ports:
- 3000:3000 # remove this if you want to use traefik
labels:
+21 -19
View File
@@ -14,7 +14,6 @@ import (
type Config struct {
Admin AdminUser
Server ServerConfig
Database DatabaseConfig
Email EmailConfig
Traefik TraefikConfig
Backup BackupConfig
@@ -37,11 +36,6 @@ type ServerConfig struct {
LogLevel string `env:"SERVER_LOG_LEVEL" envDefault:"info"`
}
type DatabaseConfig struct {
Type string `env:"DB_TYPE" envDefault:"sqlite"`
Name string `env:"DB_NAME" envDefault:"mantrae"`
}
type EmailConfig struct {
Host string `env:"EMAIL_HOST" envDefault:"localhost"`
Port string `env:"EMAIL_PORT" envDefault:"587"`
@@ -59,11 +53,10 @@ type TraefikConfig struct {
}
type BackupConfig struct {
Enabled bool `env:"BACKUP_ENABLED" envDefault:"true"`
BackupPath string `env:"BACKUP_PATH" envDefault:"backups"`
DatabaseName string `env:"DATABASE_NAME" envDefault:"mantrae"`
Interval time.Duration `env:"BACKUP_INTERVAL" envDefault:"24h"`
Keep int `env:"BACKUP_KEEP" envDefault:"3"`
Enabled bool `env:"BACKUP_ENABLED" envDefault:"true"`
BackupPath string `env:"BACKUP_PATH" envDefault:"backups"`
Interval time.Duration `env:"BACKUP_INTERVAL" envDefault:"24h"`
Keep int `env:"BACKUP_KEEP" envDefault:"3"`
}
type BackgroundJobs struct {
@@ -85,14 +78,23 @@ func ReadConfig() (*Config, error) {
return &config, nil
}
func Path(rel string) string {
cwd, err := os.Getwd()
if err != nil {
log.Fatal(err)
}
if filepath.IsAbs(rel) {
return rel
func ResolvePath(path string) string {
var basePath string
if dbPath := os.Getenv("DB_PATH"); dbPath != "" {
basePath = dbPath
} else {
basePath = "data"
}
return filepath.Join(cwd, rel)
// If the provided path is absolute, return it as-is
if filepath.IsAbs(path) {
return path
}
// Create the base directory if it doesn't exist
if err := os.MkdirAll(basePath, 0755); err != nil {
log.Printf("Warning: failed to create base directory: %v", err)
}
return filepath.Join(basePath, path)
}
+1 -1
View File
@@ -111,7 +111,7 @@ func (m *BackupManager) Restore(ctx context.Context, backupName string) error {
m.mu.Lock()
defer m.mu.Unlock()
dbPath := m.Config.DatabaseName + ".db"
dbPath := app.ResolvePath("mantrae.db")
walPath := dbPath + "-wal"
shmPath := dbPath + "-shm"
+3 -1
View File
@@ -6,6 +6,7 @@ import (
"embed"
"fmt"
"github.com/MizuchiLabs/mantrae/internal/app"
"github.com/MizuchiLabs/mantrae/internal/util"
"github.com/pressly/goose/v3"
"modernc.org/sqlite"
@@ -42,7 +43,8 @@ func InitDB() (*sql.DB, error) {
return err
})
db, err = sql.Open("sqlite", "file:mantrae.db")
dbPath := app.ResolvePath("mantrae.db")
db, err = sql.Open("sqlite", fmt.Sprintf("file:%s", dbPath))
if err != nil {
return nil, fmt.Errorf("failed to open database: %w", err)
}
+4 -1
View File
@@ -7,6 +7,8 @@ import (
"os"
"path/filepath"
"sort"
"github.com/MizuchiLabs/mantrae/internal/app"
)
// LocalStorage implements StorageBackend for local filesystem
@@ -15,7 +17,8 @@ type LocalStorage struct {
}
func NewLocalStorage(path string) (*LocalStorage, error) {
if err := os.MkdirAll(path, 0755); err != nil {
resolvedPath := app.ResolvePath(path)
if err := os.MkdirAll(resolvedPath, 0755); err != nil {
return nil, fmt.Errorf("failed to create storage directory: %w", err)
}
return &LocalStorage{basePath: path}, nil