with cgo disabled

This commit is contained in:
Kasper Juul Hermansen 2022-10-31 02:02:00 +01:00
parent 217e9c5a4d
commit c4663856c4
Signed by: kjuulh
GPG Key ID: 0F95C140730F2F23
2 changed files with 9 additions and 1 deletions

View File

@ -34,6 +34,7 @@ func BuildGolangBin() *cobra.Command {
}, },
BuildPath: "main.go", BuildPath: "main.go",
BinName: "main", BinName: "main",
CGOEnabled: false,
ExecuteOnEntrypoint: false, ExecuteOnEntrypoint: false,
}). }).
Execute(ctx) Execute(ctx)

View File

@ -26,6 +26,7 @@ type GolangBinOpts struct {
BinName string BinName string
BaseImage string BaseImage string
ExecuteOnEntrypoint bool ExecuteOnEntrypoint bool
CGOEnabled bool
} }
func (p *Pipeline) WithGolangBin(opts *GolangBinOpts) *Pipeline { func (p *Pipeline) WithGolangBin(opts *GolangBinOpts) *Pipeline {
@ -54,6 +55,12 @@ func (p *Pipeline) WithGolangBin(opts *GolangBinOpts) *Pipeline {
} }
c = container.Workdir(c, "/src") c = container.Workdir(c, "/src")
if opts.CGOEnabled {
c = c.WithEnvVariable("CGO_ENABLED", "1")
} else {
c = c.WithEnvVariable("CGO_ENABLED", "0")
}
build, err = golang.Cache(ctx, client, c) build, err = golang.Cache(ctx, client, c)
if err != nil { if err != nil {
return err return err
@ -73,7 +80,7 @@ func (p *Pipeline) WithGolangBin(opts *GolangBinOpts) *Pipeline {
byg.Step{ byg.Step{
Execute: func(_ byg.Context) error { Execute: func(_ byg.Context) error {
if opts.BaseImage == "" { if opts.BaseImage == "" {
opts.BaseImage = "harbor.server.kjuulh.io/docker-proxy/library/golang" opts.BaseImage = "harbor.server.kjuulh.io/docker-proxy/library/alpine"
} }
binpath := "/usr/bin" binpath := "/usr/bin"