From fe4c2f522898baaa44d12595076143f4ff4b2f62 Mon Sep 17 00:00:00 2001 From: Jakub Matys Date: Wed, 11 Apr 2018 08:23:07 +0200 Subject: [PATCH] build improvements --- Makefile | 51 +++++++++++++++++++++++++++++++++------- build/bin/Dockerfile | 4 ++-- build/bin/Makefile | 6 +++++ build/deb/debian/control | 2 +- build/deb/debian/rules | 1 - 5 files changed, 51 insertions(+), 13 deletions(-) diff --git a/Makefile b/Makefile index 4faed853..00e051c8 100644 --- a/Makefile +++ b/Makefile @@ -1,17 +1,50 @@ +BIN_IMAGE = blockbook-build +DEB_IMAGE = blockbook-build-deb PACKAGER = $(shell id -u):$(shell id -g) +NO_CACHE = false -.PHONY: build test deb +.PHONY: build build-debug test deb -build: - docker run -t --rm -e PACKAGER=$(PACKAGER) -v $(CURDIR):/src -v $(CURDIR)/build:/out blockbook-build make build - strip build/blockbook +build: .bin-image + docker run -t --rm -e PACKAGER=$(PACKAGER) -v $(CURDIR):/src -v $(CURDIR)/build:/out $(BIN_IMAGE) make build -test: - docker run -t --rm -e PACKAGER=$(PACKAGER) -v $(CURDIR):/src blockbook-build make test +build-debug: .bin-image + docker run -t --rm -e PACKAGER=$(PACKAGER) -v $(CURDIR):/src -v $(CURDIR)/build:/out $(BIN_IMAGE) make build-debug -deb: - docker run -t --rm -e PACKAGER=$(PACKAGER) -v $(CURDIR):/src -v $(CURDIR)/build:/out blockbook-build-deb +test: .bin-image + docker run -t --rm -e PACKAGER=$(PACKAGER) -v $(CURDIR):/src $(BIN_IMAGE) make test -clean: +deb: .deb-image + docker run -t --rm -e PACKAGER=$(PACKAGER) -v $(CURDIR):/src -v $(CURDIR)/build:/out $(DEB_IMAGE) + +build-images: + rm -f .bin-image .deb-image + $(MAKE) .bin-image .deb-image + +.bin-image: + docker build --no-cache=$(NO_CACHE) -t $(BIN_IMAGE) build/bin + @ docker images -q $(BIN_IMAGE) > $@ + +.deb-image: + docker build --no-cache=$(NO_CACHE) -t $(DEB_IMAGE) build/deb + @ docker images -q $(DEB_IMAGE) > $@ + +clean: clean-bin clean-deb + +clean-all: clean clean-images + +clean-bin: rm -f build/blockbook + +clean-deb: rm -f build/*.deb + +clean-images: clean-bin-image clean-deb-image + +clean-bin-image: + - docker rmi $(BIN_IMAGE) + @ rm -f .bin-image + +clean-deb-image: + - docker rmi $(DEB_IMAGE) + @ rm -f .deb-image diff --git a/build/bin/Dockerfile b/build/bin/Dockerfile index a19b2740..d3429cad 100644 --- a/build/bin/Dockerfile +++ b/build/bin/Dockerfile @@ -4,7 +4,7 @@ FROM debian:9 RUN apt-get update && apt-get install -y \ build-essential git wget pkg-config lxc-dev libzmq3-dev libgflags-dev \ - libsnappy-dev zlib1g-dev libbz2-dev liblz4-dev graphviz + libsnappy-dev zlib1g-dev libbz2-dev liblz4-dev graphviz upx-ucl ENV GOLANG_VERSION=go1.10.linux-amd64 ENV GOPATH=/go @@ -22,7 +22,7 @@ RUN echo -n "GOPATH: " && echo $GOPATH # install rocksdb RUN cd /opt && git clone https://github.com/facebook/rocksdb.git -RUN cd /opt/rocksdb && CFLAGS=-fPIC CXXFLAGS=-fPIC make static_lib +RUN cd /opt/rocksdb && CFLAGS=-fPIC CXXFLAGS=-fPIC make -j 4 static_lib RUN go get github.com/golang/dep/cmd/dep diff --git a/build/bin/Makefile b/build/bin/Makefile index d5bb9393..74f8a2f9 100644 --- a/build/bin/Makefile +++ b/build/bin/Makefile @@ -1,4 +1,10 @@ build: prepare-sources + cd $(GOPATH)/src/blockbook && go build -o $(CURDIR)/blockbook -ldflags="-s -w" + upx $(CURDIR)/blockbook + cp $(CURDIR)/blockbook /out/blockbook + chown $(PACKAGER) /out/blockbook + +build-debug: prepare-sources cd $(GOPATH)/src/blockbook && go build -o $(CURDIR)/blockbook cp $(CURDIR)/blockbook /out/blockbook chown $(PACKAGER) /out/blockbook diff --git a/build/deb/debian/control b/build/deb/debian/control index 842894b8..292a1555 100644 --- a/build/deb/debian/control +++ b/build/deb/debian/control @@ -2,7 +2,7 @@ Source: blockbook Section: satoshilabs Priority: optional Maintainer: jakub.matys@satoshilabs.com -Build-Depends: debhelper, dh-systemd, dh-exec +Build-Depends: debhelper, dh-systemd, dh-exec, upx Standards-Version: 3.9.5 Package: blockbook-btc diff --git a/build/deb/debian/rules b/build/deb/debian/rules index 6fc7e595..29e4409f 100755 --- a/build/deb/debian/rules +++ b/build/deb/debian/rules @@ -6,4 +6,3 @@ DH_VERBOSE = 1 dh $@ --with=systemd override_dh_strip: - dh_strip --no-automatic-dbgsym