From 904d26178f381135dad931b47e17a4be47e80c7d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lauri=20V=C3=B5sandi?= Date: Mon, 16 Feb 2026 09:24:32 +0200 Subject: [PATCH] Quick fixes --- Dockerfile | 15 ++++++++++----- cmd/main.go | 23 +++++++++++++++++++++-- 2 files changed, 31 insertions(+), 7 deletions(-) diff --git a/Dockerfile b/Dockerfile index 21e0dd4..7ca3cdf 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,12 +1,17 @@ -FROM golang:1.24 AS build -WORKDIR /go/src/github.com/codemowers/hello-gin/ +FROM golang:1.23-alpine AS build +WORKDIR /app COPY go.mod go.sum ./ RUN go mod download -COPY cmd ./ -RUN go build -tags netgo -ldflags "-linkmode 'external' -extldflags '-static'" -o /go/server . +COPY cmd ./cmd/ +COPY templates ./templates/ +COPY static ./static/ +RUN CGO_ENABLED=0 go build -ldflags="-s -w" -o /app/server ./cmd FROM scratch WORKDIR / -COPY --from=build /go/server /server +COPY --from=build /app/server /server +COPY --from=build /app/templates /templates +COPY --from=build /app/static /static ENV GIN_MODE=release +EXPOSE 8000 8080 ENTRYPOINT ["/server"] diff --git a/cmd/main.go b/cmd/main.go index f3b2c2d..7bf3836 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -9,14 +9,33 @@ import ( func main() { router := gin.Default() + + // Load HTML templates + router.LoadHTMLGlob("templates/*") + + // Serve static files (for CSS, JS, etc.) + router.Static("/static", "./static") + metricRouter := gin.Default() metrics := ginmetrics.GetMonitor() metrics.SetMetricPath("/metrics") - metrics.Use(router) + metrics.UseWithoutExposingEndpoint(router) metrics.Expose(metricRouter) router.GET("/", func(c *gin.Context) { - c.String(http.StatusOK, "Hello " + os.Getenv("USERNAME") + " from " + os.Getenv("MY_POD_NAME")) + // Get environment variables + username := "suvakelbas" + + + podName := os.Getenv("MY_POD_NAME") + if podName == "" { + podName = "Unknown Pod" + } + + c.HTML(http.StatusOK, "index.html", gin.H{ + "username": username, + "podName": podName, + }) }) go func() {