Skip to content

Commit

Permalink
Cross compile Skaffold, with CGO=1, using xgo
Browse files Browse the repository at this point in the history
Fixes #1936

Signed-off-by: David Gageot <david@gageot.net>
  • Loading branch information
dgageot committed May 31, 2019
1 parent 3e31530 commit 5d4ea95
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 3 deletions.
10 changes: 7 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,17 @@ GO_LDFLAGS += -X $(VERSION_PACKAGE).gitTreeState=$(if $(shell git status --porce
GO_LDFLAGS +="

GO_FILES := $(shell find . -type f -name '*.go' -not -path "./vendor/*")
GO_BUILD_TAGS := "kqueue"

$(BUILD_DIR)/$(PROJECT): $(BUILD_DIR)/$(PROJECT)-$(GOOS)-$(GOARCH)
cp $(BUILD_DIR)/$(PROJECT)-$(GOOS)-$(GOARCH) $@

$(BUILD_DIR)/$(PROJECT)-%-$(GOARCH): $(GO_FILES) $(BUILD_DIR)
GOOS=$* GOARCH=$(GOARCH) CGO_ENABLED=0 go build -ldflags $(GO_LDFLAGS) -gcflags $(GO_GCFLAGS) -asmflags $(GO_ASMFLAGS) -tags $(GO_BUILD_TAGS) -o $@ $(BUILD_PACKAGE)
if [ "$(GOOS)" -eq "$*" ]; then \
GOOS=$* GOARCH=$(GOARCH) CGO_ENABLED=1 go build -ldflags $(GO_LDFLAGS) -gcflags $(GO_GCFLAGS) -asmflags $(GO_ASMFLAGS) -o $@ $(BUILD_PACKAGE);\
else \
docker build --build-arg PROJECT=$(REPOPATH) --build-arg TARGETS=$*/$(GOARCH) --build-arg FLAG_LDFLAGS=$(GO_LDFLAGS) -f deploy/cross/Dockerfile -t skaffold/cross .;\
docker run --rm --entrypoint sh skaffold/cross -c "cat /build/skaffold*" > $@;\
fi

%.sha256: %
shasum -a 256 $< > $@
Expand All @@ -82,7 +86,7 @@ test: $(BUILD_DIR)

.PHONY: install
install: $(GO_FILES) $(BUILD_DIR)
GOOS=$(GOOS) GOARCH=$(GOARCH) CGO_ENABLED=0 go install -ldflags $(GO_LDFLAGS) -gcflags $(GO_GCFLAGS) -asmflags $(GO_ASMFLAGS) -tags $(GO_BUILD_TAGS) $(BUILD_PACKAGE)
GOOS=$(GOOS) GOARCH=$(GOARCH) CGO_ENABLED=1 go install -ldflags $(GO_LDFLAGS) -gcflags $(GO_GCFLAGS) -asmflags $(GO_ASMFLAGS) $(BUILD_PACKAGE)

.PHONY: integration
integration: install
Expand Down
28 changes: 28 additions & 0 deletions deploy/cross/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Copyright 2019 The Skaffold Authors All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# 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.

FROM karalabe/xgo-1.12

ARG PROJECT
ARG FLAG_LDFLAGS
ARG TARGETS

ENV PACK cmd/skaffold
ENV EXT_GOPATH /ext-go
ENV FLAG_LDFLAGS $FLAG_LDFLAGS
ENV TARGETS $TARGETS

WORKDIR /ext-go/src/$PROJECT
COPY . .
RUN /build.sh $PROJECT

0 comments on commit 5d4ea95

Please sign in to comment.