Skip to content

Commit 3d565fd

Browse files
authored
Added healthcheck (#15)
* Update simple_http_server.go * Update Dockerfile
1 parent e107b71 commit 3d565fd

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

Dockerfile

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ COPY . .
1515
# Build the application
1616
RUN go build -o simple_http_server ./simple_http_server.go
1717

18+
1819
# Move to /dist directory as the place for resulting binary folder
1920
WORKDIR /dist
2021

@@ -24,6 +25,9 @@ RUN cp /build/simple_http_server .
2425
EXPOSE 8000
2526

2627
# Build a small image
27-
FROM scratch
28+
FROM alpine
29+
RUN apk update && apk add curl
2830
COPY --from=builder /dist/simple_http_server /
31+
32+
HEALTHCHECK --interval=5s --timeout=10s --retries=3 CMD curl -sS 127.0.0.1:8081/healthcheck || exit 1
2933
ENTRYPOINT ["/simple_http_server"]

simple_http_server.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
func main() {
1616
http.HandleFunc("/", handler)
1717
http.HandleFunc("/html/", htmlhandler)
18+
http.HandleFunc("/healthcheck", healthhandler)
1819
serverBrand := figure.NewColorFigure("Simple HTTP Server", "straight", "green", true)
1920
serverBrand.Print()
2021
myBrand := figure.NewColorFigure("by PareshPawar.com", "term", "green", true)
@@ -97,3 +98,7 @@ func handler(w http.ResponseWriter, r *http.Request) {
9798
fmt.Fprintf(w, " by PareshPawar.com \n")
9899
fmt.Fprintf(w, "----------------------------------------------------------\n")
99100
}
101+
102+
func healthhandler(w http.ResponseWriter, r *http.Request) {
103+
fmt.Fprintf(w, "OK\n")
104+
}

0 commit comments

Comments
 (0)