srv is a small Go application to server static files over HTTP
MIT License
srv is a small Go application to use as a container or as a base Docker image in other projects to serve static files over HTTP
amd64
, 386
, arm64
, arm32v7
, arm32v6
, ppc64le
, s390x
and riscv64
CPU architectures1000
scratch
docker image for a tiny size of 9.11MB (uncompressed amd64 image):9091
We assume your static files are at /yourpath
on your host.
Ensure the ownership of your static files matches the ones from the container:
chown -R 1000 /yourpath
Run the container, bind mounting /yourpath
to /srv
as ready only:
docker run -d -p 8000:8000/tcp -v /yourpath:/srv:ro qmcgaw/srv
You can also use docker-compose.yml with:
docker-compose up -d
You can update the image with docker pull qmcgaw/srv
or use one of the tags available
You can use it in your own project with:
FROM qmcgaw/srv
COPY --chown=1000 srv /srv
Or with a multi stage Dockerfile:
FROM someimage AS staticbuilder
COPY . .
RUN somecompiler --output-to=/tmp/build
FROM qmcgaw/srv
COPY --from=staticbuilder --chown=1000 /tmp/build /srv
Environment variable | Default | Possible values | Description |
---|---|---|---|
HTTP_SERVER_ADDRESS |
:8000 |
Valid address | HTTP server listening address |
HTTP_SERVER_ROOT_URL |
/ |
URL path | HTTP server root URL |
HTTP_SERVER_LOG_REQUESTS |
on |
on or off
|
Log requests and responses information |
FILEPATH_SRV |
/srv |
Valid file path | File path to your static files directory |
METRICS_SERVER_ADDRESS |
:9090 |
Valid address | Prometheus HTTP server listening address |
LOG_LEVEL |
info |
debug , info , warning , error
|
Logging level |
HEALTH_SERVER_ADDRESS |
127.0.0.1:9999 |
Valid address | Health server listening address |
TZ |
America/Montreal |
string | Timezone |
Setup your environment
F1
and select Remote-Containers: Open Folder in Container...
Install Go dependencies with
go mod download
Install golangci-lint
You might want to use an editor such as Visual Studio Code with the Go extension. Working settings are already in .vscode/settings.json.
Commands available:
# Build the binary
go build cmd/app/main.go
# Test the code
go test ./...
# Lint the code
golangci-lint run
# Build the Docker image
docker build -t qmcgaw/srv .
See Contributing for more information on how to contribute to this repository.
This repository is under an MIT license unless otherwise indicated