Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better go pipelines #1086

Merged
merged 7 commits into from
Mar 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 30 additions & 12 deletions pkg/build/pipelines/go/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,12 @@ inputs:

tags:
description: |
A comma-separated list of build tags to pass to the go compiler
A comma-separated list of build tags to append to the go compiler

toolchaintags:
description: |
A comma-separated list of default toolchain go build tags
default: "netgo,osusergo"

output:
description: |
Expand Down Expand Up @@ -53,7 +58,12 @@ inputs:

ldflags:
description:
List of [pattern=]arg to pass to the go compiler with -ldflags
List of [pattern=]arg to append to the go compiler with -ldflags

strip:
description:
Set of strip ldflags passed to the go compiler
default: "-s -w"

install-dir:
description: |
Expand All @@ -70,18 +80,26 @@ inputs:
when building the binary.
default: ""

amd64:
description: |
GOAMD64 microarchitecture level to use
default: "v2"

arm64:
description: |
GOARM64 microarchitecture level to use
default: "v8.0"

pipeline:
- runs: |
TAGS=""
LDFLAGS=""
LDFLAGS="${{inputs.strip}} ${{inputs.ldflags}}"

if [ ! "${{inputs.tags}}" == "" ]; then
TAGS="${{inputs.tags}}"
fi

if [ ! "${{inputs.ldflags}}" == "" ]; then
LDFLAGS="${{inputs.ldflags}}"
fi
# Make fips binaries have symbols table by default
case "${{inputs.go-package}}" in
*-fips*)
LDFLAGS="$(echo $LDFLAGS | sed 's/-s //g')"
;;
esac

BASE_PATH="${{inputs.prefix}}/${{inputs.install-dir}}/${{inputs.output}}"

Expand All @@ -104,4 +122,4 @@ pipeline:
[ -e /home/build/go.mod.local ] && cp /home/build/go.mod.local go.mod
[ -e /home/build/go.sum.local ] && cp /home/build/go.sum.local go.sum

GOEXPERIMENT="${{inputs.experiments}}" go build -o "${{targets.contextdir}}"/${BASE_PATH} -tags "${TAGS}" -ldflags "${LDFLAGS}" -trimpath ${{inputs.packages}}
GOAMD64="${{inputs.amd64}}" GOARM64="${{inputs.arm64}}" GOEXPERIMENT="${{inputs.experiments}}" go build -o "${{targets.contextdir}}"/${BASE_PATH} -tags "${{inputs.toolchaintags}},${{inputs.tags}}" -ldflags "${LDFLAGS}" -trimpath ${{inputs.packages}}
45 changes: 31 additions & 14 deletions pkg/build/pipelines/go/install.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,42 +35,59 @@ inputs:

ldflags:
description:
List of [pattern=]arg to pass to the go compiler with -ldflags
List of [pattern=]arg to append to the go compiler with -ldflags

strip:
description:
Set of strip ldflags passed to the go compiler
default: "-s -w"

tags:
description: |
A comma-separated list of build tags to pass to the go compiler
A comma-separated list of build tags to append to the go compiler

toolchaintags:
description: |
A comma-separated list of default toolchain go build tags
default: "netgo,osusergo"

experiments:
description: |
A comma-separated list of Golang experiment names (ex: loopvar) to use
when building the binary.
default: ""

amd64:
description: |
GOAMD64 microarchitecture level to use
default: "v2"

arm64:
description: |
GOARM64 microarchitecture level to use
default: "v8.0"

pipeline:
- runs: |
TAGS=""
LDFLAGS=""
LDFLAGS="${{inputs.strip}} ${{inputs.ldflags}}"
VERSION=""

# Make fips binaries have symbols table by default
case "${{inputs.go-package}}" in
*-fips*)
LDFLAGS="$(echo $LDFLAGS | sed 's/-s //g')"
;;
esac

# Installed binaries will be stored in a tmp dir
export GOBIN=$(mktemp -d)

if [ ! "${{inputs.tags}}" == "" ]; then
TAGS="${{inputs.tags}}"
fi

if [ ! "${{inputs.ldflags}}" == "" ]; then
LDFLAGS="${{inputs.ldflags}}"
fi

if [ ! "${{inputs.version}}" == "" ]; then
VERSION="@${{inputs.version}}"
fi


# Run go install
GOEXPERIMENT="${{inputs.experiments}}" go install ${DEST_PATH} -tags "${TAGS}" -ldflags "${LDFLAGS}" ${{inputs.package}}${VERSION}
GOAMD64="${{inputs.amd64}}" GOARM64="${{inputs.arm64}}" GOEXPERIMENT="${{inputs.experiments}}" go install ${DEST_PATH} -tags "${{inputs.toolchaintags}},${{inputs.tags}}" -ldflags "${LDFLAGS}" -trimpath ${{inputs.package}}${VERSION}
mkdir -p ${{targets.contextdir}}/${{inputs.prefix}}/${{inputs.install-dir}}

# Move all resulting files to the target dir
Expand Down
Loading