Local build for Golang
Include local builds for Golang projects in Velocity
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.
Prerequisites
To include local builds for Golang projects in Velocity, you'll need:
your local build command
a Dockerfile that copies the locally compiled binary into the Docker image
a
COPY
command inside the Dockerfile that targets the locally compiled binary, similar to the following:
Create a local build run configuration
For the relevant Velocity configuration, choose No in response to the question Does your Dockerfile contain the application's build command when creating the configuration via the Wizard. Alternatively, add the remote executable path via Edit Configurations...
Enter an Application build command, similar to the following example, along with an Executable path:
Application build command
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
Add
-gcflags="all=-N -l"
Remove
-ldflags="-w -s"
(only-w
and-s
) if they exist
Example:
Path to executable
The path to executable is the path to the compiled binary within the container image. For example, the path to run the executable in the container is as follows:
This example aligns with the Dockerfile example described in the Prerequisites above.
Last updated