GO
Build a Sample Go Application:-
- Clone the SecurePacks samples repository and navigate to a Go sample app:
git clone https://github.com/initializ-buildpacks/Securepack/samples
- Use the pack CLI with the SecurePacks Go Buildpack to build the sample app:
pack build my-app --buildpack initializbuildpacks/go --builder initializbuildpacks/securepacks-initzbuilder
- Follow the instructions in the app's README to run the app.
docker run --interactive --tty --env PORT=8080 --publish 8080:8080 my-app
Override the Detected Go Version:-
You can override the detected Go version by setting the BP_GO_VERSION environment variable at build time
- With pack and a Command-Line Flag:
pack build my-app --buildpack initializbuildpacks/go --env BP_GO_VERSION="1.14.1"
- With pack and a project.toml file:
project.toml
[ _ ]
schema-version = "0.2
[[ io. .build.env ]]
name="BP_GO_VERSION"
value="1.14.1
-
Configure the go build Command You can configure the go-build command with certain flags by default.
-
Configure the
go buildCommand:
- Set
-ldflagsforgo build: When building, use the--envflag to setBP_GO_BUILD_LDFLAGS. For example, if you want to add-ldflags="-X main.variable=some-value"to the build flagset, set the environment variable accordingly:
pack build my-app --buildpack initializbuildpacks/go --env BP_GO_BUILD_LDFLAGS="-X main.variable=some-value"
Enable Process Reloading:-
Your Go binary is typically the only process running in your app container. If you want to restart the binary process when files in your app's working directory change, you can enable this feature. It can help you quickly see the effects of code changes. You can use this feature alongside a development orchestrator like Tilt.
Using BP_LIVE_RELOAD_ENABLED
To enable reloadable processes, set the $BP_LIVE_RELOAD_ENABLED environment variable during the build process.
pack build myapp --env BP_LIVE_RELOAD_ENABLED=true
Install a Custom CA Certificate
If you're using the Go buildpack, you can include your own CA certificates in the container root truststore at build-time and runtime. Follow the instructions in the CA Certificates section of the configuration docs.
Override the Start Process Set by the Buildpack
You can set custom start processes for your app image if you're using the Go buildpack. Follow the instructions in the Procfiles section of the configuration docs.
Set Environment Variables for App Launch Time
Embed launch-time environment variables in your app image if you're using the Go buildpack. Refer to the documentation for the Environment Variables Buildpack.
Add Custom Labels to the App Image:-
You can add labels to your app image if you're using the Go buildpack. Follow the instructions in the Applying Custom Labels section of the configuration docs.
Extract Go Module Information From A Build
The Go buildpack generates a software bill of materials (SBOM) for the dependencies installed in the app image during a build. You can extract information about the Go modules used in the build using the build-time SBOM.
With pack and a Command-Line Flag . When using the pack CLI, use the flag --sbom-output-dir to extract SBOMs from the build:
pack build my-app --buildpack initializbuildpacks/go --sbom-output-dir /tmp/sbom-output
To view the Go modules used in the build, inspect one of the SBOMs generated by the Go Mod Vendor buildpack. For instance, to view the SBOM as CycloneDX JSON.
cat /tmp/sbom-output/sbom.cyclonedx.json
Enable DEBUG logging
If you're using the Go buildpack, you can access extra debug logs during the image build process by setting the BP_LOG_LEVEL environment variable to DEBUG during the build:
pack build my-app --buildpack initializbuildpacks/go --env BP_LOG_LEVEL=DEBUG