szabodanika / microbin

A secure, configurable file-sharing and URL shortening web app written in Rust.
https://microbin.eu
BSD 3-Clause "New" or "Revised" License
2.71k stars 172 forks source link

Add way to healthcheck the docker image #240

Open CodaBool opened 1 year ago

CodaBool commented 1 year ago

Docker images use tools inside the image to perform healthchecks.

Healthchecks are a nice feature to support since cloud hosting (AWS ECS) and selfhostings (myself with lazydocker) commonly use this feature to determine if the service is healthy from internal reporting.

Since curl and wget are not present I tried to use nc which also was also not present. I think one of these three CLI tools should be built into the image to allow for healthchecking on port 8080.

Wget is a lighter choice over curl at 2.5Mb but not compared to netcat. However, chatgpt suggested it would be more secure

chatgpt (chatgpt generally scores really well on networking / sys admin tests, so I'm using it as a source.)

image

If size is the concern then nc seems the lightest (66Kb)

Here is how a healthcheck would be done with each of those CLI tools:

Once one of those is able to pass you can add them to a docker compose yaml file like below:

example using wget

version: "3.9"
services:
microbin:
container_name: microbin
image: danielszabo99/microbin
restart: unless-stopped
ports:
- 8080:8080
volumes:
- ./data:/app/microbin_data
healthcheck:
test: wget --no-verbose --tries=1 --spider http://localhost:8080 || exit 1
environment:
MICROBIN_ADMIN_USERNAME=
MICROBIN_ADMIN_PASSWORD=
MICROBIN_PUBLIC_PATH=https://
CodaBool commented 1 year ago

just realized the usernames don't match. You don't manage this docker image danielszabo99/microbin do you? :face_exhaling:

nvm looks like you are Dániel Szabó. Good to know this is the right place.