go1.20+: Refuse to work if cgo is enabled

On go1.20+ it is no longer possible to directly copy a cgo-enabled
library into a docker container. For this reason, this commit adds a
flag to commands that automatically make them fail with an appropriate
message if cgo is enabled.
This commit is contained in:
Tom 2023-04-27 11:13:47 +02:00
parent 5e9795ad0c
commit 6362b2887b
9 changed files with 30 additions and 10 deletions

View file

@ -12,6 +12,7 @@ import (
"github.com/rs/zerolog"
"github.com/tkw1536/goprogram"
"github.com/tkw1536/goprogram/exit"
"github.com/tkw1536/pkglib/cgo"
)
// these define the ggman-specific program types
@ -59,12 +60,7 @@ var errUserIsNotRoot = exit.Error{
Message: "this command has to be executed as root. the current user is not root",
}
// an error when cgo is enabled
var errCGoEnabled = exit.Error{
ExitCode: exit.ExitGeneralArguments,
Message: "this command has to be executed as root. the current user is not root",
}
const warnCGoEnabled = "Warning: This executable has been built with cgo enabled. This means certain commands may not work. \n"
const warnNoDeployWdcli = "Warning: Not using %q executable at %q. This might leave the distillery in an inconsistent state. \n"
func NewProgram() Program {
@ -76,6 +72,11 @@ func NewProgram() Program {
return errUserIsNotRoot
}
// warn about cgo!
if cgo.Enabled {
context.Printf(warnCGoEnabled)
}
// when not running inside docker and we need a distillery
// then we should warn if we are not using the distillery executable.
if dis := context.Environment; !context.Args.Flags.InternalInDocker && context.Description.Requirements.NeedsDistillery && !dis.Config.Paths.UsingDistilleryExecutable() {