ko can also bundle static assets into the images it produces.
By convention, any contents of a directory named
<importpath>/kodata/ will be
bundled into the image, and the path where it's available in the image will be
identified by the environment variable
As an example, you can bundle and serve static contents in your image:
Then, in your
You can simulate
ko's behavior outside of the container image by setting the
KO_DATA_PATH environment variable yourself with
KO_DATA_PATH=cmd/app/kodata/ go run ./cmd/app.
💡 Tip: Symlinks in
kodataare followed and included as well. For example, you can include Git commit information in your image with
ln -s -r .git/HEAD ./cmd/app/kodata/
Also note that
http.FileServer will not serve the
If-Modified-Since request headers) because
ko does not embed
timestamps by default.
This can be supported by manually setting the
variable during build (See FAQ).