From 902fd128a277a53e169ab1d68aced83177f5ef1a Mon Sep 17 00:00:00 2001 From: Angel Montero Date: Tue, 14 Jan 2025 00:37:29 -0500 Subject: [PATCH 1/4] Use docker image to build binary for different platforms --- Makefile | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index e7615ddc134..32d76572d9d 100644 --- a/Makefile +++ b/Makefile @@ -11,6 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. +GOVERSION ?= 1.23.4 GOPATH ?= $(shell go env GOPATH) GOBIN ?= $(or $(shell go env GOBIN),$(GOPATH)/bin) GOOS ?= $(shell go env GOOS) @@ -93,12 +94,33 @@ install: $(BUILD_DIR)/$(PROJECT) .PHONY: cross cross: $(foreach platform, $(SUPPORTED_PLATFORMS), $(BUILD_DIR)/$(PROJECT)-$(platform)) -$(BUILD_DIR)/$(PROJECT)-%: $(EMBEDDED_FILES_CHECK) $(GO_FILES) $(BUILD_DIR) +.PHONY $(BUILD_DIR)/$(PROJECT)-%: +$(BUILD_DIR)/$(PROJECT)-%: + $(eval os = $(firstword $(subst -, ,$*))) + $(eval goarch = $(lastword $(subst -, ,$(subst .exe,,$*)))) + $(eval image_platform = $(shell \ + if [[ $(os) == "darwin" ]]; then \ + echo darwin-arm64; \ + elif [[ $(goarch) == "arm64" ]]; then \ + echo arm; \ + else \ + echo main; \ + fi \ + )) + @echo $(image_platform) + docker run --rm \ + -v $(CURDIR):/skaffold \ + -w /skaffold \ + docker.elastic.co/beats-dev/golang-crossbuild:$(GOVERSION)-$(image_platform)-debian12 \ + -p="$(os)/$(goarch)" \ + --build-cmd="git config --global --add safe.directory /skaffold;make ./out/docker-skaffold-$(os)-$(goarch)" + +$(BUILD_DIR)/docker-$(PROJECT)-%: $(EMBEDDED_FILES_CHECK) $(GO_FILES) $(BUILD_DIR) $(eval os = $(firstword $(subst -, ,$*))) $(eval arch = $(lastword $(subst -, ,$(subst .exe,,$*)))) $(eval ldflags = $(GO_LDFLAGS) $(patsubst %,-extldflags \"%\",$(LDFLAGS_$(os)))) $(eval tags = $(GO_BUILD_TAGS) $(GO_BUILD_TAGS_$(os)) $(GO_BUILD_TAGS_$(os)_$(arch))) - GOOS=$(os) GOARCH=$(arch) CGO_ENABLED=1 go build -mod="vendor" -tags "$(tags)" -ldflags "$(ldflags)" -o $@ ./cmd/skaffold + CGO_ENABLED=1 go build -mod="vendor" -tags "$(tags)" -ldflags "$(ldflags)" -o $@ ./cmd/skaffold (cd `dirname $@`; shasum -a 256 `basename $@`) | tee $@.sha256 file $@ || true From 355c948f45c4a5fed5ce55a8f2b274270ba03e87 Mon Sep 17 00:00:00 2001 From: Angel Montero Date: Tue, 14 Jan 2025 00:58:09 -0500 Subject: [PATCH 2/4] add cross-compile on mac test --- .github/workflows/compile-mac.yaml | 35 ++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 .github/workflows/compile-mac.yaml diff --git a/.github/workflows/compile-mac.yaml b/.github/workflows/compile-mac.yaml new file mode 100644 index 00000000000..416a0cfbeb1 --- /dev/null +++ b/.github/workflows/compile-mac.yaml @@ -0,0 +1,35 @@ +name: Cross-Compile skaffold on MacOS + +# Triggers the workflow on push or pull request events +on: [push, pull_request] + +permissions: read-all + +concurrency: + group: build-${{ github.event.pull_request.number || github.ref }}-${{github.workflow}} + cancel-in-progress: ${{ github.ref != 'refs/heads/main' }} + +jobs: + + build: + name: Cross-Compile skaffold on MacOS + runs-on: macos-15-large + strategy: + matrix: + platforms: [linux-amd64, darwin-amd64, windows-amd64.exe, linux-arm64, darwin-arm64] + steps: + + - name: Check out code into the Go module directory + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Setup Docker + uses: docker/setup-docker-action@v4 + env: + LIMA_START_ARGS: --mount-writable + + - name: Make and install Skaffold binary from current PR + run: | + make ./out/VERSION + make ./out/skaffold-${{ matrix.platforms }}" From ad476d8895f654d34457839a3ce29fe63b13f2ee Mon Sep 17 00:00:00 2001 From: Angel Montero Date: Tue, 14 Jan 2025 09:33:20 -0500 Subject: [PATCH 3/4] install go in the cross-compile test --- .github/workflows/compile-mac.yaml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.github/workflows/compile-mac.yaml b/.github/workflows/compile-mac.yaml index 416a0cfbeb1..4777c83f140 100644 --- a/.github/workflows/compile-mac.yaml +++ b/.github/workflows/compile-mac.yaml @@ -24,6 +24,12 @@ jobs: with: fetch-depth: 0 + - name: Set up Go + uses: actions/setup-go@v5 + with: + go-version: 1.23.4 + id: go + - name: Setup Docker uses: docker/setup-docker-action@v4 env: From defe28ad943c717c737bdde798fee7a5b0e03fc0 Mon Sep 17 00:00:00 2001 From: Angel Montero Date: Tue, 14 Jan 2025 11:32:55 -0500 Subject: [PATCH 4/4] remove quote --- .github/workflows/compile-mac.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/compile-mac.yaml b/.github/workflows/compile-mac.yaml index 4777c83f140..d099febfc78 100644 --- a/.github/workflows/compile-mac.yaml +++ b/.github/workflows/compile-mac.yaml @@ -38,4 +38,4 @@ jobs: - name: Make and install Skaffold binary from current PR run: | make ./out/VERSION - make ./out/skaffold-${{ matrix.platforms }}" + make ./out/skaffold-${{ matrix.platforms }}