Switch to modernc.org/sqlite and update dockerfile

This commit is contained in:
2026-05-06 19:00:28 +02:00
parent b28b9b127b
commit e5fd59f3ed
16 changed files with 162 additions and 127 deletions
+14 -1
View File
@@ -10,9 +10,22 @@ import (
"github.com/gofiber/fiber/v3"
)
func NewStaticHandler(storagePath string, siteRepo repository.SiteRepository) fiber.Handler {
func NewStaticHandler(storagePath string, siteRepo repository.SiteRepository, staticDashboardPath, dashboardHost string) fiber.Handler {
return func(c fiber.Ctx) error {
domain := c.Hostname()
if staticDashboardPath != "" && domain == dashboardHost {
urlPath := c.Path()
filePath := filepath.Join(staticDashboardPath, filepath.Clean(urlPath))
info, err := os.Stat(filePath)
if err == nil && !info.IsDir() {
return c.SendFile(filePath)
}
return c.SendFile(filepath.Join(staticDashboardPath, "index.html"))
}
site, err := siteRepo.GetSiteByDomain(domain)
if err != nil {
return c.Status(fiber.StatusInternalServerError).SendString("Failed to resolve site")
+5 -2
View File
@@ -2,10 +2,13 @@ package middleware
import "github.com/gofiber/fiber/v3"
func APIHostGuard(allowedHost string) fiber.Handler {
func APIHostGuard(allowedHost string, alternativeHandler fiber.Handler) fiber.Handler {
return func(c fiber.Ctx) error {
if c.Hostname() != allowedHost {
return c.Status(fiber.StatusNotFound).SendString("Not Found")
if alternativeHandler != nil {
return alternativeHandler(c)
}
return c.Status(fiber.StatusForbidden).SendString("Forbidden: Invalid API host")
}
return c.Next()
}
+18 -14
View File
@@ -7,18 +7,19 @@ import (
"quay/app/handlers"
"quay/app/middleware"
"quay/app/models"
"quay/internal/config"
"quay/internal/database"
"quay/internal/envconfig"
"quay/internal/security"
"github.com/Flussen/swagger-fiber-v3"
"github.com/gofiber/fiber/v3"
"github.com/gofiber/fiber/v3/middleware/static"
)
const BootstrapUserUsername = "admin"
const BootstrapUserPassword = "admin"
func Register(app *fiber.App, cfg *config.Config, envCfg *envconfig.EnvConfig, db *sql.DB) {
func Register(app *fiber.App, envCfg *envconfig.EnvConfig, db *sql.DB) {
siteRepository := database.NewSQLiteSiteRepository(db)
deploymentRepository := database.NewSQLiteDeploymentRepository(db)
userRepository := database.NewSQLiteUserRepository(db)
@@ -45,13 +46,19 @@ func Register(app *fiber.App, cfg *config.Config, envCfg *envconfig.EnvConfig, d
}
}
storagePath, err := filepath.Abs(envCfg.StoragePath)
if err != nil {
log.Fatalf("Failed to resolve storage path: %v", err)
}
siteHandler := handlers.NewSiteHandler(siteRepository)
deploySiteHandler := handlers.NewDeploySiteHandler(envCfg, siteRepository, gitServerRepository, deploymentRepository)
userHandler := handlers.NewUserHandler(userRepository)
gitServerHandler := handlers.NewGitServerHandler(gitServerRepository)
deploymentsHandler := handlers.NewDeploymentHandler(deploymentRepository)
staticSiteHandler := handlers.NewStaticHandler(storagePath, siteRepository, envCfg.StaticDashboardPath, envCfg.DashboardHost)
api := app.Group("/api/v1", middleware.APIHostGuard(envCfg.DashboardHost))
api := app.Group("/api/v1", middleware.APIHostGuard(envCfg.DashboardHost, staticSiteHandler))
public := api.Group("")
public.Get("/health", handlers.HealthCheck)
@@ -61,6 +68,13 @@ func Register(app *fiber.App, cfg *config.Config, envCfg *envconfig.EnvConfig, d
public.Post("/deploy", deploySiteHandler.PostDeploy)
public.Get("/api/docs.json", static.New("./docs/swagger.json"))
public.Get("/api/swagger/*", swagger.New(swagger.Config{
URL: "/api/docs.json",
Title: "mcheads.net API Documentation",
}))
// Protected routes - require auth for everything by default
protected := api.Group("", middleware.RequireAuth())
@@ -119,15 +133,5 @@ func Register(app *fiber.App, cfg *config.Config, envCfg *envconfig.EnvConfig, d
})
})
storagePath, err := filepath.Abs(envCfg.StoragePath)
if err != nil {
log.Fatalf("Failed to resolve storage path: %v", err)
}
siteMap := make(map[string]config.SiteConfig)
for _, site := range cfg.Sites {
siteMap[site.Domain] = site
}
app.Use(handlers.NewStaticHandler(storagePath, siteRepository))
app.Use(staticSiteHandler)
}