Skip to content

Commit 22e4056

Browse files
committed
feat(makefile): check that generated go binaries are statically linked
1 parent 19673b2 commit 22e4056

7 files changed

Lines changed: 16 additions & 0 deletions

File tree

builder/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ BINARY_DEST_DIR := image/bin
1616
build: check-docker
1717
for i in $(BINARIES); do \
1818
GOOS=linux GOARCH=amd64 CGO_ENABLED=0 godep go build -a -installsuffix cgo -v -ldflags '-s' -o $(BINARY_DEST_DIR)/$$i bin/$$i.go || exit 1; \
19+
$(call check-static-binary,$(BINARY_DEST_DIR)/$$i) \
1920
done
2021
docker build -t $(IMAGE) image
2122

cache/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ BINARY_DEST_DIR = image/bin
1414

1515
build: check-docker
1616
GOOS=linux GOARCH=amd64 CGO_ENABLED=0 godep go build -a -installsuffix cgo -v -ldflags '-s' -o $(BINARY_DEST_DIR)/boot main.go || exit 1
17+
$(call check-static-binary,$(BINARY_DEST_DIR)/boot)
1718
docker build -t $(BUILD_IMAGE) .
1819
docker cp `docker run -d $(BUILD_IMAGE)`:/usr/local/bin/redis-server $(BINARY_DEST_DIR)/
1920
docker build -t $(IMAGE) image

includes.mk

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,3 +48,13 @@ check-deisctl:
4848
@if [ -z $$(which deisctl) ]; then \
4949
echo "Missing \`deisctl\` utility, please install from https://github.com/deis/deis"; \
5050
fi
51+
52+
define check-static-binary
53+
if file $(1) | grep -q "statically linked"; then \
54+
echo -n ""; \
55+
else \
56+
echo "The binary file $(1) is not statically linked. Build canceled"; \
57+
exit 1; \
58+
fi
59+
endef
60+

logger/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ BINARY_DEST_DIR = image/bin
1515

1616
build: check-docker
1717
GOOS=linux GOARCH=amd64 CGO_ENABLED=0 godep go build -a -installsuffix cgo -v -ldflags '-s' -o $(BINARY_DEST_DIR)/logger github.com/deis/deis/logger || exit 1
18+
$(call check-static-binary,$(BINARY_DEST_DIR)/logger)
1819
docker build -t $(IMAGE) image
1920

2021
clean: check-docker check-registry

logspout/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ DEV_DOCKER_IMAGE := $(DEV_REGISTRY)/$(RELEASE_IMAGE)
1414

1515
build: check-docker
1616
GOOS=linux GOARCH=amd64 CGO_ENABLED=0 godep go build -a -installsuffix cgo -v -ldflags '-s' -o image/logspout
17+
$(call check-static-binary,image/logspout)
1718
docker build -t $(RELEASE_IMAGE) image
1819

1920
clean:

publisher/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ BINARY_DEST_DIR = image/bin
1515

1616
build: check-docker
1717
GOOS=linux GOARCH=amd64 CGO_ENABLED=0 godep go build -a -installsuffix cgo -v -ldflags '-s' -o $(BINARY_DEST_DIR)/publisher github.com/deis/deis/publisher || exit 1
18+
$(call check-static-binary,$(BINARY_DEST_DIR)/publisher)
1819
docker build -t $(RELEASE_IMAGE) image
1920

2021
clean: check-docker check-registry

router/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ build: check-docker
1717
docker build -t $(BUILD_IMAGE) .
1818
docker cp `docker run -d $(BUILD_IMAGE)`:/nginx.tgz image/
1919
docker cp `docker run -d $(BUILD_IMAGE)`:/go/bin/boot image/bin/
20+
$(call check-static-binary,image/bin/boot)
2021
docker build -t $(IMAGE) image
2122
rm image/nginx.tgz
2223
rm image/bin/boot

0 commit comments

Comments
 (0)