This Docker image is used to build Go service projects on the LUSHDigital infrastructure. It is not supposed to be used to run images in production, but rather to serve as a an intermediary image in staged docker builds to produce artefacts.
Since we don't need to have the entire Go toolchain in our production images, we can take the build artefacts from the first build stage and put them in another.
FROM lushdigital/alpine-golang:latest
FROM alpine:latest
# Copy from the first stage of the build process
COPY --from=0 /repo/build build
RUN ["build/service"]
The image will build your projects with -ldflags
setting two variables in your main package called tag
containing the very latest version tag of your tree and ref
containing the current git commit hash.
package main
var (
tag string
ref string
)
func main() {
...
}
This package will also use the build flags to interpolate the commit hash and latest version tag straight into the LUSHDigital/core package.
package main
import (
"github.com/LUSHDigital/core"
)
func main() {
// The service struct will now automatically contain the commit hash and latest version tag derived from the build flags.
service := core.NewService("example", "service")
...
}