Moved github PAT and storage path to env vars
This commit is contained in:
+1
-1
@@ -1,5 +1,5 @@
|
|||||||
.env
|
.env
|
||||||
config/config.yaml
|
config/config.yaml
|
||||||
mydeploys
|
storage
|
||||||
quay
|
quay
|
||||||
config
|
config
|
||||||
@@ -27,6 +27,7 @@ USER appuser
|
|||||||
|
|
||||||
ENV PORT=4321
|
ENV PORT=4321
|
||||||
ENV CONFIG_DIR=/config
|
ENV CONFIG_DIR=/config
|
||||||
|
ENV STORAGE_PATH=/storage
|
||||||
|
|
||||||
EXPOSE 4321
|
EXPOSE 4321
|
||||||
|
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ func NewStaticHandler(storagePath string, siteMap map[string]config.SiteConfig)
|
|||||||
return func(c fiber.Ctx) error {
|
return func(c fiber.Ctx) error {
|
||||||
site, ok := siteMap[c.Hostname()]
|
site, ok := siteMap[c.Hostname()]
|
||||||
if !ok {
|
if !ok {
|
||||||
return c.SendStatus(fiber.StatusNotFound)
|
return c.Status(fiber.StatusNotFound).SendString("Site not found")
|
||||||
}
|
}
|
||||||
|
|
||||||
urlPath := filepath.Clean(c.Path())
|
urlPath := filepath.Clean(c.Path())
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import (
|
|||||||
"quay/app/github"
|
"quay/app/github"
|
||||||
"quay/app/models"
|
"quay/app/models"
|
||||||
"quay/internal/config"
|
"quay/internal/config"
|
||||||
|
"quay/internal/envconfig"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"crypto/subtle"
|
"crypto/subtle"
|
||||||
@@ -12,7 +13,7 @@ import (
|
|||||||
"github.com/gofiber/fiber/v3"
|
"github.com/gofiber/fiber/v3"
|
||||||
)
|
)
|
||||||
|
|
||||||
func NewUpdateSiteHandler(cfg *config.Config) fiber.Handler {
|
func NewUpdateSiteHandler(cfg *config.Config, envCfg *envconfig.EnvConfig) fiber.Handler {
|
||||||
return func(c fiber.Ctx) error {
|
return func(c fiber.Ctx) error {
|
||||||
sitename := c.Query("site")
|
sitename := c.Query("site")
|
||||||
if sitename == "" {
|
if sitename == "" {
|
||||||
@@ -58,7 +59,7 @@ func NewUpdateSiteHandler(cfg *config.Config) fiber.Handler {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
sitePath := filepath.Join(cfg.Global.StoragePath, siteConfig.Name)
|
sitePath := filepath.Join(envCfg.StoragePath, siteConfig.Name)
|
||||||
if _, err := filepath.Abs(sitePath); err != nil {
|
if _, err := filepath.Abs(sitePath); err != nil {
|
||||||
return c.Status(500).JSON(models.APIError{
|
return c.Status(500).JSON(models.APIError{
|
||||||
Error: "Failed to resolve site path",
|
Error: "Failed to resolve site path",
|
||||||
@@ -69,7 +70,7 @@ func NewUpdateSiteHandler(cfg *config.Config) fiber.Handler {
|
|||||||
siteConfig.Owner,
|
siteConfig.Owner,
|
||||||
siteConfig.Repo,
|
siteConfig.Repo,
|
||||||
siteConfig.Branch,
|
siteConfig.Branch,
|
||||||
cfg.Global.GithubPat,
|
envCfg.GithubPat,
|
||||||
sitePath,
|
sitePath,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -5,17 +5,18 @@ import (
|
|||||||
"path/filepath"
|
"path/filepath"
|
||||||
"quay/app/handlers"
|
"quay/app/handlers"
|
||||||
"quay/internal/config"
|
"quay/internal/config"
|
||||||
|
"quay/internal/envconfig"
|
||||||
|
|
||||||
"github.com/gofiber/fiber/v3"
|
"github.com/gofiber/fiber/v3"
|
||||||
)
|
)
|
||||||
|
|
||||||
func Register(app *fiber.App, cfg *config.Config) {
|
func Register(app *fiber.App, cfg *config.Config, envCfg *envconfig.EnvConfig) {
|
||||||
api := app.Group("/api")
|
api := app.Group("/api")
|
||||||
api.Get("/health", handlers.HealthCheck)
|
api.Get("/health", handlers.HealthCheck)
|
||||||
|
|
||||||
api.Post("/update", handlers.NewUpdateSiteHandler(cfg))
|
api.Post("/update", handlers.NewUpdateSiteHandler(cfg, envCfg))
|
||||||
|
|
||||||
storagePath, err := filepath.Abs(cfg.Global.StoragePath)
|
storagePath, err := filepath.Abs(envCfg.StoragePath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("Failed to resolve storage path: %v", err)
|
log.Fatalf("Failed to resolve storage path: %v", err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,10 +2,6 @@
|
|||||||
# This file defines the global settings and the sites to be deployed.
|
# This file defines the global settings and the sites to be deployed.
|
||||||
# You can use ${VARIABLE_NAME} to reference environment variables for sensitive information.
|
# You can use ${VARIABLE_NAME} to reference environment variables for sensitive information.
|
||||||
|
|
||||||
global:
|
|
||||||
github_pat: "${GITHUB_PAT}"
|
|
||||||
storage_path: /var/www/sites
|
|
||||||
|
|
||||||
sites:
|
sites:
|
||||||
- repo: my-lib-docs
|
- repo: my-lib-docs
|
||||||
owner: yourname
|
owner: yourname
|
||||||
|
|||||||
+1
-1
@@ -10,7 +10,7 @@ services:
|
|||||||
- '8080:4321'
|
- '8080:4321'
|
||||||
volumes:
|
volumes:
|
||||||
- ./config:/config
|
- ./config:/config
|
||||||
- ./mydeploys:/deploys
|
- ./storage:/storage
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
healthcheck:
|
healthcheck:
|
||||||
test:
|
test:
|
||||||
|
|||||||
@@ -6,11 +6,6 @@ import (
|
|||||||
"gopkg.in/yaml.v3"
|
"gopkg.in/yaml.v3"
|
||||||
)
|
)
|
||||||
|
|
||||||
type GlobalConfig struct {
|
|
||||||
GithubPat string `yaml:"github_pat"`
|
|
||||||
StoragePath string `yaml:"storage_path"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type SiteConfig struct {
|
type SiteConfig struct {
|
||||||
Name string `yaml:"name"`
|
Name string `yaml:"name"`
|
||||||
Repo string `yaml:"repo"`
|
Repo string `yaml:"repo"`
|
||||||
@@ -23,7 +18,6 @@ type SiteConfig struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
Global GlobalConfig `yaml:"global"`
|
|
||||||
Sites []SiteConfig `yaml:"sites"`
|
Sites []SiteConfig `yaml:"sites"`
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -37,12 +31,6 @@ func (c Error) Error() string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func validateConfig(config *Config) error {
|
func validateConfig(config *Config) error {
|
||||||
if config.Global.GithubPat == "" {
|
|
||||||
return &Error{Field: "global.github_pat", Message: "GitHub PAT is required"}
|
|
||||||
}
|
|
||||||
if config.Global.StoragePath == "" {
|
|
||||||
return &Error{Field: "global.storage_path", Message: "Storage path is required"}
|
|
||||||
}
|
|
||||||
for i, site := range config.Sites {
|
for i, site := range config.Sites {
|
||||||
if site.Name == "" {
|
if site.Name == "" {
|
||||||
return &Error{Field: "sites[" + string(i) + "].name", Message: "Name is required"}
|
return &Error{Field: "sites[" + string(i) + "].name", Message: "Name is required"}
|
||||||
|
|||||||
@@ -1,10 +1,14 @@
|
|||||||
package envconfig
|
package envconfig
|
||||||
|
|
||||||
import "os"
|
import (
|
||||||
|
"os"
|
||||||
|
)
|
||||||
|
|
||||||
type EnvConfig struct {
|
type EnvConfig struct {
|
||||||
Port string
|
Port string
|
||||||
ConfigDir string
|
ConfigDir string
|
||||||
|
GithubPat string
|
||||||
|
StoragePath string
|
||||||
}
|
}
|
||||||
|
|
||||||
func Load() EnvConfig {
|
func Load() EnvConfig {
|
||||||
@@ -18,8 +22,20 @@ func Load() EnvConfig {
|
|||||||
configDir = "./"
|
configDir = "./"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
githubPat := os.Getenv("GITHUB_PAT")
|
||||||
|
if githubPat == "" {
|
||||||
|
githubPat = ""
|
||||||
|
}
|
||||||
|
|
||||||
|
storagePath := os.Getenv("STORAGE_PATH")
|
||||||
|
if storagePath == "" {
|
||||||
|
storagePath = "./storage"
|
||||||
|
}
|
||||||
|
|
||||||
return EnvConfig{
|
return EnvConfig{
|
||||||
Port: port,
|
Port: port,
|
||||||
ConfigDir: configDir,
|
ConfigDir: configDir,
|
||||||
|
GithubPat: githubPat,
|
||||||
|
StoragePath: storagePath,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user