Quick fixes
This commit is contained in:
15
Dockerfile
15
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"]
|
||||
|
||||
23
cmd/main.go
23
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() {
|
||||
|
||||
Reference in New Issue
Block a user