This is a Dockerfile for an image including primarily Go and Watchman. It is sometimes updated to the latest available Go and Watchman versions.
The main reason to use this Dockerfile would be to automatically rebuild and run your application on save.
Some other information may be viewed on docker hub.
The simplest form is:
version: '3'
services:
app:
image: eyesore/go:1.16.6
volumes:
- ./:/app
The default entrypoint watches all .go files with Watchman. Whenever a change is detected:
go get
will attempt to import any new dependencies (into the container)go build
will attempt to compile your project- Compile failure will display errors in the log, but your previous successful build will continue to run if persistent.
- If the build succeeds, previous instances will be killed and the new version will run.
If invoking/running your application is not as simple as /go/bin/app
, fret not. There is an environment variable for you: $GWD_CMD
If set, this will be appended to the run command:
docker run --rm -ti -v $(PWD):/app -e GWD_CMD='start service --with options'
This will result in the your application being started with as /go/bin/app start service --with options
If you need still more control, you also have access to the trigger options accepted by Watchman.
By creating a JSON file containing a valid trigger object, you can set all available properties and they will be passed to the invocation of trigger by the default entrypoint. Make the the JSON file containing this configuration available to the container either by mounting it in a volume, or including it in your mounted application (at /app), and set the environment variable GWD_CMD_FILE
with the full path to the file.
The defaults are:
{
"name": "build-and-run",
"append_files": false,
"command": ["/usr/local/bin/build-and-run.sh", "${GWD_CMD}"],
"expression": ["match", "**/*.go", "wholename"]
}
Including a .watchmanconfig
in the root of your project will also be used:
Valid configurations defined by Watchman.
The container also packs a minimal (and not configurable) deployment entrypoint. This will build your application into a binary named app
in a mounted dist folder. It will also copy any supporting resources found in a mounted dist-include
folder. For example:
docker run --rm -ti --entrypoint /usr/local/bin/build-for-deploy.sh \
-v $(pwd):/dist \
-v $(pwd)/dist-include \
-v $(pwd):/app \
eyesore/go
Or in something like docker-compose.deploy.yml
:
version: '3'
services:
app:
entrypoint:
- /usr/local/bin/build-for-deploy.sh
volumes:
- goBuild:/dist
- ./dist-include:/dist-include