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

Build manager binary in a modular way #145

Merged
merged 1 commit into from
Sep 25, 2024
Merged
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
30 changes: 22 additions & 8 deletions hack/build.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
#!/bin/bash
set -ex

#!/bin/bash -ex
DEST_DIR=$1

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure why it is used here. Other operators create in bin directory (we already create it in https://github.com/medik8s/machine-deletion-remediation/pull/145/files#diff-3d78da75ea6dd0aa86fac99d385c70af27002c3d2cc205934432150e2f2ccf9cR10),
Any thoughts? @clobrano

Copy link
Contributor

@clobrano clobrano Sep 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The makefile builds the binary under bin/ directory, but the Dockerfiles have the binary built directly in the root

https://github.com/clobrano/machine-deletion-remediation/blob/2632f1609758846a91614ebe88fe3696ae64fa2d/Makefile#L189-L190

https://github.com/clobrano/machine-deletion-remediation/blob/2632f1609758846a91614ebe88fe3696ae64fa2d/Dockerfile#L36-L37

I don't really remember why, but it is on purpose

GIT_VERSION=$(git describe --always --tags || true)
Expand All @@ -11,8 +9,24 @@ BUILD_DATE=$(date --utc -Iseconds)

mkdir -p bin

LDFLAGS="-s -w "
LDFLAGS+="-X github.com/medik8s/machine-deletion-remediation/version.Version=${VERSION} "
LDFLAGS+="-X github.com/medik8s/machine-deletion-remediation/version.GitCommit=${COMMIT} "
LDFLAGS+="-X github.com/medik8s/machine-deletion-remediation/version.BuildDate=${BUILD_DATE} "
GOFLAGS=-mod=vendor CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags="${LDFLAGS}" -o "${DEST_DIR}"/manager main.go
LDFLAGS_VALUE="-X github.com/medik8s/machine-deletion-remediation/version.Version=${VERSION} "
LDFLAGS_VALUE+="-X github.com/medik8s/machine-deletion-remediation/version.GitCommit=${COMMIT} "
LDFLAGS_VALUE+="-X github.com/medik8s/machine-deletion-remediation/version.BuildDate=${BUILD_DATE} "
# allow override for debugging flags
LDFLAGS_DEBUG="${LDFLAGS_DEBUG:-" -s -w"}"
LDFLAGS_VALUE+="${LDFLAGS_DEBUG}"
# must be single quoted for use in GOFLAGS, and for more options see https://pkg.go.dev/cmd/link
LDFLAGS="'-ldflags=${LDFLAGS_VALUE}'"

# add ldflags to goflags
export GOFLAGS+=" ${LDFLAGS}"
echo "goflags: ${GOFLAGS}"

# allow override and use zero by default- static linking
export CGO_ENABLED=${CGO_ENABLED:-0}
echo "cgo: ${CGO_ENABLED}"

# export in case it was set
export GOEXPERIMENT="${GOEXPERIMENT}"

GOOS=linux GOARCH=amd64 go build -o "${DEST_DIR}"/manager main.go
Loading