Local build for Golang
Some application deployments require an executable to be built outside of the Docker build process, and then copied into the conatiner image as a distinct build step.
To include local builds for Golang projects in Velocity, you'll need a Dockerfile that copies the locally compiled binary into the Docker image, and you'll need your local build command handy.
Your Dockerfile will need to include the following:
COPYcommand that targets the locally compiled binary
RUN apk --no-cache add ca-certificates
COPY ./app .
You'll need to select "No" in response to the question "Does your Dockerfile contain the applicaiton's build command."
Then, you'll need to enter an Application build command, like the one shown below along with an Executable path, as shown below.
The application build command for Go projects should include the following:
- The target OS (the cluster node OS)
- The target Architecture i.e. amd64 / arm64 (the cluster node Arch)
- Disable CGO
- The full path to the resulting binary from the root of your project
- The full path to the main module from the root of your project
-s) if they exist
CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -gcflags="all=-N -l" -o path/from/project/root/app ./path/from/project/root/main.go
The path to executable is the path within the container image to the compiled binary. Notice that the following example aligns with the Dockerfile example above -- i.e. the path to run the executable in the container is as follows: