srv

srv is a small Go application to server static files over HTTP

MIT License

Stars
4

SRV

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

Features

  • Compatible with amd64, 386, arm64, arm32v7, arm32v6, ppc64le, s390x and riscv64 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

Setup

As a container

We assume your static files are at /yourpath on your host.

  1. Ensure the ownership of your static files matches the ones from the container:

    chown -R 1000 /yourpath
    
  2. 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
    
  3. You can update the image with docker pull qmcgaw/srv or use one of the tags available

As a base image

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 variables

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

Development

  1. Setup your environment

    1. 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
    2. With Visual Studio Code, install the remote containers extension
    3. In Visual Studio Code, press on F1 and select Remote-Containers: Open Folder in Container...
    4. Your dev environment is ready to go!... and it's running in a container 👍 So you can discard it and update it easily!
    1. Install Go, Docker and Git

    2. Install Go dependencies with

      go mod download
      
    3. Install golangci-lint

    4. You might want to use an editor such as Visual Studio Code with the Go extension. Working settings are already in .vscode/settings.json.

  2. 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 .
    
  3. See Contributing for more information on how to contribute to this repository.

License

This repository is under an MIT license unless otherwise indicated