diff --git a/.gitignore b/.gitignore index ca1caee..59bd15c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ .env -config.yaml -mydeploys \ No newline at end of file +config/config.yaml +mydeploys +quay +config \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..3a5da3f --- /dev/null +++ b/Dockerfile @@ -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"] \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..2cd8f8c --- /dev/null +++ b/docker-compose.yml @@ -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 \ No newline at end of file diff --git a/internal/envconfig/envconfig.go b/internal/envconfig/envconfig.go index 8dd700b..f4a66fc 100644 --- a/internal/envconfig/envconfig.go +++ b/internal/envconfig/envconfig.go @@ -3,7 +3,8 @@ package envconfig import "os" type EnvConfig struct { - Port string + Port string + ConfigDir string } func Load() EnvConfig { @@ -12,7 +13,13 @@ func Load() EnvConfig { port = "4321" } + configDir := os.Getenv("CONFIG_DIR") + if configDir == "" { + configDir = "./" + } + return EnvConfig{ - Port: port, + Port: port, + ConfigDir: configDir, } } diff --git a/main.go b/main.go index 35caf96..0542b61 100644 --- a/main.go +++ b/main.go @@ -2,6 +2,7 @@ package main import ( "log" + "path/filepath" "quay/app/routes" "quay/internal/config" "quay/internal/envconfig" @@ -16,7 +17,8 @@ func main() { envCfg := envconfig.Load() - cfg, err := config.Load("config.yaml") + configFilePath := filepath.Join(envCfg.ConfigDir, "config.yaml") + cfg, err := config.Load(configFilePath) if err != nil { panic("Failed to load config: " + err.Error()) }