Use this repository in your Makefile by including it:
BINARY := metal-api
MAINMODULE := <your package>
COMMONDIR := $(or ${COMMONDIR},../../common)
include $(COMMONDIR)/Makefile.inc
release:: all ;You have to:
- specify the
BINARYname. This will be the generated binary, it will be placed in thebinfolder. - specify the
MAINMODULEpath. This path should point to the folder of yourmain.go - specify the
COMMONDIRis the directory where this repository is located. you MUST evaluate if there is an environment variableCOMMONDIRand use this one, so that our CI server and multistage builds can set this path to another location than on your local pc. - overwrite the
releasetarget (note the two colons after the target name). Normally you should set this to theallwhich compiles your go code. But sometimes you want to do something before compiling (generate code, etc.).
Now you can simply make to build a binary
You can use the image as a base builder image in your own Dockerfile:
FROM metalstack/builder:latest as builderThis base image wants you to have a go.mod and a Makefile where the default target
creates the binary. This binary will be located in the path /work/bin/....