Skip to content

Commit

Permalink
[YUNIKORN-2486] Web: Use Docker to build reproducible binaries (#179)
Browse files Browse the repository at this point in the history
Introduces a build var (REPRODUCIBLE_BUILDS=1) to force building
binaries using Docker. This results in builds with a consistent
environment every time.

Closes: #179
  • Loading branch information
craigcondit committed Mar 15, 2024
1 parent 1b147a4 commit 8c2b795
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ yarn-error.log
.classpath
.c9/
*.launch
*.swp
.settings/
*.sublime-workspace

Expand Down
1 change: 1 addition & 0 deletions .go_repro_version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1.21.8
17 changes: 17 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,14 @@ ifeq ($(REGISTRY),)
REGISTRY := apache
endif

# Reproducible builds mode
GO_REPRO_VERSION := $(shell cat .go_repro_version)
ifeq ($(REPRODUCIBLE_BUILDS),1)
REPRO := 1
else
REPRO :=
endif

# Set the default web port
PORT=9889

Expand Down Expand Up @@ -233,11 +241,20 @@ build_server_prod: $(RELEASE_BIN_DIR)/$(SERVER_BINARY)
$(RELEASE_BIN_DIR)/$(SERVER_BINARY): go.mod go.sum $(shell find pkg)
@echo "building web server binary"
@mkdir -p ${RELEASE_BIN_DIR}
ifeq ($(REPRO),1)
docker run -t --rm=true --volume "$(BASE_DIR):/buildroot" "golang:$(GO_REPRO_VERSION)" sh -c "cd /buildroot && \
CGO_ENABLED=0 GOOS=linux GOARCH=\"${EXEC_ARCH}\" \
go build -a -o=${RELEASE_BIN_DIR}/${SERVER_BINARY} -trimpath -ldflags \
'-buildid= -extldflags \"-static\" -X main.version=${VERSION} -X main.date=${DATE}' \
-tags netgo -installsuffix netgo \
./pkg/cmd/web/"
else
CGO_ENABLED=0 GOOS=linux GOARCH="${EXEC_ARCH}" \
"$(GO)" build -a -o=${RELEASE_BIN_DIR}/${SERVER_BINARY} -trimpath -ldflags \
'-buildid= -extldflags "-static" -X main.version=${VERSION} -X main.date=${DATE}' \
-tags netgo -installsuffix netgo \
./pkg/cmd/web/
endif

# Run the web interface from the production image
.PHONY: run
Expand Down

0 comments on commit 8c2b795

Please sign in to comment.