Skip to content

Commit 34cb344

Browse files
committed
Added cross-compilation tool
1 parent 6a932e0 commit 34cb344

File tree

4 files changed

+68
-4
lines changed

4 files changed

+68
-4
lines changed

.dockerignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
examples
2+
dist/
3+
4+
.git
5+
*~
6+
*#
7+
.#*
8+
scw

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
scw
33
scwversion/version.go
44
Godeps/
5+
dist/
56

67
# junk
78
*~

Dockerfile

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
FROM golang:cross
2+
3+
ENV CGO_ENABLED 0
4+
5+
# Install Godep for vendoring
6+
RUN go get github.com/tools/godep
7+
# Recompile the standard library without CGO
8+
RUN go install -a std
9+
10+
RUN apt-get install -y -q git
11+
12+
#RUN go get -d github.com/docker/docker github.com/Sirupsen/logrus github.com/dustin/go-humanize github.com/kardianos/osext golang.org/x/crypto/ssh/terminal
13+
14+
# Declare the maintainer
15+
MAINTAINER Scaleway Team <[email protected]> (@scaleway)
16+
17+
# For convenience, set an env variable with the path of the code
18+
ENV APP_DIR /go/src/github.com/scaleway/scaleway-cli
19+
20+
ADD . /go/src/github.com/scaleway/scaleway-cli
21+
22+
#RUN cd $APP_DIR && godep get && godep save
23+
24+
# Compile the binary and statically link
25+
RUN cd $APP_DIR && GOOS=darwin GOARCH=amd64 godep go build -a -v -ldflags '-d -w -s' -o /go/bin/scw-Darwin-x86_64
26+
RUN cd $APP_DIR && GOOS=darwin GOARCH=386 godep go build -a -v -ldflags '-d -w -s' -o /go/bin/scw-Darwin-i386
27+
RUN cd $APP_DIR && GOOS=linux GOARCH=amd64 godep go build -a -v -ldflags '-w -s' -o /go/bin/scw-Linux-x86_64
28+
RUN cd $APP_DIR && GOOS=linux GOARCH=386 godep go build -a -v -ldflags '-d -w -s' -o /go/bin/scw-Linux-i386
29+
RUN cd $APP_DIR && GOOS=linux GOARCH=arm GOARM=5 godep go build -a -v -ldflags '-d -w -s' -o /go/bin/scw-Linux-arm
30+
RUN cd $APP_DIR && GOOS=linux GOARCH=arm GOARM=6 godep go build -a -v -ldflags '-d -w -s' -o /go/bin/scw-Linux-armv6
31+
RUN cd $APP_DIR && GOOS=linux GOARCH=arm GOARM=7 godep go build -a -v -ldflags '-d -w -s' -o /go/bin/scw-Linux-armv7
32+
RUN cd $APP_DIR && GOOS=freebsd GOARCH=amd64 godep go build -a -v -ldflags '-w -s' -o /go/bin/scw-Freebsd-x86_64
33+
RUN cd $APP_DIR && GOOS=freebsd GOARCH=386 godep go build -a -v -ldflags '-d -w -s' -o /go/bin/scw-Freebsd-i386
34+
RUN cd $APP_DIR && GOOS=freebsd GOARCH=arm GOARM=5 godep go build -a -v -ldflags '-d -w -s' -o /go/bin/scw-Freebsd-arm
35+
#RUN cd $APP_DIR && GOOS=openbsd GOARCH=amd64 godep go build -a -v -ldflags '-w -s' -o /go/bin/scw-Openbsd-x86_64
36+
#RUN cd $APP_DIR && GOOS=openbsd GOARCH=386 godep go build -a -v -ldflags '-d -w -s' -o /go/bin/scw-Openbsd-i386
37+
#RUN cd $APP_DIR && GOOS=openbsd GOARCH=arm GOARM=5 godep go build -a -v -ldflags '-d -w -s' -o /go/bin/scw-Openbsd-arm
38+
RUN cd $APP_DIR && GOOS=windows GOARCH=amd64 godep go build -a -v -ldflags '-w -s' -o /go/bin/scw-Windows-x86_64
39+
#RUN cd $APP_DIR && GOOS=windows GOARCH=386 godep go build -a -v -ldflags '-d -w -s' -o /go/bin/scw-Windows-i386
40+
#RUN cd $APP_DIR && GOOS=windows GOARCH=arm GOARM=5 godep go build -a -v -ldflags '-d -w -s' -o /go/bin/scw-Windows-arm

Makefile

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ NAME = scw
1212
SRC = .
1313
REV = $(shell git rev-parse HEAD || echo "nogit")
1414
TAG = $(shell git describe --always || echo "nogit")
15+
BUILDER = scaleway-cli-builder
1516

1617

1718
BUILD_LIST = $(foreach int, $(SRC), $(int)_build)
@@ -22,20 +23,22 @@ TEST_LIST = $(foreach int, $(SRC), $(int)_test)
2223
FMT_TEST = $(foreach int, $(SRC), $(int)_fmt)
2324

2425

25-
.PHONY: $(CLEAN_LIST) $(TEST_LIST) $(FMT_LIST) $(INSTALL_LIST) $(BUILD_LIST) $(IREF_LIST) scwversion
26+
.PHONY: $(CLEAN_LIST) $(TEST_LIST) $(FMT_LIST) $(INSTALL_LIST) $(BUILD_LIST) $(IREF_LIST) scwversion/version.go
2627

2728

2829
all: build
29-
build: scwversion $(BUILD_LIST)
30+
build: scwversion/version.go $(BUILD_LIST)
3031
clean: $(CLEAN_LIST)
3132
install: $(INSTALL_LIST)
3233
test: $(TEST_LIST)
3334
iref: $(IREF_LIST)
3435
fmt: $(FMT_TEST)
3536

3637

37-
scwversion:
38-
@sed 's/\(.*GITCOMMIT.* = \).*/\1"$(REV)"/;s/\(.*VERSION.* = \).*/\1"$(TAG)"/' scwversion/version.tpl > scwversion/version.go
38+
scwversion/version.go:
39+
@sed 's/\(.*GITCOMMIT.* = \).*/\1"$(REV)"/;s/\(.*VERSION.* = \).*/\1"$(TAG)"/' scwversion/version.tpl > $@.tmp
40+
@if [ "$$(diff $@.tmp $@ 2>&1)" != "" ]; then echo toto; mv $@.tmp $@; fi
41+
@rm -f $@.tmp
3942

4043

4144
Godeps:
@@ -56,3 +59,15 @@ $(TEST_LIST): %_test:
5659
$(GOTEST) ./$*
5760
$(FMT_TEST): %_fmt:
5861
$(GOFMT) ./$*
62+
63+
64+
cross: scwversion/version.go
65+
docker build -t $(BUILDER) .
66+
@docker rm scaleway-cli-builer 2>/dev/null || true
67+
mkdir -p dist
68+
docker run --name=$(BUILDER) $(BUILDER) tar -cf - /etc/ssl > dist/ssl.tar
69+
docker cp $(BUILDER):/go/bin tmp
70+
docker rm $(BUILDER)
71+
touch tmp/bin/*
72+
mv tmp/bin/* dist/
73+
rm -rf tmp dist/godep

0 commit comments

Comments
 (0)