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

Update release to build darwin/arm64 binary #5286

Merged
merged 5 commits into from
Feb 4, 2021
Merged
Show file tree
Hide file tree
Changes from 2 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
45 changes: 26 additions & 19 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ GCP_PROJECT ?= k8s-skaffold
GKE_CLUSTER_NAME ?= integration-tests
GKE_ZONE ?= us-central1-a

SUPPORTED_PLATFORMS = linux-amd64 darwin-amd64 windows-amd64.exe linux-arm64
SUPPORTED_PLATFORMS = linux-amd64 darwin-amd64 windows-amd64.exe linux-arm64 darwin-arm64
BUILD_PACKAGE = $(REPOPATH)/cmd/skaffold

SKAFFOLD_TEST_PACKAGES = ./pkg/skaffold/... ./cmd/... ./hack/... ./pkg/webhook/...
Expand All @@ -42,31 +42,31 @@ ifeq "$(strip $(VERSION))" ""
override VERSION = $(shell git describe --always --tags --dirty)
endif

LDFLAGS_linux = -static
LDFLAGS_darwin =
LDFLAGS_windows =

GO_BUILD_TAGS_linux = "osusergo netgo static_build release"
GO_BUILD_TAGS_darwin = "release"
GO_BUILD_TAGS_windows = "release"

GO_LDFLAGS = -X $(VERSION_PACKAGE).version=$(VERSION)
GO_LDFLAGS += -X $(VERSION_PACKAGE).buildDate=$(shell date +'%Y-%m-%dT%H:%M:%SZ')
GO_LDFLAGS += -X $(VERSION_PACKAGE).gitCommit=$(COMMIT)
GO_LDFLAGS += -X $(VERSION_PACKAGE).gitTreeState=$(if $(shell git status --porcelain),dirty,clean)
GO_LDFLAGS += -s -w

GO_LDFLAGS_windows =" $(GO_LDFLAGS) -extldflags \"$(LDFLAGS_windows)\""
GO_LDFLAGS_darwin =" $(GO_LDFLAGS) -extldflags \"$(LDFLAGS_darwin)\""
GO_LDFLAGS_linux =" $(GO_LDFLAGS) -extldflags \"$(LDFLAGS_linux)\""
GO_BUILD_TAGS_linux = osusergo netgo static_build release
LDFLAGS_linux = -static

GO_BUILD_TAGS_windows = release

# darwin/arm64 requires Go 1.16beta1 or later; dockercore/golang-cross
# doesn't have a recent macOS toolchain so disable CGO and use
# github.com/rjeczalik/notify's kqueue support.
GO_VERSION_darwin_arm64 = 1.16beta1
CGO_ENABLED_darwin_arm64 = 0
GO_BUILD_TAGS_darwin = release

ifneq "$(strip $(LOCAL))" "true"
override STATIK_FILES = cmd/skaffold/app/cmd/statik/statik.go
endif

# when build for local development (`LOCAL=true make install` can skip license check)
$(BUILD_DIR)/$(PROJECT): $(STATIK_FILES) $(GO_FILES) $(BUILD_DIR)
GOOS=$(GOOS) GOARCH=$(GOARCH) CGO_ENABLED=1 go build -gcflags="all=-N -l" -tags $(GO_BUILD_TAGS_$(GOOS)) -ldflags $(GO_LDFLAGS_$(GOOS)) -o $@ $(BUILD_PACKAGE)
GOOS=$(GOOS) GOARCH=$(GOARCH) CGO_ENABLED=1 go build -gcflags="all=-N -l" -tags "$(GO_BUILD_TAGS_$(GOOS))" -ldflags "$(GO_LDFLAGS_$(GOOS))" -o $@ $(BUILD_PACKAGE)
IsaacPD marked this conversation as resolved.
Show resolved Hide resolved

