Sanic uses templaters to convert configuration templates defined in various languages into .yaml or .json files, ready to be processed by kubernetes
This specific one uses golang text templates
In general, you should choose the same template language as your webserver or configuration templater, to reduce developer cognitive overhead.
- Build this image:
docker build -t distributedcontainers/templater-golang .
- Run this image on the example files:
docker run --rm -v $(pwd)/example/in:/in:ro -v $(pwd)/example/out:/out:rw distributedcontainers/templater-golang
- Create some services in dockerfiles
- Create a deploy/in directory
- Add deploy/out to your gitignore (i.e., /deploy/out)
- Make some kubernetes deployment yamls in /deploy/in, with images set to
{{getenv "REGISTRY_HOST"}}/sanic-site:{{getenv "IMAGE_TAG"}}
, wheresanic-site
should be replaced with the name of your image - Run
sanic deploy
to build andkubectl apply
the templated resources.
Sanic furnishes your templater with the following variables:
SANIC_ENV
, the name of the environment you are currently inPROJECT_DIR
, the directory in which the projects' files are live mounted (only in development)- this is useful for live mounting your files using a kubernetes volume, see the example for details.
REGISTRY_HOST
, the registry for the current sanic environmentIMAGE_TAG
, the tag for the current state of the repository (i.e., if yousanic build
without specifying a tag, it will match up with this)