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 15, 2019
1 parent aa059bd commit e380dc0
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ before_script:
- echo -e "Host github.com\n\tStrictHostKeyChecking no\n" >> ~/.ssh/config

script:
- make out/skaffold
- make install
- make test

after_success:
Expand Down
12 changes: 8 additions & 4 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)
.PHONY: xgo
xgo:
go get github.com/karalabe/xgo

$(BUILD_DIR)/$(PROJECT)-%-$(GOARCH): xgo $(GO_FILES) $(BUILD_DIR)
xgo -go 1.12 -dest $(BUILD_DIR) -out $(PROJECT) --pkg cmd/skaffold --targets=$*/$(GOARCH) -ldflags $(GO_LDFLAGS) .
mv $(BUILD_DIR)/$(PROJECT)-$** $@

%.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
7 changes: 1 addition & 6 deletions deploy/skaffold/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -88,18 +88,13 @@ RUN apt-get update && apt-get install --no-install-recommends --no-install-sugge
COPY --from=golang:1.11 /usr/local/go /usr/local/go
ENV PATH /usr/local/go/bin:/go/bin:$PATH
ENV GOPATH /go/

WORKDIR /go/src/github.com/GoogleContainerTools/skaffold

COPY . .

FROM builder as integration
ARG VERSION

RUN make out/skaffold-linux-amd64 VERSION=$VERSION && mv out/skaffold-linux-amd64 /usr/bin/skaffold

RUN make install
CMD ["make", "integration"]

FROM runtime_deps as distribution

COPY --from=integration /usr/bin/skaffold /usr/bin/skaffold

0 comments on commit e380dc0

Please sign in to comment.