Crates.io | httpget |
lib.rs | httpget |
version | 0.1.22 |
source | src |
created_at | 2023-03-02 04:19:30.429388 |
updated_at | 2023-12-16 02:59:31.258786 |
description | A small, simple client to make http get requests and return a 0 status code if they succeed, 1 status code otherwise |
homepage | |
repository | https://github.com/taliamax/httpget |
max_upload_size | |
id | 798628 |
size | 5,109,484 |
This is a tiny client that sends an HTTP GET request to the parameter that you specify on the command line. This is statically compiled, so it is useful to toss into distroless or scratch containers that need to have an HTTP client for health check purposes.
This project came to be because a friend wanted to run health checks in a distroless container, and I wanted to make a binary that was as small as it could be. I did a writeup about that process, so if you want more information please read this blog post.
It's also becoming a bigger trend to use either distroless containers, or containers based on scratch
for security/image size reasons; this project allows a minimal dependency client that can only do GET requests, and has negligible footprint on container size.
Let's compare the binary size against other popular ones, specifically against wget
and curl
, measured from the binary & its dependencies in the alpine
container
Binary | Size |
---|---|
curl |
6.1mb |
wget |
1.4mb |
httpget , no TLS |
531kb |
httpget , with rustls |
1.2mb |
So, all in all, it's quite minimal.
Currently, only x86_64 binaries are released. If you are hoping to use this with ARM-based images, you will need to build them yourself.
Since this binary is primarily meant to be used for Docker health checks, the easiest way to consume this binary is through Docker. The binaries are published in the ghcr.io/cryptaliagy/httpget
repository in scratch containers, and you can use the version tags or latest
/latest-tls
.
Any released version tag includes an equivalent tls
tag. See below for an example Dockerfile, or see this project for an example usecase.
FROM golang:latest as build
# Build steps here
# (...)
# In the end we get a binary at /app/bin/example with our web service
FROM ghcr.io/cryptaliagy/httpget:latest as httpget
FROM scratch as runner
COPY --from=build /app/bin/example /example
COPY --from=httpget /httpget /httpget
HEALTHCHECK --interval=30s --timeout=30s --start-period=5s --retries=3 CMD ["/httpget", "http://localhost:8080/healthz"]
CMD ["/example"]
Another option is to put the httpget
image before the build stage and copy it into the output directory for the build stage, so your final image is only a single layer:
FROM ghcr.io/cryptaliagy/httpget:latest as httpget
FROM golang:latest as build
# Build steps here
# (...)
# In the end we get a binary at /app/bin/example with our web service
COPY --from=httpget /httpget /app/bin/httpget
FROM scratch as runner
COPY --from=build /app/bin /bin
HEALTHCHECK --interval=30s --timeout=30s --start-period=5s --retries=3 CMD ["/bin/httpget", "http://localhost:8080/healthz"]
CMD ["/bin/example"]
The regular binary and the TLS binary are available through Github Releases, and can be downloaded here. The httpget
binary can only use http://
protocol URLs, and the httpget-tls
can use either http://
or https://
.
This project is published on crates.io, and can be installed using cargo
with the command cargo install httpget
. This will not produce a statically-linked binary: for that, you must ensure that you've installed the correct *-unknown-linux-musl
target.
You can also clone this repository and run cargo install --path .
to install through Cargo