A really small static web server for Docker
Find a file
Dj Walker-Morgan 6ca38384a8 typo fixes
2020-09-10 12:49:06 +01:00
.gitignore chore: removing binary 2017-11-14 00:21:37 +01:00
.travis.yml feat: travis build 2017-11-14 00:23:49 +01:00
auth.go fix #9: right header to force authenticate 2017-11-18 16:39:24 +01:00
Dockerfile Added -https-promote switch 2020-09-08 14:52:18 +01:00
Dockerfile.arm5 Add dockerfile for arm5, 6, 7 and arm64 2020-07-22 12:28:04 -07:00
Dockerfile.arm6 Add dockerfile for arm5, 6, 7 and arm64 2020-07-22 12:28:04 -07:00
Dockerfile.arm7 Add dockerfile for arm5, 6, 7 and arm64 2020-07-22 12:28:04 -07:00
Dockerfile.arm64 Add dockerfile for arm5, 6, 7 and arm64 2020-07-22 12:28:04 -07:00
fallback.go feat: recursive fallback resolution 2019-10-15 23:02:26 +10:00
LICENSE Initial commit 2015-07-16 20:55:23 +02:00
main.go Added -https-promote switch 2020-09-08 14:52:18 +01:00
README.md typo fixes 2020-09-10 12:49:06 +01:00

goStatic Docker Pulls Docker Build Build Status GoDoc

A really small static web server for Docker

The goal

My goal is to create to smallest docker container for my web static files. The advantage of Go is that you can generate a fully static binary, so that you don't need anything else.

Wait, I've been using old versions of GoStatic and things have changed!

Yeah, decided to drop support of unsecured HTTPS. Two-years ago, when I started GoStatic, there was no automatic HTTPS available. Nowadays, thanks to Let's Encrypt, it's really easy to do so. If you need HTTPS, I recommend caddy.

Features

  • A fully static web server in 6MB
  • No framework
  • Web server built for Docker
  • Can generate the certificate on its own
  • Light container
  • More secure than official images (see below)
  • Log enabled

Why?

Because the official Golang image is wayyyy too big (around 1/2Gb as you can see below) and could be insecure.

For me, the whole point of containers is to have a light container... Many links should provide you with additional info to see my point of view:

How to use

docker run -d -p 80:8043 -v path/to/website:/srv/http --name goStatic pierrezemb/gostatic

Usage

./goStatic --help
Usage of /goStatic:
  -append-header HeaderName:Value
        HTTP response header, specified as HeaderName:Value that should be added to all responses.
  -context string
        The 'context' path on which files are served, e.g. 'doc' will serve the files at 'http://localhost:<port>/doc/'
  -default-user-basic-auth string
        Define the user (default "gopher")
  -enable-basic-auth
        Enable basic auth. By default, password are randomly generated. Use --set-basic-auth to set it.
  -enable-health
        Enable health check endpoint. You can call /health to get a 200 response. Useful for Kubernetes, OpenFaas, etc.
  -fallback string
        Default fallback file. Either absolute for a specific asset (/index.html), or relative to recursively resolve (index.html).
  -password-length int
        Size of the randomized password (default 16)
  -path string
        The path for the static files (default "/srv/http")
  -port int
        The listening port (default 8043)
  -set-basic-auth string
        Define the basic auth. Form must be user:password
  -https-promote
        Connections to http: are redirected to https:
  -enable-logging
        Writes a simple log entry for requests to the server

Fallback

The fallback option is principally useful for single-page applications (SPAs) where the browser may request a file, but where part of the path is in fact an internal route in the application, not a file on disk. goStatic supports two possible usages of this option:

  1. Using an absolute path so that all not found requests resolve to the same file
  2. Using a relative file, which searches up the tree for the specified file

The second case is useful if you have multiple SPAs within the one filesystem. e.g., / and /admin.