Added Dockerfile

This commit is contained in:
Robin Dittmar
2026-07-03 10:30:33 +02:00
parent 4afb76cea0
commit d98e8e9244
3 changed files with 24 additions and 16 deletions
+20
View File
@@ -0,0 +1,20 @@
FROM golang:1.26 AS build
WORKDIR /app
#COPY go.mod go.sum ./
COPY go.mod ./
RUN go mod download
COPY . .
RUN go build -o ./server github.com/robindittmar/dttmr-api/cmd/api-server
FROM debian:latest
WORKDIR /app
COPY --from=build /app/server /app/server
EXPOSE 8080
CMD ["/app/server"]
+4 -16
View File
@@ -45,13 +45,7 @@ func main() {
log.Print(err)
}
b, err := json.Marshal(resp)
if err != nil {
log.Println(err)
return
}
_, err = w.Write(b)
err := json.NewEncoder(w).Encode(resp)
if err != nil {
log.Println(err)
return
@@ -61,19 +55,13 @@ func main() {
http.HandleFunc("/health", func(w http.ResponseWriter, r *http.Request) {
resp := HealthResponse{Status: "ok"}
b, err := json.Marshal(&resp)
if err != nil {
log.Println(err)
return
}
_, err = w.Write(b)
err := json.NewEncoder(w).Encode(resp)
if err != nil {
log.Println(err)
return
}
})
fmt.Println("Listening on localhost:8080")
log.Fatal(http.ListenAndServe("localhost:8080", nil))
fmt.Println("Listening on port 8080")
log.Fatal(http.ListenAndServe(":8080", nil))
}
View File