Skip to content

Commit

Permalink
Added healthcheck (#15)
Browse files Browse the repository at this point in the history
* Update simple_http_server.go

* Update Dockerfile
  • Loading branch information
purvesh0110 authored Apr 16, 2024
1 parent e107b71 commit 3d565fd
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
6 changes: 5 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ COPY . .
# Build the application
RUN go build -o simple_http_server ./simple_http_server.go


# Move to /dist directory as the place for resulting binary folder
WORKDIR /dist

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

# Build a small image
FROM scratch
FROM alpine
RUN apk update && apk add curl
COPY --from=builder /dist/simple_http_server /

HEALTHCHECK --interval=5s --timeout=10s --retries=3 CMD curl -sS 127.0.0.1:8081/healthcheck || exit 1
ENTRYPOINT ["/simple_http_server"]
5 changes: 5 additions & 0 deletions simple_http_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
func main() {
http.HandleFunc("/", handler)
http.HandleFunc("/html/", htmlhandler)
http.HandleFunc("/healthcheck", healthhandler)
serverBrand := figure.NewColorFigure("Simple HTTP Server", "straight", "green", true)
serverBrand.Print()
myBrand := figure.NewColorFigure("by PareshPawar.com", "term", "green", true)
Expand Down Expand Up @@ -97,3 +98,7 @@ func handler(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, " by PareshPawar.com \n")
fmt.Fprintf(w, "----------------------------------------------------------\n")
}

func healthhandler(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "OK\n")
}

0 comments on commit 3d565fd

Please sign in to comment.