Go Build API

Montuer has a continuously developed build recipe dedicated for Go Programming Language to build its output.

The objective is simple: to build a Go app for a specific compute system in a consistent and reproducible manner.

All users has to do is to issue this command:

1
monteur build

For this recipe, they are arranged based on its own semantic versioning and is not directly related to Monteur's actual release version. Hence, feel free to explore and update each versions to suit your CI needs.

Resources

This recipe is built and maintained based on the following resources:

One Time Setup

To ensure maximum compatibility with the recipe, you might need to setup your build system with some of the Go specific one-time setup into your build system.

Cross Build

There is a very high chance that you will perform cross-build in your current build system. Unfortunately, Go has yet to completely support its internal linking feature for all its offering CPU architectures (See Issue 50405).

Hence, you need to at least make sure the correct crossbuild-essentials tools are readily available in your operating system. Here are some examples for installing cross-building essential tools for armhf and aarch64:

1
2
apt install crossbuild-essential-armhf
apt install crossbuild-essential-aarch64

Recipe File

Here are all the Monteur Build CI Job recipe files for operating Go semi-autonomously. They are sorted by the latest version first, at the top.

Please read through its requiremnets and changes before procuring.

Version v2.0.0

Download Link: go-v2p0p0.toml

Minimum Requirements

  • Montuer version: v0.0.2 and above.

  • Supported platform: STRICTLY depends on Go availability.

Installation Instructions

  • Download and place the recipe file into your .configs/montuer/build/jobs directory as [OS]-[ARCH].toml filename pattern like linux-amd64.toml.

  • Update the recipe's Metadata.Name to match the build summary name.

  • Update the recipe's Metadata.Description to accordingly especially replacing <APP>, <OS>, and <CPU> placeholders with their respective actual values.

  • Update the recipe's Variables.PlatformOS to match the target OS with the Go compatible value (e.g. linux).

  • Update the recipe's Variables.PlatformCPU to match the target CPU architecture with the Go compatible value (e.g. amd64 and NOT x86_64).

  • Update the recipe's Variables.PlatformExt to optionally match the OS compatible file extension like .exe for windows. Otherwise, leave it blank.

  • Update the recipe's Variables.BuildFlags to match your own Go build customizations.

  • Update the recipe's Variables.BuildConditions to match the build environments and conditions. The default includes everything sensible so please remove all non-applicable ones like CC=arm-linux-gnueabi-gcc for non-arm build. Please keep CGO_ENABLED=0 as minimum value to explictly instruct go not to use cgo at all.

  • Update the recipe's FMTVariables.SrcPath to match the directory location of your main package (containing main.go).

  • Update the recipe's [[Dependencies]] to have applicable dependencies like arm-linux-gnueabi-gcc for arm build.

Changelog

  • BACKWARD COMPATBILE - Added arm build with their specific dependencies and build conditions.

  • BACKWARD COMPATBILE - Added -trimpath and its other variants into Variables.BuildFlags.

  • BACKWARD COMPATBILE - Added Variables.BuildConditions to enable CGO and arm configurable settings.

  • BACKWARD COMPATBILE - Added CGO_ENABLED=0 to explictly instruct go to use cgo at will.

Version v1.0.0

Download Link: go-v1p0p0.toml

Minimum Requirements

  • Montuer version: v0.0.1.

  • Supported platform: STRICTLY depends on Go availability.

Installation Instructions

  • Download and place the recipe file into your .configs/app/variants/ directory as [OS]-[ARCH].toml filename pattern like linux-amd64.toml.

  • Update the recipe's Metadata.Name to match the build summary name.

  • Update the recipe's Metadata.Description accordingly especially replacing <APP>, <OS>, and <CPU> placeholders with their respective actual values.

  • Update the recipe's Variables.PlatformOS to match the target OS with the Go compatible value (e.g. linux).

  • Update the recipe's Variables.PlatformCPU to match the target CPU architecture with the Go compatible value (e.g. amd64 and NOT x86_64).

  • Update the recipe's Variables.PlatformExt to optionally match the OS compatible file extension like .exe for windows. Otherwise, leave it blank.

  • Update the recipe's Variables.BuildFlags to match your own Go build customizations.

  • Update the recipe's FMTVariables.SrcPath to match the directory location of your main package (containing main.go).

Changelog

  • BACKWARD COMPATBILE - Created the base TOML configuration recipe.

  • BACKWARD COMPATBILE - Tested with GitLab CI.

  • BACKWARD COMPATBILE - Using go with -buildmode=pie -ldflags "-s -w" as default arguments.

Epilogue

That's all for Monteur's Build CI Job handling Go building tasks. If you have any question, please feel free to raise your question at our Issues Section.