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
- Compatible with
amd64
,386
,arm64
,arm32v7
,arm32v6
,ppc64le
,s390x
andriscv64
CPU architectures - Runs without root as user ID
1000
- Based on the
scratch
docker image for a tiny size of 9.11MB (uncompressed amd64 image) - Docker image tags and sizes
- Prometheus metrics available on
: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
Using VSCode and Docker (easier)
- Install Docker
- On Windows, share a drive with Docker Desktop and have the project on that partition
- On OSX, share your project directory with Docker Desktop
- With Visual Studio Code, install the remote containers extension
- In Visual Studio Code, press on
F1
and selectRemote-Containers: Open Folder in Container...
- Your dev environment is ready to go!... and it's running in a container 👍 So you can discard it and update it easily!
Locally
-
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.
- Install Docker
-
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