Dockerize app

This commit is contained in:
2026-03-30 21:35:37 +02:00
parent e81286b394
commit b6f831631f
5 changed files with 70 additions and 5 deletions
+4 -2
View File
@@ -1,3 +1,5 @@
.env .env
config.yaml config/config.yaml
mydeploys mydeploys
quay
config
+33
View File
@@ -0,0 +1,33 @@
FROM golang:1.25-alpine AS builder
WORKDIR /app
RUN apk add --no-cache build-base libwebp-dev
COPY go.mod go.sum ./
RUN go mod download
COPY . .
RUN go build -tags "fts5" -o quay
FROM alpine:3.19
WORKDIR /app
RUN apk add --no-cache libwebp libstdc++
RUN adduser -D -g '' appuser
COPY --from=builder /app/quay .
RUN chown -R appuser:appuser /app
USER appuser
ENV PORT=4321
ENV CONFIG_DIR=/config
EXPOSE 4321
CMD ["./quay"]
+21
View File
@@ -0,0 +1,21 @@
services:
quay:
build:
context: .
dockerfile: Dockerfile
container_name: quay
env_file:
- .env
ports:
- '8080:4321'
volumes:
- ./config:/config
- ./mydeploys:/deploys
restart: unless-stopped
healthcheck:
test:
['CMD', 'wget', '--no-verbose', '--tries=1', '--spider', 'http://localhost/health']
interval: 30s
timeout: 10s
retries: 3
start_period: 40s
+9 -2
View File
@@ -3,7 +3,8 @@ package envconfig
import "os" import "os"
type EnvConfig struct { type EnvConfig struct {
Port string Port string
ConfigDir string
} }
func Load() EnvConfig { func Load() EnvConfig {
@@ -12,7 +13,13 @@ func Load() EnvConfig {
port = "4321" port = "4321"
} }
configDir := os.Getenv("CONFIG_DIR")
if configDir == "" {
configDir = "./"
}
return EnvConfig{ return EnvConfig{
Port: port, Port: port,
ConfigDir: configDir,
} }
} }
+3 -1
View File
@@ -2,6 +2,7 @@ package main
import ( import (
"log" "log"
"path/filepath"
"quay/app/routes" "quay/app/routes"
"quay/internal/config" "quay/internal/config"
"quay/internal/envconfig" "quay/internal/envconfig"
@@ -16,7 +17,8 @@ func main() {
envCfg := envconfig.Load() envCfg := envconfig.Load()
cfg, err := config.Load("config.yaml") configFilePath := filepath.Join(envCfg.ConfigDir, "config.yaml")
cfg, err := config.Load(configFilePath)
if err != nil { if err != nil {
panic("Failed to load config: " + err.Error()) panic("Failed to load config: " + err.Error())
} }