.PHONY: install
install: $(BUILD_DIR)/$(PROJECT)
Expand All @@ -81,14 +81,18 @@ cross: $(foreach platform, $(SUPPORTED_PLATFORMS), $(BUILD_DIR)/$(PROJECT)-$(pla
$(BUILD_DIR)/$(PROJECT)-%: $(STATIK_FILES) $(GO_FILES) $(BUILD_DIR) deploy/cross/Dockerfile
$(eval os = $(firstword $(subst -, ,$*)))
$(eval arch = $(lastword $(subst -, ,$(subst .exe,,$*))))
$(eval ldflags = $(GO_LDFLAGS_$(os)))
$(eval tags = $(GO_BUILD_TAGS_$(os)))
$(eval ldflags = $(LDFLAGS_$(os)))
$(eval tags = $(GO_BUILD_TAGS_$(os)) $(GO_BUILD_TAGS_$(os)_$(arch)))
$(eval cgoenabled = $(CGO_ENABLED_$(os)_$(arch)))
$(eval goversion = $(GO_VERSION_$(os)_$(arch)))

docker build \
--build-arg GOOS=$(os) \
--build-arg GOARCH=$(arch) \
--build-arg TAGS=$(tags) \
--build-arg LDFLAGS=$(ldflags) \
--build-arg GOOS="$(os)" \
--build-arg GOARCH="$(arch)" \
--build-arg TAGS="$(tags)" \
--build-arg LDFLAGS="$(GO_LDFLAGS) $(patsubst %,-extldflags \"%\",$(ldflags))" \
$(patsubst %,--build-arg CGO_ENABLED="%",$(cgoenabled)) \
$(patsubst %,--build-arg GO_VERSION="%",$(goversion)) \
-f deploy/cross/Dockerfile \
-t skaffold/cross \
.
Expand All @@ -97,6 +101,9 @@ $(BUILD_DIR)/$(PROJECT)-%: $(STATIK_FILES) $(GO_FILES) $(BUILD_DIR) deploy/cross
shasum -a 256 $@ | tee [email protected]
file $@ || true

$(BUILD_DIR)/$(PROJECT)-darwin: $(BUILD_DIR)/$(PROJECT)-darwin-amd64 $(BUILD_DIR)/$(PROJECT)-darwin-arm64
go run github.com/randall77/makefat $@ $^

.PHONY: $(BUILD_DIR)/VERSION
$(BUILD_DIR)/VERSION: $(BUILD_DIR)
@ echo $(VERSION) > $@
Expand Down
15 changes: 10 additions & 5 deletions deploy/cross/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,27 @@
# See the License for the specific language governing permissions and
# limitations under the License.

FROM dockercore/golang-cross:1.13.14 as base
FROM dockercore/golang-cross:1.13.15 as base

# The base image is not yet available for go 1.14.
# Allow overriding the go toolchain version as required, though dockercore/golang-cross
# only supports up to macOS 10.10, and Go 1.15 requires a later version.
ARG GO_VERSION=1.14.14

# The base image is not yet available for go 1.15.
# Let's just replace the Go that's installed with a newer one.
RUN rm -Rf /usr/local/go && mkdir /usr/local/go
RUN curl --fail --show-error --silent --location https://dl.google.com/go/go1.14.2.linux-amd64.tar.gz \
RUN curl --fail --show-error --silent --location https://dl.google.com/go/go${GO_VERSION}.linux-amd64.tar.gz \
| tar xz --directory=/usr/local/go --strip-components=1

# Cross compile Skaffold for Linux, Windows and MacOS
ARG GOOS
ARG GOARCH
ARG TAGS
ARG LDFLAGS
ARG CGO_ENABLED=1

WORKDIR /skaffold
COPY . ./
RUN if [ "$GOOS" = "darwin" ]; then export CC=o64-clang CXX=o64-clang++; fi; \
GOOS=$GOOS GOARCH=$GOARCH CGO_ENABLED=1 \
go build -tags "${TAGS}" -ldflags "${LDFLAGS}" -o /build/skaffold ./cmd/skaffold
GOOS=$GOOS GOARCH=$GOARCH CGO_ENABLED=$CGO_ENABLED \
go build -tags "${TAGS}" -ldflags "${LDFLAGS}" -o /build/skaffold ./cmd/skaffold
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ require (
github.com/opencontainers/runc v1.0.0-rc92 // indirect
github.com/pkg/browser v0.0.0-20180916011732-0a3d74bf9ce4
github.com/rakyll/statik v0.1.7
github.com/rjeczalik/notify v0.9.2
github.com/rjeczalik/notify v0.9.3-0.20201210012515-e2a77dcc14cf
github.com/russross/blackfriday/v2 v2.0.1
github.com/segmentio/textio v1.2.0
github.com/sirupsen/logrus v1.7.0
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1071,6 +1071,8 @@ github.com/rcrowley/go-metrics v0.0.0-20181016184325-3113b8401b8a/go.mod h1:bCqn
github.com/remyoudompheng/bigfft v0.0.0-20170806203942-52369c62f446/go.mod h1:uYEyJGbgTkfkS4+E/PavXkNJcbFIpEtjt2B0KDQ5+9M=
github.com/rjeczalik/notify v0.9.2 h1:MiTWrPj55mNDHEiIX5YUSKefw/+lCQVoAFmD6oQm5w8=
github.com/rjeczalik/notify v0.9.2/go.mod h1:aErll2f0sUX9PXZnVNyeiObbmTlk5jnMoCa4QEjJeqM=
github.com/rjeczalik/notify v0.9.3-0.20201210012515-e2a77dcc14cf h1:MY2fqXPSLfjld10N04fNcSFdR9K/Y57iXxZRFAivHzI=
github.com/rjeczalik/notify v0.9.3-0.20201210012515-e2a77dcc14cf/go.mod h1:aErll2f0sUX9PXZnVNyeiObbmTlk5jnMoCa4QEjJeqM=
github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6SoW27p1b0cqNHllgS5HIMJraePCO15w5zCzIWYg=
github.com/rogpeppe/fastuuid v1.1.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ=
github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ=
Expand Down