Skip to content

Healtch check functionality for Golang Docker images built from scratch.

License

Notifications You must be signed in to change notification settings

hibare/go-docker-healthcheck

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

go-docker-healthcheck

Go Report Card GitHub issues GitHub pull requests GitHub GitHub release (latest by date)

Healthcheck functionality for Golang Docker images built from scratch.

Original source: https://medium.com/google-cloud/dockerfile-go-healthchecks-k8s-9a87d5c5b4cb

This is useful to add healthcheck in Golang docker images created from scratch.

Note: This project is designed for docker containers (Linux) only.

Installation

Project provides an installation script.

curl -sfL https://raw.githubusercontent.com/hibare/go-docker-healthcheck/main/install.sh | sh -s -- -d -b /usr/local/bin

This will install healthcheck in /usr/local/bin

Verify signature

Installation script provides an way to verify checksum signature before running artifact checksum validation. This is an optional step in installation script.

To run signature verification during installation, supply additional -v argument.

curl -sfL https://raw.githubusercontent.com/hibare/go-docker-healthcheck/main/install.sh | sh -s -- -d -v -b /usr/local/bin

Usage Example

Fetch source code asset from Github release. Compile into a binary.


FROM golang:1.17.0-alpine AS base

# Build golang healthcheck binary

FROM base AS healthcheck

RUN curl -sfL https://raw.githubusercontent.com/hibare/go-docker-healthcheck/main/install.sh | sh -s -- -d -b /usr/local/bin

Copy binary into final stage.


COPY --from=healthcheck /usr/local/bin/healthcheck /bin/healthcheck

Add healthcheck command to docker. Replace the URL in healthcheck with actual application healthcheck URL.


HEALTHCHECK \
 --interval=30s \
 --timeout=3s \
 CMD ["healthcheck", "--url", "http://localhost:5000/ping/"]

Example

A working example can be found here.