From 7308bcf51a5809ef8933ce5c68dcaa3983b530ff Mon Sep 17 00:00:00 2001 From: Jakub Matys Date: Tue, 10 Apr 2018 11:53:33 +0200 Subject: [PATCH 1/9] new building and packaging --- Makefile | 17 ++++++++ {docker => build/bin}/Dockerfile | 12 ++---- build/bin/Makefile | 12 ++++++ build/deb/Dockerfile | 12 ++++++ build/deb/build-deb.sh | 10 +++++ .../debian/blockbook-btc-testnet.conffiles | 1 + build/deb/debian/blockbook-btc-testnet.dirs | 2 + .../deb/debian/blockbook-btc-testnet.install | 4 ++ build/deb/debian/blockbook-btc-testnet.links | 2 + .../debian/blockbook-btc-testnet.logrotate | 9 ++++ .../deb/debian/blockbook-btc-testnet.postinst | 20 +++++++++ .../deb/debian/blockbook-btc-testnet.service | 43 +++++++++++++++++++ build/deb/debian/blockbook-btc.conffiles | 1 + build/deb/debian/blockbook-btc.dirs | 2 + build/deb/debian/blockbook-btc.install | 4 ++ build/deb/debian/blockbook-btc.links | 2 + build/deb/debian/blockbook-btc.logrotate | 9 ++++ build/deb/debian/blockbook-btc.postinst | 20 +++++++++ build/deb/debian/blockbook-btc.service | 43 +++++++++++++++++++ build/deb/debian/blockbook-zec.conffiles | 1 + build/deb/debian/blockbook-zec.dirs | 2 + build/deb/debian/blockbook-zec.install | 4 ++ build/deb/debian/blockbook-zec.links | 2 + build/deb/debian/blockbook-zec.logrotate | 9 ++++ build/deb/debian/blockbook-zec.postinst | 20 +++++++++ build/deb/debian/blockbook-zec.service | 43 +++++++++++++++++++ build/deb/debian/changelog | 5 +++ build/deb/debian/compat | 1 + build/deb/debian/control | 21 +++++++++ build/deb/debian/rules | 9 ++++ configs/btc-testnet.json | 6 +-- configs/btc.json | 8 ++++ configs/zec.json | 8 ++++ docker/build.sh | 16 ------- 34 files changed, 352 insertions(+), 28 deletions(-) create mode 100644 Makefile rename {docker => build/bin}/Dockerfile (73%) create mode 100644 build/bin/Makefile create mode 100644 build/deb/Dockerfile create mode 100755 build/deb/build-deb.sh create mode 100644 build/deb/debian/blockbook-btc-testnet.conffiles create mode 100644 build/deb/debian/blockbook-btc-testnet.dirs create mode 100755 build/deb/debian/blockbook-btc-testnet.install create mode 100644 build/deb/debian/blockbook-btc-testnet.links create mode 100644 build/deb/debian/blockbook-btc-testnet.logrotate create mode 100644 build/deb/debian/blockbook-btc-testnet.postinst create mode 100644 build/deb/debian/blockbook-btc-testnet.service create mode 100644 build/deb/debian/blockbook-btc.conffiles create mode 100644 build/deb/debian/blockbook-btc.dirs create mode 100755 build/deb/debian/blockbook-btc.install create mode 100644 build/deb/debian/blockbook-btc.links create mode 100644 build/deb/debian/blockbook-btc.logrotate create mode 100644 build/deb/debian/blockbook-btc.postinst create mode 100644 build/deb/debian/blockbook-btc.service create mode 100644 build/deb/debian/blockbook-zec.conffiles create mode 100644 build/deb/debian/blockbook-zec.dirs create mode 100755 build/deb/debian/blockbook-zec.install create mode 100644 build/deb/debian/blockbook-zec.links create mode 100644 build/deb/debian/blockbook-zec.logrotate create mode 100644 build/deb/debian/blockbook-zec.postinst create mode 100644 build/deb/debian/blockbook-zec.service create mode 100644 build/deb/debian/changelog create mode 100644 build/deb/debian/compat create mode 100644 build/deb/debian/control create mode 100755 build/deb/debian/rules create mode 100644 configs/btc.json create mode 100644 configs/zec.json delete mode 100755 docker/build.sh diff --git a/Makefile b/Makefile new file mode 100644 index 00000000..4faed853 --- /dev/null +++ b/Makefile @@ -0,0 +1,17 @@ +PACKAGER = $(shell id -u):$(shell id -g) + +.PHONY: build test deb + +build: + docker run -t --rm -e PACKAGER=$(PACKAGER) -v $(CURDIR):/src -v $(CURDIR)/build:/out blockbook-build make build + strip build/blockbook + +test: + docker run -t --rm -e PACKAGER=$(PACKAGER) -v $(CURDIR):/src blockbook-build make test + +deb: + docker run -t --rm -e PACKAGER=$(PACKAGER) -v $(CURDIR):/src -v $(CURDIR)/build:/out blockbook-build-deb + +clean: + rm -f build/blockbook + rm -f build/*.deb diff --git a/docker/Dockerfile b/build/bin/Dockerfile similarity index 73% rename from docker/Dockerfile rename to build/bin/Dockerfile index 380128b6..a19b2740 100644 --- a/docker/Dockerfile +++ b/build/bin/Dockerfile @@ -26,14 +26,8 @@ RUN cd /opt/rocksdb && CFLAGS=-fPIC CXXFLAGS=-fPIC make static_lib RUN go get github.com/golang/dep/cmd/dep -# clone repo and ensure dependencies -RUN cd $GOPATH/src && git clone https://github.com/jpochyla/blockbook.git -RUN cd $GOPATH/src/blockbook && dep ensure +ADD Makefile /build/Makefile -# install gorocksdb -RUN cd $GOPATH/src/blockbook/vendor/github.com/tecbot/gorocksdb && \ - go install . +VOLUME /out -WORKDIR $GOPATH/src/blockbook - -CMD go build -o /out/blockbook +WORKDIR /build diff --git a/build/bin/Makefile b/build/bin/Makefile new file mode 100644 index 00000000..d5bb9393 --- /dev/null +++ b/build/bin/Makefile @@ -0,0 +1,12 @@ +build: prepare-sources + cd $(GOPATH)/src/blockbook && go build -o $(CURDIR)/blockbook + cp $(CURDIR)/blockbook /out/blockbook + chown $(PACKAGER) /out/blockbook + +test: prepare-sources + cd $(GOPATH)/src/blockbook && go test -v ./bchain/coins/zec + +prepare-sources: + @ [ -n "`ls /src 2> /dev/null`" ] || (echo "/src doesn't exist or is empty" 1>&2 && exit 1) + cp -r /src $(GOPATH)/src/blockbook + cd $(GOPATH)/src/blockbook && dep ensure -vendor-only diff --git a/build/deb/Dockerfile b/build/deb/Dockerfile new file mode 100644 index 00000000..5782d98b --- /dev/null +++ b/build/deb/Dockerfile @@ -0,0 +1,12 @@ +# initialize from the image + +FROM blockbook-build:latest + +RUN apt-get update && apt-get install -y \ + devscripts debhelper make dh-systemd dh-exec + +ADD build-deb.sh /build/build-deb.sh + +WORKDIR /build + +CMD /build/build-deb.sh diff --git a/build/deb/build-deb.sh b/build/deb/build-deb.sh new file mode 100755 index 00000000..0c064954 --- /dev/null +++ b/build/deb/build-deb.sh @@ -0,0 +1,10 @@ +#!/bin/bash +set -e + +cp -r /src/build/deb/debian . +cp -r /src/configs . +mkdir server && cp /src/server/testcert.* server + +dpkg-buildpackage -us -uc +mv ../*.deb /out +chown $PACKAGER /out/*.deb diff --git a/build/deb/debian/blockbook-btc-testnet.conffiles b/build/deb/debian/blockbook-btc-testnet.conffiles new file mode 100644 index 00000000..354f62ae --- /dev/null +++ b/build/deb/debian/blockbook-btc-testnet.conffiles @@ -0,0 +1 @@ +/opt/blockbook/btc-testnet/config/blockchaincfg.json diff --git a/build/deb/debian/blockbook-btc-testnet.dirs b/build/deb/debian/blockbook-btc-testnet.dirs new file mode 100644 index 00000000..e1d51287 --- /dev/null +++ b/build/deb/debian/blockbook-btc-testnet.dirs @@ -0,0 +1,2 @@ +/data/btc-testnet/blockbook +/opt/blockbook/btc-testnet/logs diff --git a/build/deb/debian/blockbook-btc-testnet.install b/build/deb/debian/blockbook-btc-testnet.install new file mode 100755 index 00000000..58ed0672 --- /dev/null +++ b/build/deb/debian/blockbook-btc-testnet.install @@ -0,0 +1,4 @@ +#!/usr/bin/dh-exec +blockbook /opt/blockbook/btc-testnet/bin +server/testcert.* /opt/blockbook/btc-testnet/cert +configs/btc-testnet.json => /opt/blockbook/btc-testnet/config/blockchaincfg.json diff --git a/build/deb/debian/blockbook-btc-testnet.links b/build/deb/debian/blockbook-btc-testnet.links new file mode 100644 index 00000000..d8166b72 --- /dev/null +++ b/build/deb/debian/blockbook-btc-testnet.links @@ -0,0 +1,2 @@ +/opt/blockbook/btc-testnet/cert/testcert.crt /opt/blockbook/btc-testnet/cert/blockbook.crt +/opt/blockbook/btc-testnet/cert/testcert.key /opt/blockbook/btc-testnet/cert/blockbook.key diff --git a/build/deb/debian/blockbook-btc-testnet.logrotate b/build/deb/debian/blockbook-btc-testnet.logrotate new file mode 100644 index 00000000..624d120b --- /dev/null +++ b/build/deb/debian/blockbook-btc-testnet.logrotate @@ -0,0 +1,9 @@ +/opt/blockbook/btc-testnet/logs/blockbook.log +{ + rotate 7 + daily + compress + missingok + notifempty + copytruncate +} diff --git a/build/deb/debian/blockbook-btc-testnet.postinst b/build/deb/debian/blockbook-btc-testnet.postinst new file mode 100644 index 00000000..9f310abc --- /dev/null +++ b/build/deb/debian/blockbook-btc-testnet.postinst @@ -0,0 +1,20 @@ +#!/bin/bash +set -e + +case "$1" in + + configure) + if ! id -u blockbook &> /dev/null + then + useradd --system -M -U blockbook + fi + + if [ "$(stat -c '%U' /data/btc-testnet/blockbook)" != "blockbook" ] + then + chown -R blockbook:blockbook /data/btc-testnet/blockbook + fi + ;; + +esac + +#DEBHELPER# diff --git a/build/deb/debian/blockbook-btc-testnet.service b/build/deb/debian/blockbook-btc-testnet.service new file mode 100644 index 00000000..ab84d20a --- /dev/null +++ b/build/deb/debian/blockbook-btc-testnet.service @@ -0,0 +1,43 @@ +# It is not recommended to modify this file in-place, because it will +# be overwritten during package upgrades. If you want to add further +# options or overwrite existing ones then use +# $ systemctl edit blockbook-btc-testnet.service +# See "man systemd.service" for details. + +[Unit] +Description=Blockbook daemon (BTC testnet) +After=network.target + +[Service] +ExecStart=/opt/blockbook/btc-testnet/bin/blockbook -coin=btc-testnet -blockchaincfg=/opt/blockbook/btc-testnet/config/blockchaincfg.json -datadir=/data/btc-testnet/blockbook/db -sync -httpserver=:18335 -socketio=:18336 -certfile=/opt/blockbook/btc-testnet/cert/blockbook -explorer=https://bitcore1.trezor.io/ +# Creates /run/blockbook owned by blockbook +RuntimeDirectory=blockbook +User=blockbook +# Type=forking +# PIDFile=/run/bitcoind/btc-testnet.pid +Restart=on-failure +StandardOutput=file:/opt/blockbook/btc-testnet/logs/blockbook.log +StandardError=file:/opt/blockbook/btc-testnet/logs/blockbook.log + +# Hardening measures +#################### + +# Provide a private /tmp and /var/tmp. +PrivateTmp=true + +# Mount /usr, /boot/ and /etc read-only for the process. +ProtectSystem=full + +# Disallow the process and all of its children to gain +# new privileges through execve(). +NoNewPrivileges=true + +# Use a new /dev namespace only populated with API pseudo devices +# such as /dev/null, /dev/zero and /dev/random. +PrivateDevices=true + +# Deny the creation of writable and executable memory mappings. +MemoryDenyWriteExecute=true + +[Install] +WantedBy=multi-user.target diff --git a/build/deb/debian/blockbook-btc.conffiles b/build/deb/debian/blockbook-btc.conffiles new file mode 100644 index 00000000..1714ce0f --- /dev/null +++ b/build/deb/debian/blockbook-btc.conffiles @@ -0,0 +1 @@ +/opt/blockbook/btc/config/blockchaincfg.json diff --git a/build/deb/debian/blockbook-btc.dirs b/build/deb/debian/blockbook-btc.dirs new file mode 100644 index 00000000..907b5d84 --- /dev/null +++ b/build/deb/debian/blockbook-btc.dirs @@ -0,0 +1,2 @@ +/data/btc/blockbook +/opt/blockbook/btc/logs diff --git a/build/deb/debian/blockbook-btc.install b/build/deb/debian/blockbook-btc.install new file mode 100755 index 00000000..fb662d95 --- /dev/null +++ b/build/deb/debian/blockbook-btc.install @@ -0,0 +1,4 @@ +#!/usr/bin/dh-exec +blockbook /opt/blockbook/btc/bin +server/testcert.* /opt/blockbook/btc/cert +configs/btc.json => /opt/blockbook/btc/config/blockchaincfg.json diff --git a/build/deb/debian/blockbook-btc.links b/build/deb/debian/blockbook-btc.links new file mode 100644 index 00000000..519988cb --- /dev/null +++ b/build/deb/debian/blockbook-btc.links @@ -0,0 +1,2 @@ +/opt/blockbook/btc/cert/testcert.crt /opt/blockbook/btc/cert/blockbook.crt +/opt/blockbook/btc/cert/testcert.key /opt/blockbook/btc/cert/blockbook.key diff --git a/build/deb/debian/blockbook-btc.logrotate b/build/deb/debian/blockbook-btc.logrotate new file mode 100644 index 00000000..16b1f999 --- /dev/null +++ b/build/deb/debian/blockbook-btc.logrotate @@ -0,0 +1,9 @@ +/opt/blockbook/btc/logs/blockbook.log +{ + rotate 7 + daily + compress + missingok + notifempty + copytruncate +} diff --git a/build/deb/debian/blockbook-btc.postinst b/build/deb/debian/blockbook-btc.postinst new file mode 100644 index 00000000..721e99f6 --- /dev/null +++ b/build/deb/debian/blockbook-btc.postinst @@ -0,0 +1,20 @@ +#!/bin/bash +set -e + +case "$1" in + + configure) + if ! id -u blockbook &> /dev/null + then + useradd --system -M -U blockbook + fi + + if [ "$(stat -c '%U' /data/btc/blockbook)" != "blockbook" ] + then + chown -R blockbook:blockbook /data/btc/blockbook + fi + ;; + +esac + +#DEBHELPER# diff --git a/build/deb/debian/blockbook-btc.service b/build/deb/debian/blockbook-btc.service new file mode 100644 index 00000000..e5cf847a --- /dev/null +++ b/build/deb/debian/blockbook-btc.service @@ -0,0 +1,43 @@ +# It is not recommended to modify this file in-place, because it will +# be overwritten during package upgrades. If you want to add further +# options or overwrite existing ones then use +# $ systemctl edit blockbook-btc.service +# See "man systemd.service" for details. + +[Unit] +Description=Blockbook daemon (BTC mainnet) +After=network.target + +[Service] +ExecStart=/opt/blockbook/btc/bin/blockbook -coin=btc -blockchaincfg=/opt/blockbook/btc/config/blockchaincfg.json -datadir=/data/btc/blockbook/db -sync -httpserver=:8335 -socketio=:8336 -certfile=/opt/blockbook/btc/cert/blockbook -explorer=https://bitcore1.trezor.io/ +# Creates /run/blockbook owned by blockbook +RuntimeDirectory=blockbook +User=blockbook +# Type=forking +# PIDFile=/run/bitcoind/btc.pid +Restart=on-failure +StandardOutput=file:/opt/blockbook/btc/logs/blockbook.log +StandardError=file:/opt/blockbook/btc/logs/blockbook.log + +# Hardening measures +#################### + +# Provide a private /tmp and /var/tmp. +PrivateTmp=true + +# Mount /usr, /boot/ and /etc read-only for the process. +ProtectSystem=full + +# Disallow the process and all of its children to gain +# new privileges through execve(). +NoNewPrivileges=true + +# Use a new /dev namespace only populated with API pseudo devices +# such as /dev/null, /dev/zero and /dev/random. +PrivateDevices=true + +# Deny the creation of writable and executable memory mappings. +MemoryDenyWriteExecute=true + +[Install] +WantedBy=multi-user.target diff --git a/build/deb/debian/blockbook-zec.conffiles b/build/deb/debian/blockbook-zec.conffiles new file mode 100644 index 00000000..d3e9eb1c --- /dev/null +++ b/build/deb/debian/blockbook-zec.conffiles @@ -0,0 +1 @@ +/opt/blockbook/zec/config/blockchaincfg.json diff --git a/build/deb/debian/blockbook-zec.dirs b/build/deb/debian/blockbook-zec.dirs new file mode 100644 index 00000000..6d0f5523 --- /dev/null +++ b/build/deb/debian/blockbook-zec.dirs @@ -0,0 +1,2 @@ +/data/zec/blockbook +/opt/blockbook/zec/logs diff --git a/build/deb/debian/blockbook-zec.install b/build/deb/debian/blockbook-zec.install new file mode 100755 index 00000000..e696a00b --- /dev/null +++ b/build/deb/debian/blockbook-zec.install @@ -0,0 +1,4 @@ +#!/usr/bin/dh-exec --with=install +blockbook /opt/blockbook/zec/bin +server/testcert.* /opt/blockbook/zec/cert +configs/zec.json => /opt/blockbook/zec/config/blockchaincfg.json diff --git a/build/deb/debian/blockbook-zec.links b/build/deb/debian/blockbook-zec.links new file mode 100644 index 00000000..251168f7 --- /dev/null +++ b/build/deb/debian/blockbook-zec.links @@ -0,0 +1,2 @@ +/opt/blockbook/zec/cert/testcert.crt /opt/blockbook/zec/cert/blockbook.crt +/opt/blockbook/zec/cert/testcert.key /opt/blockbook/zec/cert/blockbook.key diff --git a/build/deb/debian/blockbook-zec.logrotate b/build/deb/debian/blockbook-zec.logrotate new file mode 100644 index 00000000..2420567b --- /dev/null +++ b/build/deb/debian/blockbook-zec.logrotate @@ -0,0 +1,9 @@ +/opt/blockbook/zec/logs/blockbook.log +{ + rotate 7 + daily + compress + missingok + notifempty + copytruncate +} diff --git a/build/deb/debian/blockbook-zec.postinst b/build/deb/debian/blockbook-zec.postinst new file mode 100644 index 00000000..1212e626 --- /dev/null +++ b/build/deb/debian/blockbook-zec.postinst @@ -0,0 +1,20 @@ +#!/bin/bash +set -e + +case "$1" in + + configure) + if ! id -u blockbook &> /dev/null + then + useradd --system -M -U blockbook + fi + + if [ "$(stat -c '%U' /data/zec/blockbook)" != "blockbook" ] + then + chown -R blockbook:blockbook /data/zec/blockbook + fi + ;; + +esac + +#DEBHELPER# diff --git a/build/deb/debian/blockbook-zec.service b/build/deb/debian/blockbook-zec.service new file mode 100644 index 00000000..3cc3cd63 --- /dev/null +++ b/build/deb/debian/blockbook-zec.service @@ -0,0 +1,43 @@ +# It is not recommended to modify this file in-place, because it will +# be overwritten during package upgrades. If you want to add further +# options or overwrite existing ones then use +# $ systemctl edit blockbook-zec.service +# See "man systemd.service" for details. + +[Unit] +Description=Blockbook daemon (ZEC mainnet) +After=network.target + +[Service] +ExecStart=/opt/blockbook/zec/bin/blockbook -coin=zec -blockchaincfg=/opt/blockbook/zec/config/blockchaincfg.json -datadir=/data/zec/blockbook/db -sync -httpserver=:8235 -socketio=:8236 -certfile=/opt/blockbook/zec/cert/blockbook -explorer=https://zec-bitcore1.trezor.io/ +# Creates /run/blockbook owned by blockbook +RuntimeDirectory=blockbook +User=blockbook +# Type=forking +# PIDFile=/run/bitcoind/zec.pid +Restart=on-failure +StandardOutput=file:/opt/blockbook/zec/logs/blockbook.log +StandardError=file:/opt/blockbook/zec/logs/blockbook.log + +# Hardening measures +#################### + +# Provide a private /tmp and /var/tmp. +PrivateTmp=true + +# Mount /usr, /boot/ and /etc read-only for the process. +ProtectSystem=full + +# Disallow the process and all of its children to gain +# new privileges through execve(). +NoNewPrivileges=true + +# Use a new /dev namespace only populated with API pseudo devices +# such as /dev/null, /dev/zero and /dev/random. +PrivateDevices=true + +# Deny the creation of writable and executable memory mappings. +MemoryDenyWriteExecute=true + +[Install] +WantedBy=multi-user.target diff --git a/build/deb/debian/changelog b/build/deb/debian/changelog new file mode 100644 index 00000000..900e7276 --- /dev/null +++ b/build/deb/debian/changelog @@ -0,0 +1,5 @@ +blockbook (0.0.1-satoshilabs1) unstable; urgency=medium + + * Initial build + + -- Jakub Matys Fri, 06 Apr 2018 12:44:25 +0200 diff --git a/build/deb/debian/compat b/build/deb/debian/compat new file mode 100644 index 00000000..ec635144 --- /dev/null +++ b/build/deb/debian/compat @@ -0,0 +1 @@ +9 diff --git a/build/deb/debian/control b/build/deb/debian/control new file mode 100644 index 00000000..842894b8 --- /dev/null +++ b/build/deb/debian/control @@ -0,0 +1,21 @@ +Source: blockbook +Section: satoshilabs +Priority: optional +Maintainer: jakub.matys@satoshilabs.com +Build-Depends: debhelper, dh-systemd, dh-exec +Standards-Version: 3.9.5 + +Package: blockbook-btc +Architecture: amd64 +Depends: ${shlibs:Depends}, ${misc:Depends} +Description: Satoshilabs blockbook server + +Package: blockbook-btc-testnet +Architecture: amd64 +Depends: ${shlibs:Depends}, ${misc:Depends} +Description: Satoshilabs blockbook server + +Package: blockbook-zec +Architecture: amd64 +Depends: ${shlibs:Depends}, ${misc:Depends} +Description: Satoshilabs blockbook server diff --git a/build/deb/debian/rules b/build/deb/debian/rules new file mode 100755 index 00000000..6fc7e595 --- /dev/null +++ b/build/deb/debian/rules @@ -0,0 +1,9 @@ +#!/usr/bin/make -f + +DH_VERBOSE = 1 + +%: + dh $@ --with=systemd + +override_dh_strip: + dh_strip --no-automatic-dbgsym diff --git a/configs/btc-testnet.json b/configs/btc-testnet.json index 17275838..a58b662a 100644 --- a/configs/btc-testnet.json +++ b/configs/btc-testnet.json @@ -1,8 +1,8 @@ { - "rpcURL": "http://localhost:8332", + "rpcURL": "http://localhost:18332", "rpcUser": "rpc", "rpcPass": "rpc", "rpcTimeout": 25, "parse": true, - "zeroMQBinding": "tcp://127.0.0.1:28332" -} \ No newline at end of file + "zeroMQBinding": "tcp://127.0.0.1:18334" +} diff --git a/configs/btc.json b/configs/btc.json new file mode 100644 index 00000000..754f04b1 --- /dev/null +++ b/configs/btc.json @@ -0,0 +1,8 @@ +{ + "rpcURL": "http://127.0.0.1:8332", + "rpcUser": "rpc", + "rpcPass": "rpc", + "rpcTimeout": 25, + "parse": true, + "zeroMQBinding": "tcp://127.0.0.1:8334" +} diff --git a/configs/zec.json b/configs/zec.json new file mode 100644 index 00000000..e99cbf54 --- /dev/null +++ b/configs/zec.json @@ -0,0 +1,8 @@ +{ + "rpcURL": "http://127.0.0.1:8232", + "rpcUser": "rpc", + "rpcPass": "rpc", + "rpcTimeout": 25, + "parse": true, + "zeroMQBinding": "tcp://127.0.0.1:8234" +} diff --git a/docker/build.sh b/docker/build.sh deleted file mode 100755 index 106f3bef..00000000 --- a/docker/build.sh +++ /dev/null @@ -1,16 +0,0 @@ -#!/usr/bin/env bash -set -e - -cd `dirname $0` - -# prepare build image -docker build -t blockbook-build . - -if [ "$1" == "local" ]; then - SRC_BIND="-v $(pwd)/..:/go/src/blockbook" -fi - -# build binary -docker run -t --rm -v $(pwd):/out $SRC_BIND blockbook-build - -strip blockbook From fe4c2f522898baaa44d12595076143f4ff4b2f62 Mon Sep 17 00:00:00 2001 From: Jakub Matys Date: Wed, 11 Apr 2018 08:23:07 +0200 Subject: [PATCH 2/9] 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 From a07ef5ac807e1429ec6156406e8cf9f6a8a51b8c Mon Sep 17 00:00:00 2001 From: Jakub Matys Date: Wed, 11 Apr 2018 08:44:23 +0200 Subject: [PATCH 3/9] added backend packaging files --- contrib/backends/Makefile | 28 ++++++++++++ contrib/backends/bitcoin/Makefile | 13 ++++++ contrib/backends/bitcoin/btc-testnet.conf | 12 +++++ contrib/backends/bitcoin/btc.conf | 11 +++++ .../bitcoin/debian/bitcoin-btc.conffiles | 1 + .../backends/bitcoin/debian/bitcoin-btc.dirs | 1 + .../bitcoin/debian/bitcoin-btc.install | 1 + .../bitcoin/debian/bitcoin-btc.logrotate | 10 +++++ .../bitcoin/debian/bitcoin-btc.postinst | 20 +++++++++ .../bitcoin/debian/bitcoin-btc.service | 44 +++++++++++++++++++ .../bitcoin/debian/bitcoin-testnet.conffiles | 1 + .../bitcoin/debian/bitcoin-testnet.dirs | 1 + .../bitcoin/debian/bitcoin-testnet.install | 1 + .../bitcoin/debian/bitcoin-testnet.logrotate | 10 +++++ .../bitcoin/debian/bitcoin-testnet.postinst | 20 +++++++++ .../bitcoin/debian/bitcoin-testnet.service | 44 +++++++++++++++++++ .../backends/bitcoin/debian/bitcoin.install | 1 + contrib/backends/bitcoin/debian/bitcoin.links | 2 + contrib/backends/bitcoin/debian/changelog | 5 +++ contrib/backends/bitcoin/debian/compat | 1 + contrib/backends/bitcoin/debian/control | 21 +++++++++ contrib/backends/bitcoin/debian/rules | 6 +++ contrib/backends/docker/Dockerfile | 13 ++++++ contrib/backends/docker/build.sh | 15 +++++++ contrib/backends/zcash/Makefile | 11 +++++ contrib/backends/zcash/debian/changelog | 5 +++ contrib/backends/zcash/debian/compat | 1 + contrib/backends/zcash/debian/control | 16 +++++++ contrib/backends/zcash/debian/rules | 6 +++ .../backends/zcash/debian/zcash-zec.conffiles | 1 + contrib/backends/zcash/debian/zcash-zec.dirs | 1 + .../backends/zcash/debian/zcash-zec.install | 1 + .../backends/zcash/debian/zcash-zec.logrotate | 10 +++++ .../backends/zcash/debian/zcash-zec.postinst | 22 ++++++++++ .../backends/zcash/debian/zcash-zec.service | 44 +++++++++++++++++++ contrib/backends/zcash/debian/zcash.install | 1 + contrib/backends/zcash/debian/zcash.links | 2 + contrib/backends/zcash/zec.conf | 13 ++++++ 38 files changed, 416 insertions(+) create mode 100644 contrib/backends/Makefile create mode 100644 contrib/backends/bitcoin/Makefile create mode 100644 contrib/backends/bitcoin/btc-testnet.conf create mode 100644 contrib/backends/bitcoin/btc.conf create mode 100644 contrib/backends/bitcoin/debian/bitcoin-btc.conffiles create mode 100644 contrib/backends/bitcoin/debian/bitcoin-btc.dirs create mode 100644 contrib/backends/bitcoin/debian/bitcoin-btc.install create mode 100644 contrib/backends/bitcoin/debian/bitcoin-btc.logrotate create mode 100644 contrib/backends/bitcoin/debian/bitcoin-btc.postinst create mode 100644 contrib/backends/bitcoin/debian/bitcoin-btc.service create mode 100644 contrib/backends/bitcoin/debian/bitcoin-testnet.conffiles create mode 100644 contrib/backends/bitcoin/debian/bitcoin-testnet.dirs create mode 100644 contrib/backends/bitcoin/debian/bitcoin-testnet.install create mode 100644 contrib/backends/bitcoin/debian/bitcoin-testnet.logrotate create mode 100644 contrib/backends/bitcoin/debian/bitcoin-testnet.postinst create mode 100644 contrib/backends/bitcoin/debian/bitcoin-testnet.service create mode 100644 contrib/backends/bitcoin/debian/bitcoin.install create mode 100644 contrib/backends/bitcoin/debian/bitcoin.links create mode 100644 contrib/backends/bitcoin/debian/changelog create mode 100644 contrib/backends/bitcoin/debian/compat create mode 100644 contrib/backends/bitcoin/debian/control create mode 100755 contrib/backends/bitcoin/debian/rules create mode 100644 contrib/backends/docker/Dockerfile create mode 100755 contrib/backends/docker/build.sh create mode 100644 contrib/backends/zcash/Makefile create mode 100644 contrib/backends/zcash/debian/changelog create mode 100644 contrib/backends/zcash/debian/compat create mode 100644 contrib/backends/zcash/debian/control create mode 100755 contrib/backends/zcash/debian/rules create mode 100644 contrib/backends/zcash/debian/zcash-zec.conffiles create mode 100644 contrib/backends/zcash/debian/zcash-zec.dirs create mode 100644 contrib/backends/zcash/debian/zcash-zec.install create mode 100644 contrib/backends/zcash/debian/zcash-zec.logrotate create mode 100644 contrib/backends/zcash/debian/zcash-zec.postinst create mode 100644 contrib/backends/zcash/debian/zcash-zec.service create mode 100644 contrib/backends/zcash/debian/zcash.install create mode 100644 contrib/backends/zcash/debian/zcash.links create mode 100644 contrib/backends/zcash/zec.conf diff --git a/contrib/backends/Makefile b/contrib/backends/Makefile new file mode 100644 index 00000000..819b0d4a --- /dev/null +++ b/contrib/backends/Makefile @@ -0,0 +1,28 @@ +TARGETS = bitcoin zcash +IMAGE = blockbook-backend-build-deb +NO_CACHE = false + +.PHONY: $(TARGETS) + +all: $(TARGETS) + +$(TARGETS): .docker-image + docker run -t --rm -e PACKAGER="`id -u`:`id -g`" -v $(CURDIR)/$@:/deb/$@ $(IMAGE) $@ + mv $@/*.deb . + +build-image: + rm -f .docker-image + $(MAKE) .docker-image + +.docker-image: + docker build --no-cache=$(NO_CACHE)-t $(IMAGE) docker + @ docker images -q $(IMAGE) > $@ + +clean: clean-packages clean-image + +clean-packages: + rm -f *.deb + +clean-image: + - docker rmi $(IMAGE) + @ rm -f .docker-image diff --git a/contrib/backends/bitcoin/Makefile b/contrib/backends/bitcoin/Makefile new file mode 100644 index 00000000..1061ac82 --- /dev/null +++ b/contrib/backends/bitcoin/Makefile @@ -0,0 +1,13 @@ +BITCOIN_VERSION := 0.16.0 + +all: + wget https://bitcoin.org/bin/bitcoin-core-${BITCOIN_VERSION}/bitcoin-${BITCOIN_VERSION}-x86_64-linux-gnu.tar.gz + tar -xf bitcoin-${BITCOIN_VERSION}-x86_64-linux-gnu.tar.gz + mv bitcoin-${BITCOIN_VERSION} bitcoin + rm bitcoin/bin/bitcoin-qt + rm bitcoin/bin/bitcoin-tx + rm bitcoin/bin/test_bitcoin + +clean: + rm -rf bitcoin + rm -f bitcoin-${BITCOIN_VERSION}-x86_64-linux-gnu.tar.gz* diff --git a/contrib/backends/bitcoin/btc-testnet.conf b/contrib/backends/bitcoin/btc-testnet.conf new file mode 100644 index 00000000..cb3d8033 --- /dev/null +++ b/contrib/backends/bitcoin/btc-testnet.conf @@ -0,0 +1,12 @@ +daemon=1 +server=1 +testnet=1 +rpcuser=rpc +rpcpassword=rpc +rpcport=18332 +txindex=1 +rpcworkqueue=32 +zmqpubhashtx=tcp://127.0.0.1:18334 +zmqpubhashblock=tcp://127.0.0.1:18334 +zmqpubrawblock=tcp://127.0.0.1:18334 +zmqpubrawtx=tcp://127.0.0.1:18334 diff --git a/contrib/backends/bitcoin/btc.conf b/contrib/backends/bitcoin/btc.conf new file mode 100644 index 00000000..faa23bbd --- /dev/null +++ b/contrib/backends/bitcoin/btc.conf @@ -0,0 +1,11 @@ +daemon=1 +server=1 +rpcuser=rpc +rpcpassword=rpc +rpcport=8332 +txindex=1 +rpcworkqueue=32 +zmqpubhashtx=tcp://127.0.0.1:8334 +zmqpubhashblock=tcp://127.0.0.1:8334 +zmqpubrawblock=tcp://127.0.0.1:8334 +zmqpubrawtx=tcp://127.0.0.1:8334 diff --git a/contrib/backends/bitcoin/debian/bitcoin-btc.conffiles b/contrib/backends/bitcoin/debian/bitcoin-btc.conffiles new file mode 100644 index 00000000..186137f2 --- /dev/null +++ b/contrib/backends/bitcoin/debian/bitcoin-btc.conffiles @@ -0,0 +1 @@ +/data/btc/bitcoin/btc.conf diff --git a/contrib/backends/bitcoin/debian/bitcoin-btc.dirs b/contrib/backends/bitcoin/debian/bitcoin-btc.dirs new file mode 100644 index 00000000..4195abd8 --- /dev/null +++ b/contrib/backends/bitcoin/debian/bitcoin-btc.dirs @@ -0,0 +1 @@ +/data/btc/bitcoin diff --git a/contrib/backends/bitcoin/debian/bitcoin-btc.install b/contrib/backends/bitcoin/debian/bitcoin-btc.install new file mode 100644 index 00000000..4d959fa5 --- /dev/null +++ b/contrib/backends/bitcoin/debian/bitcoin-btc.install @@ -0,0 +1 @@ +btc.conf /data/btc/bitcoin diff --git a/contrib/backends/bitcoin/debian/bitcoin-btc.logrotate b/contrib/backends/bitcoin/debian/bitcoin-btc.logrotate new file mode 100644 index 00000000..9f8bd435 --- /dev/null +++ b/contrib/backends/bitcoin/debian/bitcoin-btc.logrotate @@ -0,0 +1,10 @@ +/data/btc/bitcoin/debug.log +/data/btc/bitcoin/db.log +{ + rotate 7 + daily + compress + missingok + notifempty + copytruncate +} diff --git a/contrib/backends/bitcoin/debian/bitcoin-btc.postinst b/contrib/backends/bitcoin/debian/bitcoin-btc.postinst new file mode 100644 index 00000000..e22a02e6 --- /dev/null +++ b/contrib/backends/bitcoin/debian/bitcoin-btc.postinst @@ -0,0 +1,20 @@ +#!/bin/bash +set -e + +case "$1" in + + configure) + if ! id -u bitcoin &> /dev/null + then + useradd --system -M -U bitcoin + fi + + if [ "$(stat -c '%U' /data/btc/bitcoin)" != "bitcoin" ] + then + chown bitcoin:bitcoin /data/btc/bitcoin + fi + ;; + +esac + +#DEBHELPER# diff --git a/contrib/backends/bitcoin/debian/bitcoin-btc.service b/contrib/backends/bitcoin/debian/bitcoin-btc.service new file mode 100644 index 00000000..a8011f6e --- /dev/null +++ b/contrib/backends/bitcoin/debian/bitcoin-btc.service @@ -0,0 +1,44 @@ +# It is not recommended to modify this file in-place, because it will +# be overwritten during package upgrades. If you want to add further +# options or overwrite existing ones then use +# $ systemctl edit bitcoin-btc.service +# See "man systemd.service" for details. + +# Note that almost all daemon options could be specified in +# /data/btc/bitcoin/bitcoin.conf + +[Unit] +Description=Bitcoin daemon (mainnet) +After=network.target + +[Service] +ExecStart=/opt/satoshilabs/bitcoin/bin/bitcoind -datadir=/data/btc/bitcoin -conf=/data/btc/bitcoin/btc.conf -pid=/run/bitcoind/btc.pid +# Creates /run/bitcoind owned by bitcoin +RuntimeDirectory=bitcoind +User=bitcoin +Type=forking +PIDFile=/run/bitcoind/btc.pid +Restart=on-failure + +# Hardening measures +#################### + +# Provide a private /tmp and /var/tmp. +PrivateTmp=true + +# Mount /usr, /boot/ and /etc read-only for the process. +ProtectSystem=full + +# Disallow the process and all of its children to gain +# new privileges through execve(). +NoNewPrivileges=true + +# Use a new /dev namespace only populated with API pseudo devices +# such as /dev/null, /dev/zero and /dev/random. +PrivateDevices=true + +# Deny the creation of writable and executable memory mappings. +MemoryDenyWriteExecute=true + +[Install] +WantedBy=multi-user.target diff --git a/contrib/backends/bitcoin/debian/bitcoin-testnet.conffiles b/contrib/backends/bitcoin/debian/bitcoin-testnet.conffiles new file mode 100644 index 00000000..773374c9 --- /dev/null +++ b/contrib/backends/bitcoin/debian/bitcoin-testnet.conffiles @@ -0,0 +1 @@ +/data/btc-testnet/bitcoin/btc-testnet.conf diff --git a/contrib/backends/bitcoin/debian/bitcoin-testnet.dirs b/contrib/backends/bitcoin/debian/bitcoin-testnet.dirs new file mode 100644 index 00000000..26b686f8 --- /dev/null +++ b/contrib/backends/bitcoin/debian/bitcoin-testnet.dirs @@ -0,0 +1 @@ +/data/btc-testnet/bitcoin diff --git a/contrib/backends/bitcoin/debian/bitcoin-testnet.install b/contrib/backends/bitcoin/debian/bitcoin-testnet.install new file mode 100644 index 00000000..f86f4a4b --- /dev/null +++ b/contrib/backends/bitcoin/debian/bitcoin-testnet.install @@ -0,0 +1 @@ +btc-testnet.conf /data/btc-testnet/bitcoin diff --git a/contrib/backends/bitcoin/debian/bitcoin-testnet.logrotate b/contrib/backends/bitcoin/debian/bitcoin-testnet.logrotate new file mode 100644 index 00000000..f718ec24 --- /dev/null +++ b/contrib/backends/bitcoin/debian/bitcoin-testnet.logrotate @@ -0,0 +1,10 @@ +/data/btc-testnet/bitcoin/testnet3/debug.log +/data/btc-testnet/bitcoin/testnet3/db.log +{ + rotate 7 + daily + compress + missingok + notifempty + copytruncate +} diff --git a/contrib/backends/bitcoin/debian/bitcoin-testnet.postinst b/contrib/backends/bitcoin/debian/bitcoin-testnet.postinst new file mode 100644 index 00000000..ebadd9ae --- /dev/null +++ b/contrib/backends/bitcoin/debian/bitcoin-testnet.postinst @@ -0,0 +1,20 @@ +#!/bin/bash +set -e + +case "$1" in + + configure) + if ! id -u bitcoin &> /dev/null + then + useradd --system -M -U bitcoin + fi + + if [ "$(stat -c '%U' /data/btc-testnet/bitcoin)" != "bitcoin" ] + then + chown bitcoin:bitcoin /data/btc-testnet/bitcoin + fi + ;; + +esac + +#DEBHELPER# diff --git a/contrib/backends/bitcoin/debian/bitcoin-testnet.service b/contrib/backends/bitcoin/debian/bitcoin-testnet.service new file mode 100644 index 00000000..0f4080b2 --- /dev/null +++ b/contrib/backends/bitcoin/debian/bitcoin-testnet.service @@ -0,0 +1,44 @@ +# It is not recommended to modify this file in-place, because it will +# be overwritten during package upgrades. If you want to add further +# options or overwrite existing ones then use +# $ systemctl edit bitcoin-testnet.service +# See "man systemd.service" for details. + +# Note that almost all daemon options could be specified in +# /data/btc-testnet/bitcoin/bitcoin.conf + +[Unit] +Description=Bitcoin daemon (testnet) +After=network.target + +[Service] +ExecStart=/opt/satoshilabs/bitcoin/bin/bitcoind -datadir=/data/btc-testnet/bitcoin -conf=/data/btc-testnet/bitcoin/btc-testnet.conf -pid=/run/bitcoind/testnet.pid +# Creates /run/bitcoind owned by bitcoin +RuntimeDirectory=bitcoind +User=bitcoin +Type=forking +PIDFile=/run/bitcoind/testnet.pid +Restart=on-failure + +# Hardening measures +#################### + +# Provide a private /tmp and /var/tmp. +PrivateTmp=true + +# Mount /usr, /boot/ and /etc read-only for the process. +ProtectSystem=full + +# Disallow the process and all of its children to gain +# new privileges through execve(). +NoNewPrivileges=true + +# Use a new /dev namespace only populated with API pseudo devices +# such as /dev/null, /dev/zero and /dev/random. +PrivateDevices=true + +# Deny the creation of writable and executable memory mappings. +MemoryDenyWriteExecute=true + +[Install] +WantedBy=multi-user.target diff --git a/contrib/backends/bitcoin/debian/bitcoin.install b/contrib/backends/bitcoin/debian/bitcoin.install new file mode 100644 index 00000000..204eafa1 --- /dev/null +++ b/contrib/backends/bitcoin/debian/bitcoin.install @@ -0,0 +1 @@ +bitcoin /opt/satoshilabs diff --git a/contrib/backends/bitcoin/debian/bitcoin.links b/contrib/backends/bitcoin/debian/bitcoin.links new file mode 100644 index 00000000..a8af3c05 --- /dev/null +++ b/contrib/backends/bitcoin/debian/bitcoin.links @@ -0,0 +1,2 @@ +/opt/satoshilabs/bitcoin/bin/bitcoind /usr/bin/bitcoind +/opt/satoshilabs/bitcoin/bin/bitcoin-cli /usr/bin/bitcoin-cli diff --git a/contrib/backends/bitcoin/debian/changelog b/contrib/backends/bitcoin/debian/changelog new file mode 100644 index 00000000..cdfa9ad8 --- /dev/null +++ b/contrib/backends/bitcoin/debian/changelog @@ -0,0 +1,5 @@ +bitcoin (0.16.0-satoshilabs1) unstable; urgency=medium + + * Initial build + + -- Jakub Matys Thu, 05 Apr 2018 08:40:39 +0200 diff --git a/contrib/backends/bitcoin/debian/compat b/contrib/backends/bitcoin/debian/compat new file mode 100644 index 00000000..ec635144 --- /dev/null +++ b/contrib/backends/bitcoin/debian/compat @@ -0,0 +1 @@ +9 diff --git a/contrib/backends/bitcoin/debian/control b/contrib/backends/bitcoin/debian/control new file mode 100644 index 00000000..d1f7f143 --- /dev/null +++ b/contrib/backends/bitcoin/debian/control @@ -0,0 +1,21 @@ +Source: bitcoin +Section: satoshilabs +Priority: optional +Maintainer: jakub.matys@satoshilabs.com +Build-Depends: debhelper, wget, tar, gzip, make, dh-systemd +Standards-Version: 3.9.5 + +Package: bitcoin +Architecture: amd64 +Depends: ${shlibs:Depends}, ${misc:Depends} +Description: Satoshilabs packaged bitcoin server (binaries) + +Package: bitcoin-btc +Architecture: all +Depends: bitcoin (= ${binary:Version}), logrotate +Description: Satoshilabs packaged bitcoin server (configuration) + +Package: bitcoin-testnet +Architecture: all +Depends: bitcoin (= ${binary:Version}), logrotate +Description: Satoshilabs packaged bitcoin server (configuration) diff --git a/contrib/backends/bitcoin/debian/rules b/contrib/backends/bitcoin/debian/rules new file mode 100755 index 00000000..e9b6951b --- /dev/null +++ b/contrib/backends/bitcoin/debian/rules @@ -0,0 +1,6 @@ +#!/usr/bin/make -f + +DH_VERBOSE = 1 + +%: + dh $@ --with=systemd diff --git a/contrib/backends/docker/Dockerfile b/contrib/backends/docker/Dockerfile new file mode 100644 index 00000000..75e94805 --- /dev/null +++ b/contrib/backends/docker/Dockerfile @@ -0,0 +1,13 @@ +FROM debian:9 + +ENV DEBIAN_FRONTEND noninteractive + +RUN apt-get update && \ + apt-get install -y devscripts debhelper wget tar gzip make dh-systemd && \ + apt-get clean + +ADD build.sh /deb/build.sh + +WORKDIR /deb + +ENTRYPOINT ["/deb/build.sh"] diff --git a/contrib/backends/docker/build.sh b/contrib/backends/docker/build.sh new file mode 100755 index 00000000..8402eb7e --- /dev/null +++ b/contrib/backends/docker/build.sh @@ -0,0 +1,15 @@ +#!/bin/bash +set -e + +if [ $# -ne 1 ] +then + echo "Usage: $(basename $0) target" > /dev/stderr + exit 1 +fi + +cd $1 + +mk-build-deps -ir -t "apt-get -qq --no-install-recommends" +dpkg-buildpackage -us -uc +mv ../*.deb . +chown $PACKAGER *.deb diff --git a/contrib/backends/zcash/Makefile b/contrib/backends/zcash/Makefile new file mode 100644 index 00000000..02b06991 --- /dev/null +++ b/contrib/backends/zcash/Makefile @@ -0,0 +1,11 @@ +ZCASH_VERSION := 1.0.15 + +all: + wget https://z.cash/downloads/zcash-${ZCASH_VERSION}-linux64.tar.gz + tar -xf zcash-${ZCASH_VERSION}-linux64.tar.gz + mv zcash-${ZCASH_VERSION} zcash + rm zcash/bin/zcash-tx + +clean: + rm -rf zcash + rm -f zcash-${ZCASH_VERSION}-linux64.tar.gz* diff --git a/contrib/backends/zcash/debian/changelog b/contrib/backends/zcash/debian/changelog new file mode 100644 index 00000000..6f9495d0 --- /dev/null +++ b/contrib/backends/zcash/debian/changelog @@ -0,0 +1,5 @@ +zcash (1.0.15-satoshilabs1) unstable; urgency=medium + + * Initial build + + -- Jakub Matys Thu, 05 Apr 2018 08:40:39 +0200 diff --git a/contrib/backends/zcash/debian/compat b/contrib/backends/zcash/debian/compat new file mode 100644 index 00000000..ec635144 --- /dev/null +++ b/contrib/backends/zcash/debian/compat @@ -0,0 +1 @@ +9 diff --git a/contrib/backends/zcash/debian/control b/contrib/backends/zcash/debian/control new file mode 100644 index 00000000..1352372f --- /dev/null +++ b/contrib/backends/zcash/debian/control @@ -0,0 +1,16 @@ +Source: zcash +Section: satoshilabs +Priority: optional +Maintainer: jakub.matys@satoshilabs.com +Build-Depends: debhelper, wget, tar, gzip, make, dh-systemd +Standards-Version: 3.9.5 + +Package: zcash +Architecture: amd64 +Depends: ${shlibs:Depends}, ${misc:Depends} +Description: Satoshilabs packaged zcash server (binaries) + +Package: zcash-zec +Architecture: all +Depends: zcash (= ${binary:Version}), logrotate +Description: Satoshilabs packaged zcash server (configuration) diff --git a/contrib/backends/zcash/debian/rules b/contrib/backends/zcash/debian/rules new file mode 100755 index 00000000..e9b6951b --- /dev/null +++ b/contrib/backends/zcash/debian/rules @@ -0,0 +1,6 @@ +#!/usr/bin/make -f + +DH_VERBOSE = 1 + +%: + dh $@ --with=systemd diff --git a/contrib/backends/zcash/debian/zcash-zec.conffiles b/contrib/backends/zcash/debian/zcash-zec.conffiles new file mode 100644 index 00000000..e8d03862 --- /dev/null +++ b/contrib/backends/zcash/debian/zcash-zec.conffiles @@ -0,0 +1 @@ +/data/zec/zcash/zec.conf diff --git a/contrib/backends/zcash/debian/zcash-zec.dirs b/contrib/backends/zcash/debian/zcash-zec.dirs new file mode 100644 index 00000000..5f8be1f2 --- /dev/null +++ b/contrib/backends/zcash/debian/zcash-zec.dirs @@ -0,0 +1 @@ +/data/zec/zcash diff --git a/contrib/backends/zcash/debian/zcash-zec.install b/contrib/backends/zcash/debian/zcash-zec.install new file mode 100644 index 00000000..60fa4360 --- /dev/null +++ b/contrib/backends/zcash/debian/zcash-zec.install @@ -0,0 +1 @@ +zec.conf /data/zec/zcash diff --git a/contrib/backends/zcash/debian/zcash-zec.logrotate b/contrib/backends/zcash/debian/zcash-zec.logrotate new file mode 100644 index 00000000..536cdeab --- /dev/null +++ b/contrib/backends/zcash/debian/zcash-zec.logrotate @@ -0,0 +1,10 @@ +/data/zec/zcash/debug.log +/data/zec/zcash/db.log +{ + rotate 7 + daily + compress + missingok + notifempty + copytruncate +} diff --git a/contrib/backends/zcash/debian/zcash-zec.postinst b/contrib/backends/zcash/debian/zcash-zec.postinst new file mode 100644 index 00000000..144fec21 --- /dev/null +++ b/contrib/backends/zcash/debian/zcash-zec.postinst @@ -0,0 +1,22 @@ +#!/bin/bash +set -e + +case "$1" in + + configure) + if ! id -u zcash &> /dev/null + then + useradd --system -M -U zcash + fi + + if [ "$(stat -c '%U' /data/zec/zcash)" != "zcash" ] + then + chown zcash:zcash /data/zec/zcash + fi + + HOME=/data/zec/zcash /opt/satoshilabs/zcash/bin/zcash-fetch-params + ;; + +esac + +#DEBHELPER# diff --git a/contrib/backends/zcash/debian/zcash-zec.service b/contrib/backends/zcash/debian/zcash-zec.service new file mode 100644 index 00000000..6eb81110 --- /dev/null +++ b/contrib/backends/zcash/debian/zcash-zec.service @@ -0,0 +1,44 @@ +# It is not recommended to modify this file in-place, because it will +# be overwritten during package upgrades. If you want to add further +# options or overwrite existing ones then use +# $ systemctl edit zcash-zec.service +# See "man systemd.service" for details. + +# Note that almost all daemon options could be specified in +# /data/zec/zcash/zcash.conf + +[Unit] +Description=ZCash daemon (mainnet) +After=network.target + +[Service] +ExecStart=/opt/satoshilabs/zcash/bin/zcashd -datadir=/data/zec/zcash -conf=/data/zec/zcash/zec.conf -pid=/run/zcashd/zec.pid +# Creates /run/zcashd owned by zcash +RuntimeDirectory=zcashd +User=zcash +Type=forking +PIDFile=/run/zcashd/zec.pid +Restart=on-failure + +# Hardening measures +#################### + +# Provide a private /tmp and /var/tmp. +PrivateTmp=true + +# Mount /usr, /boot/ and /etc read-only for the process. +ProtectSystem=full + +# Disallow the process and all of its children to gain +# new privileges through execve(). +NoNewPrivileges=true + +# Use a new /dev namespace only populated with API pseudo devices +# such as /dev/null, /dev/zero and /dev/random. +PrivateDevices=true + +# Deny the creation of writable and executable memory mappings. +MemoryDenyWriteExecute=true + +[Install] +WantedBy=multi-user.target diff --git a/contrib/backends/zcash/debian/zcash.install b/contrib/backends/zcash/debian/zcash.install new file mode 100644 index 00000000..f1f0f6bc --- /dev/null +++ b/contrib/backends/zcash/debian/zcash.install @@ -0,0 +1 @@ +zcash /opt/satoshilabs diff --git a/contrib/backends/zcash/debian/zcash.links b/contrib/backends/zcash/debian/zcash.links new file mode 100644 index 00000000..9a1efd8d --- /dev/null +++ b/contrib/backends/zcash/debian/zcash.links @@ -0,0 +1,2 @@ +/opt/satoshilabs/zcash/bin/zcashd /usr/bin/zcashd +/opt/satoshilabs/zcash/bin/zcash-cli /usr/bin/zcash-cli diff --git a/contrib/backends/zcash/zec.conf b/contrib/backends/zcash/zec.conf new file mode 100644 index 00000000..7498f754 --- /dev/null +++ b/contrib/backends/zcash/zec.conf @@ -0,0 +1,13 @@ +daemon=1 +server=1 +rpcuser=rpc +rpcpassword=rpc +rpcport=8232 +txindex=1 +mainnet=1 +addnode=mainnet.z.cash +rpcworkqueue=32 +zmqpubhashtx=tcp://127.0.0.1:8234 +zmqpubhashblock=tcp://127.0.0.1:8234 +zmqpubrawblock=tcp://127.0.0.1:8234 +zmqpubrawtx=tcp://127.0.0.1:8234 From 1e39faa6b62532a789269aab8d0dfa893c749dcb Mon Sep 17 00:00:00 2001 From: Jakub Matys Date: Wed, 11 Apr 2018 12:49:24 +0200 Subject: [PATCH 4/9] remove installed packages from cache --- build/bin/Dockerfile | 8 +++++--- build/deb/Dockerfile | 5 +++-- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/build/bin/Dockerfile b/build/bin/Dockerfile index d3429cad..0317e72f 100644 --- a/build/bin/Dockerfile +++ b/build/bin/Dockerfile @@ -2,9 +2,11 @@ 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 upx-ucl +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 upx-ucl && \ + apt-get clean ENV GOLANG_VERSION=go1.10.linux-amd64 ENV GOPATH=/go diff --git a/build/deb/Dockerfile b/build/deb/Dockerfile index 5782d98b..bb0f3d56 100644 --- a/build/deb/Dockerfile +++ b/build/deb/Dockerfile @@ -2,8 +2,9 @@ FROM blockbook-build:latest -RUN apt-get update && apt-get install -y \ - devscripts debhelper make dh-systemd dh-exec +RUN apt-get update && \ + apt-get install -y devscripts debhelper make dh-systemd dh-exec && \ + apt-get clean ADD build-deb.sh /build/build-deb.sh From cf27ed086b0e2e9d008be5e6ed43f61fdbfb2d6d Mon Sep 17 00:00:00 2001 From: Jakub Matys Date: Wed, 11 Apr 2018 12:50:13 +0200 Subject: [PATCH 5/9] fixed command for image build --- contrib/backends/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contrib/backends/Makefile b/contrib/backends/Makefile index 819b0d4a..1d3e964c 100644 --- a/contrib/backends/Makefile +++ b/contrib/backends/Makefile @@ -15,7 +15,7 @@ build-image: $(MAKE) .docker-image .docker-image: - docker build --no-cache=$(NO_CACHE)-t $(IMAGE) docker + docker build --no-cache=$(NO_CACHE) -t $(IMAGE) docker @ docker images -q $(IMAGE) > $@ clean: clean-packages clean-image From 6c1e114074f6f43082dc8bc7c94574bb63852cf5 Mon Sep 17 00:00:00 2001 From: Jakub Matys Date: Wed, 11 Apr 2018 12:51:38 +0200 Subject: [PATCH 6/9] backend binaries and configs are installed to dedicated directories --- .../bitcoin/debian/bitcoin-btc.conffiles | 2 +- .../bitcoin/debian/bitcoin-btc.install | 3 ++- .../bitcoin/debian/bitcoin-btc.service | 4 ++-- .../bitcoin/debian/bitcoin-testnet.conffiles | 2 +- .../bitcoin/debian/bitcoin-testnet.install | 3 ++- .../bitcoin/debian/bitcoin-testnet.service | 4 ++-- .../backends/bitcoin/debian/bitcoin.install | 1 - contrib/backends/bitcoin/debian/bitcoin.links | 2 -- contrib/backends/bitcoin/debian/control | 19 +++++++------------ contrib/backends/zcash/debian/control | 13 ++++--------- .../backends/zcash/debian/zcash-zec.conffiles | 2 +- .../backends/zcash/debian/zcash-zec.install | 3 ++- .../backends/zcash/debian/zcash-zec.postinst | 2 +- .../backends/zcash/debian/zcash-zec.service | 7 ++++--- contrib/backends/zcash/debian/zcash.install | 1 - contrib/backends/zcash/debian/zcash.links | 2 -- 16 files changed, 29 insertions(+), 41 deletions(-) delete mode 100644 contrib/backends/bitcoin/debian/bitcoin.install delete mode 100644 contrib/backends/bitcoin/debian/bitcoin.links delete mode 100644 contrib/backends/zcash/debian/zcash.install delete mode 100644 contrib/backends/zcash/debian/zcash.links diff --git a/contrib/backends/bitcoin/debian/bitcoin-btc.conffiles b/contrib/backends/bitcoin/debian/bitcoin-btc.conffiles index 186137f2..d18f88ce 100644 --- a/contrib/backends/bitcoin/debian/bitcoin-btc.conffiles +++ b/contrib/backends/bitcoin/debian/bitcoin-btc.conffiles @@ -1 +1 @@ -/data/btc/bitcoin/btc.conf +/opt/bitcoin/btc/btc.conf diff --git a/contrib/backends/bitcoin/debian/bitcoin-btc.install b/contrib/backends/bitcoin/debian/bitcoin-btc.install index 4d959fa5..fe2df203 100644 --- a/contrib/backends/bitcoin/debian/bitcoin-btc.install +++ b/contrib/backends/bitcoin/debian/bitcoin-btc.install @@ -1 +1,2 @@ -btc.conf /data/btc/bitcoin +bitcoin/* /opt/bitcoin/btc +btc.conf /opt/bitcoin/btc diff --git a/contrib/backends/bitcoin/debian/bitcoin-btc.service b/contrib/backends/bitcoin/debian/bitcoin-btc.service index a8011f6e..25f02d8e 100644 --- a/contrib/backends/bitcoin/debian/bitcoin-btc.service +++ b/contrib/backends/bitcoin/debian/bitcoin-btc.service @@ -5,14 +5,14 @@ # See "man systemd.service" for details. # Note that almost all daemon options could be specified in -# /data/btc/bitcoin/bitcoin.conf +# /opt/bitcoin/btc/btc.conf [Unit] Description=Bitcoin daemon (mainnet) After=network.target [Service] -ExecStart=/opt/satoshilabs/bitcoin/bin/bitcoind -datadir=/data/btc/bitcoin -conf=/data/btc/bitcoin/btc.conf -pid=/run/bitcoind/btc.pid +ExecStart=/opt/bitcoin/btc/bin/bitcoind -datadir=/data/btc/bitcoin -conf=/opt/bitcoin/btc/btc.conf -pid=/run/bitcoind/btc.pid # Creates /run/bitcoind owned by bitcoin RuntimeDirectory=bitcoind User=bitcoin diff --git a/contrib/backends/bitcoin/debian/bitcoin-testnet.conffiles b/contrib/backends/bitcoin/debian/bitcoin-testnet.conffiles index 773374c9..2f410641 100644 --- a/contrib/backends/bitcoin/debian/bitcoin-testnet.conffiles +++ b/contrib/backends/bitcoin/debian/bitcoin-testnet.conffiles @@ -1 +1 @@ -/data/btc-testnet/bitcoin/btc-testnet.conf +/opt/bitcoin/btc-testnet/btc-testnet.conf diff --git a/contrib/backends/bitcoin/debian/bitcoin-testnet.install b/contrib/backends/bitcoin/debian/bitcoin-testnet.install index f86f4a4b..a9124874 100644 --- a/contrib/backends/bitcoin/debian/bitcoin-testnet.install +++ b/contrib/backends/bitcoin/debian/bitcoin-testnet.install @@ -1 +1,2 @@ -btc-testnet.conf /data/btc-testnet/bitcoin +bitcoin/* /opt/bitcoin/btc-testnet +btc-testnet.conf /opt/bitcoin/btc-testnet diff --git a/contrib/backends/bitcoin/debian/bitcoin-testnet.service b/contrib/backends/bitcoin/debian/bitcoin-testnet.service index 0f4080b2..431fe84d 100644 --- a/contrib/backends/bitcoin/debian/bitcoin-testnet.service +++ b/contrib/backends/bitcoin/debian/bitcoin-testnet.service @@ -5,14 +5,14 @@ # See "man systemd.service" for details. # Note that almost all daemon options could be specified in -# /data/btc-testnet/bitcoin/bitcoin.conf +# /opt/bitcoin/btc-testnet/btc-testnet.conf [Unit] Description=Bitcoin daemon (testnet) After=network.target [Service] -ExecStart=/opt/satoshilabs/bitcoin/bin/bitcoind -datadir=/data/btc-testnet/bitcoin -conf=/data/btc-testnet/bitcoin/btc-testnet.conf -pid=/run/bitcoind/testnet.pid +ExecStart=/opt/bitcoin/btc-testnet/bin/bitcoind -datadir=/data/btc-testnet/bitcoin -conf=/opt/bitcoin/btc-testnet/btc-testnet.conf -pid=/run/bitcoind/testnet.pid # Creates /run/bitcoind owned by bitcoin RuntimeDirectory=bitcoind User=bitcoin diff --git a/contrib/backends/bitcoin/debian/bitcoin.install b/contrib/backends/bitcoin/debian/bitcoin.install deleted file mode 100644 index 204eafa1..00000000 --- a/contrib/backends/bitcoin/debian/bitcoin.install +++ /dev/null @@ -1 +0,0 @@ -bitcoin /opt/satoshilabs diff --git a/contrib/backends/bitcoin/debian/bitcoin.links b/contrib/backends/bitcoin/debian/bitcoin.links deleted file mode 100644 index a8af3c05..00000000 --- a/contrib/backends/bitcoin/debian/bitcoin.links +++ /dev/null @@ -1,2 +0,0 @@ -/opt/satoshilabs/bitcoin/bin/bitcoind /usr/bin/bitcoind -/opt/satoshilabs/bitcoin/bin/bitcoin-cli /usr/bin/bitcoin-cli diff --git a/contrib/backends/bitcoin/debian/control b/contrib/backends/bitcoin/debian/control index d1f7f143..b53f5d77 100644 --- a/contrib/backends/bitcoin/debian/control +++ b/contrib/backends/bitcoin/debian/control @@ -2,20 +2,15 @@ Source: bitcoin Section: satoshilabs Priority: optional Maintainer: jakub.matys@satoshilabs.com -Build-Depends: debhelper, wget, tar, gzip, make, dh-systemd +Build-Depends: debhelper, wget, tar, gzip, make, dh-systemd, dh-exec Standards-Version: 3.9.5 -Package: bitcoin -Architecture: amd64 -Depends: ${shlibs:Depends}, ${misc:Depends} -Description: Satoshilabs packaged bitcoin server (binaries) - Package: bitcoin-btc -Architecture: all -Depends: bitcoin (= ${binary:Version}), logrotate -Description: Satoshilabs packaged bitcoin server (configuration) +Architecture: amd64 +Depends: ${shlibs:Depends}, ${misc:Depends}, logrotate +Description: Satoshilabs packaged bitcoin server Package: bitcoin-testnet -Architecture: all -Depends: bitcoin (= ${binary:Version}), logrotate -Description: Satoshilabs packaged bitcoin server (configuration) +Architecture: amd64 +Depends: ${shlibs:Depends}, ${misc:Depends}, logrotate +Description: Satoshilabs packaged bitcoin server diff --git a/contrib/backends/zcash/debian/control b/contrib/backends/zcash/debian/control index 1352372f..1f6e861c 100644 --- a/contrib/backends/zcash/debian/control +++ b/contrib/backends/zcash/debian/control @@ -2,15 +2,10 @@ Source: zcash Section: satoshilabs Priority: optional Maintainer: jakub.matys@satoshilabs.com -Build-Depends: debhelper, wget, tar, gzip, make, dh-systemd +Build-Depends: debhelper, wget, tar, gzip, make, dh-systemd, dh-exec Standards-Version: 3.9.5 -Package: zcash -Architecture: amd64 -Depends: ${shlibs:Depends}, ${misc:Depends} -Description: Satoshilabs packaged zcash server (binaries) - Package: zcash-zec -Architecture: all -Depends: zcash (= ${binary:Version}), logrotate -Description: Satoshilabs packaged zcash server (configuration) +Architecture: amd64 +Depends: ${shlibs:Depends}, ${misc:Depends}, logrotate +Description: Satoshilabs packaged zcash server diff --git a/contrib/backends/zcash/debian/zcash-zec.conffiles b/contrib/backends/zcash/debian/zcash-zec.conffiles index e8d03862..b67eba29 100644 --- a/contrib/backends/zcash/debian/zcash-zec.conffiles +++ b/contrib/backends/zcash/debian/zcash-zec.conffiles @@ -1 +1 @@ -/data/zec/zcash/zec.conf +/opt/zcash/zec/zec.conf diff --git a/contrib/backends/zcash/debian/zcash-zec.install b/contrib/backends/zcash/debian/zcash-zec.install index 60fa4360..0bdf2442 100644 --- a/contrib/backends/zcash/debian/zcash-zec.install +++ b/contrib/backends/zcash/debian/zcash-zec.install @@ -1 +1,2 @@ -zec.conf /data/zec/zcash +zcash/* /opt/zcash/zec +zec.conf /opt/zcash/zec diff --git a/contrib/backends/zcash/debian/zcash-zec.postinst b/contrib/backends/zcash/debian/zcash-zec.postinst index 144fec21..4ca85d19 100644 --- a/contrib/backends/zcash/debian/zcash-zec.postinst +++ b/contrib/backends/zcash/debian/zcash-zec.postinst @@ -14,7 +14,7 @@ case "$1" in chown zcash:zcash /data/zec/zcash fi - HOME=/data/zec/zcash /opt/satoshilabs/zcash/bin/zcash-fetch-params + HOME=/data/zec/zcash /opt/zcash/zec/bin/zcash-fetch-params ;; esac diff --git a/contrib/backends/zcash/debian/zcash-zec.service b/contrib/backends/zcash/debian/zcash-zec.service index 6eb81110..a232480d 100644 --- a/contrib/backends/zcash/debian/zcash-zec.service +++ b/contrib/backends/zcash/debian/zcash-zec.service @@ -5,14 +5,15 @@ # See "man systemd.service" for details. # Note that almost all daemon options could be specified in -# /data/zec/zcash/zcash.conf +# /opt/zcash/zec/zec.conf [Unit] Description=ZCash daemon (mainnet) After=network.target [Service] -ExecStart=/opt/satoshilabs/zcash/bin/zcashd -datadir=/data/zec/zcash -conf=/data/zec/zcash/zec.conf -pid=/run/zcashd/zec.pid +Environment="HOME=/data/zec/zcash" +ExecStart=/opt/zcash/zec/bin/zcashd -datadir=/data/zec/zcash -conf=/opt/zcash/zec/zec.conf -pid=/run/zcashd/zec.pid # Creates /run/zcashd owned by zcash RuntimeDirectory=zcashd User=zcash @@ -38,7 +39,7 @@ NoNewPrivileges=true PrivateDevices=true # Deny the creation of writable and executable memory mappings. -MemoryDenyWriteExecute=true +# MemoryDenyWriteExecute=true [Install] WantedBy=multi-user.target diff --git a/contrib/backends/zcash/debian/zcash.install b/contrib/backends/zcash/debian/zcash.install deleted file mode 100644 index f1f0f6bc..00000000 --- a/contrib/backends/zcash/debian/zcash.install +++ /dev/null @@ -1 +0,0 @@ -zcash /opt/satoshilabs diff --git a/contrib/backends/zcash/debian/zcash.links b/contrib/backends/zcash/debian/zcash.links deleted file mode 100644 index 9a1efd8d..00000000 --- a/contrib/backends/zcash/debian/zcash.links +++ /dev/null @@ -1,2 +0,0 @@ -/opt/satoshilabs/zcash/bin/zcashd /usr/bin/zcashd -/opt/satoshilabs/zcash/bin/zcash-cli /usr/bin/zcash-cli From a37ccdaee0dc2ccc6cc233c6990d1609e0961b88 Mon Sep 17 00:00:00 2001 From: Jakub Matys Date: Thu, 12 Apr 2018 15:23:16 +0200 Subject: [PATCH 7/9] fixed logging --- blockbook.go | 8 +++++--- build/bin/Dockerfile | 2 +- build/bin/Makefile | 1 - build/deb/build-deb.sh | 2 +- build/deb/debian/blockbook-btc-testnet.install | 1 + build/deb/debian/blockbook-btc-testnet.logrotate | 9 --------- build/deb/debian/blockbook-btc-testnet.postinst | 11 +++++++---- build/deb/debian/blockbook-btc-testnet.service | 10 +++------- build/deb/debian/blockbook-btc.install | 1 + build/deb/debian/blockbook-btc.logrotate | 9 --------- build/deb/debian/blockbook-btc.postinst | 11 +++++++---- build/deb/debian/blockbook-btc.service | 10 +++------- build/deb/debian/blockbook-zec.install | 1 + build/deb/debian/blockbook-zec.logrotate | 9 --------- build/deb/debian/blockbook-zec.postinst | 11 +++++++---- build/deb/debian/blockbook-zec.service | 10 +++------- build/deb/debian/control | 8 ++++---- server/https.go | 11 +++-------- server/socketio.go | 2 +- 19 files changed, 48 insertions(+), 79 deletions(-) delete mode 100644 build/deb/debian/blockbook-btc-testnet.logrotate delete mode 100644 build/deb/debian/blockbook-btc.logrotate delete mode 100644 build/deb/debian/blockbook-zec.logrotate diff --git a/blockbook.go b/blockbook.go index 280f61ba..9df288f1 100644 --- a/blockbook.go +++ b/blockbook.go @@ -79,12 +79,14 @@ var ( chanOsSignal chan os.Signal ) +func init() { + glog.MaxSize = 1024 * 1024 + glog.CopyStandardLogTo("INFO") +} + func main() { flag.Parse() - // override setting for glog to log only to stderr, to match the http handler - flag.Lookup("logtostderr").Value.Set("true") - defer glog.Flush() chanOsSignal = make(chan os.Signal, 1) diff --git a/build/bin/Dockerfile b/build/bin/Dockerfile index 0317e72f..a84074e2 100644 --- a/build/bin/Dockerfile +++ b/build/bin/Dockerfile @@ -5,7 +5,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 upx-ucl && \ + liblz4-dev graphviz && \ apt-get clean ENV GOLANG_VERSION=go1.10.linux-amd64 diff --git a/build/bin/Makefile b/build/bin/Makefile index 74f8a2f9..3bdee2f5 100644 --- a/build/bin/Makefile +++ b/build/bin/Makefile @@ -1,6 +1,5 @@ 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 diff --git a/build/deb/build-deb.sh b/build/deb/build-deb.sh index 0c064954..21aabdde 100755 --- a/build/deb/build-deb.sh +++ b/build/deb/build-deb.sh @@ -3,7 +3,7 @@ set -e cp -r /src/build/deb/debian . cp -r /src/configs . -mkdir server && cp /src/server/testcert.* server +mkdir server && cp -r /src/server/testcert.* /src/server/static server dpkg-buildpackage -us -uc mv ../*.deb /out diff --git a/build/deb/debian/blockbook-btc-testnet.install b/build/deb/debian/blockbook-btc-testnet.install index 58ed0672..cc143232 100755 --- a/build/deb/debian/blockbook-btc-testnet.install +++ b/build/deb/debian/blockbook-btc-testnet.install @@ -1,4 +1,5 @@ #!/usr/bin/dh-exec blockbook /opt/blockbook/btc-testnet/bin server/testcert.* /opt/blockbook/btc-testnet/cert +server/static /opt/blockbook/btc-testnet configs/btc-testnet.json => /opt/blockbook/btc-testnet/config/blockchaincfg.json diff --git a/build/deb/debian/blockbook-btc-testnet.logrotate b/build/deb/debian/blockbook-btc-testnet.logrotate deleted file mode 100644 index 624d120b..00000000 --- a/build/deb/debian/blockbook-btc-testnet.logrotate +++ /dev/null @@ -1,9 +0,0 @@ -/opt/blockbook/btc-testnet/logs/blockbook.log -{ - rotate 7 - daily - compress - missingok - notifempty - copytruncate -} diff --git a/build/deb/debian/blockbook-btc-testnet.postinst b/build/deb/debian/blockbook-btc-testnet.postinst index 9f310abc..f7bfccbc 100644 --- a/build/deb/debian/blockbook-btc-testnet.postinst +++ b/build/deb/debian/blockbook-btc-testnet.postinst @@ -9,10 +9,13 @@ case "$1" in useradd --system -M -U blockbook fi - if [ "$(stat -c '%U' /data/btc-testnet/blockbook)" != "blockbook" ] - then - chown -R blockbook:blockbook /data/btc-testnet/blockbook - fi + for dir in /data/btc-testnet/blockbook /opt/blockbook/btc-testnet/logs + do + if [ "$(stat -c '%U' $dir)" != "blockbook" ] + then + chown -R blockbook:blockbook $dir + fi + done ;; esac diff --git a/build/deb/debian/blockbook-btc-testnet.service b/build/deb/debian/blockbook-btc-testnet.service index ab84d20a..38fa52ad 100644 --- a/build/deb/debian/blockbook-btc-testnet.service +++ b/build/deb/debian/blockbook-btc-testnet.service @@ -9,15 +9,11 @@ Description=Blockbook daemon (BTC testnet) After=network.target [Service] -ExecStart=/opt/blockbook/btc-testnet/bin/blockbook -coin=btc-testnet -blockchaincfg=/opt/blockbook/btc-testnet/config/blockchaincfg.json -datadir=/data/btc-testnet/blockbook/db -sync -httpserver=:18335 -socketio=:18336 -certfile=/opt/blockbook/btc-testnet/cert/blockbook -explorer=https://bitcore1.trezor.io/ -# Creates /run/blockbook owned by blockbook -RuntimeDirectory=blockbook +ExecStart=/opt/blockbook/btc-testnet/bin/blockbook -coin=btc-testnet -blockchaincfg=/opt/blockbook/btc-testnet/config/blockchaincfg.json -datadir=/data/btc-testnet/blockbook/db -sync -httpserver=:18335 -socketio=:18336 -certfile=/opt/blockbook/btc-testnet/cert/blockbook -explorer=https://bitcore1.trezor.io/ -log_dir=/opt/blockbook/btc-testnet/logs User=blockbook -# Type=forking -# PIDFile=/run/bitcoind/btc-testnet.pid +Type=simple Restart=on-failure -StandardOutput=file:/opt/blockbook/btc-testnet/logs/blockbook.log -StandardError=file:/opt/blockbook/btc-testnet/logs/blockbook.log +WorkingDirectory=/opt/blockbook/btc-testnet # Hardening measures #################### diff --git a/build/deb/debian/blockbook-btc.install b/build/deb/debian/blockbook-btc.install index fb662d95..29961515 100755 --- a/build/deb/debian/blockbook-btc.install +++ b/build/deb/debian/blockbook-btc.install @@ -1,4 +1,5 @@ #!/usr/bin/dh-exec blockbook /opt/blockbook/btc/bin server/testcert.* /opt/blockbook/btc/cert +server/static /opt/blockbook/btc configs/btc.json => /opt/blockbook/btc/config/blockchaincfg.json diff --git a/build/deb/debian/blockbook-btc.logrotate b/build/deb/debian/blockbook-btc.logrotate deleted file mode 100644 index 16b1f999..00000000 --- a/build/deb/debian/blockbook-btc.logrotate +++ /dev/null @@ -1,9 +0,0 @@ -/opt/blockbook/btc/logs/blockbook.log -{ - rotate 7 - daily - compress - missingok - notifempty - copytruncate -} diff --git a/build/deb/debian/blockbook-btc.postinst b/build/deb/debian/blockbook-btc.postinst index 721e99f6..29b2c0fd 100644 --- a/build/deb/debian/blockbook-btc.postinst +++ b/build/deb/debian/blockbook-btc.postinst @@ -9,10 +9,13 @@ case "$1" in useradd --system -M -U blockbook fi - if [ "$(stat -c '%U' /data/btc/blockbook)" != "blockbook" ] - then - chown -R blockbook:blockbook /data/btc/blockbook - fi + for dir in /data/btc/blockbook /opt/blockbook/btc/logs + do + if [ "$(stat -c '%U' $dir)" != "blockbook" ] + then + chown -R blockbook:blockbook $dir + fi + done ;; esac diff --git a/build/deb/debian/blockbook-btc.service b/build/deb/debian/blockbook-btc.service index e5cf847a..4eaad785 100644 --- a/build/deb/debian/blockbook-btc.service +++ b/build/deb/debian/blockbook-btc.service @@ -9,15 +9,11 @@ Description=Blockbook daemon (BTC mainnet) After=network.target [Service] -ExecStart=/opt/blockbook/btc/bin/blockbook -coin=btc -blockchaincfg=/opt/blockbook/btc/config/blockchaincfg.json -datadir=/data/btc/blockbook/db -sync -httpserver=:8335 -socketio=:8336 -certfile=/opt/blockbook/btc/cert/blockbook -explorer=https://bitcore1.trezor.io/ -# Creates /run/blockbook owned by blockbook -RuntimeDirectory=blockbook +ExecStart=/opt/blockbook/btc/bin/blockbook -coin=btc -blockchaincfg=/opt/blockbook/btc/config/blockchaincfg.json -datadir=/data/btc/blockbook/db -sync -httpserver=:8335 -socketio=:8336 -certfile=/opt/blockbook/btc/cert/blockbook -explorer=https://bitcore1.trezor.io/ -log_dir=/opt/blockbook/btc/logs User=blockbook -# Type=forking -# PIDFile=/run/bitcoind/btc.pid +Type=simple Restart=on-failure -StandardOutput=file:/opt/blockbook/btc/logs/blockbook.log -StandardError=file:/opt/blockbook/btc/logs/blockbook.log +WorkingDirectory=/opt/blockbook/btc # Hardening measures #################### diff --git a/build/deb/debian/blockbook-zec.install b/build/deb/debian/blockbook-zec.install index e696a00b..d34066f5 100755 --- a/build/deb/debian/blockbook-zec.install +++ b/build/deb/debian/blockbook-zec.install @@ -1,4 +1,5 @@ #!/usr/bin/dh-exec --with=install blockbook /opt/blockbook/zec/bin server/testcert.* /opt/blockbook/zec/cert +server/static /opt/blockbook/zec configs/zec.json => /opt/blockbook/zec/config/blockchaincfg.json diff --git a/build/deb/debian/blockbook-zec.logrotate b/build/deb/debian/blockbook-zec.logrotate deleted file mode 100644 index 2420567b..00000000 --- a/build/deb/debian/blockbook-zec.logrotate +++ /dev/null @@ -1,9 +0,0 @@ -/opt/blockbook/zec/logs/blockbook.log -{ - rotate 7 - daily - compress - missingok - notifempty - copytruncate -} diff --git a/build/deb/debian/blockbook-zec.postinst b/build/deb/debian/blockbook-zec.postinst index 1212e626..271b4603 100644 --- a/build/deb/debian/blockbook-zec.postinst +++ b/build/deb/debian/blockbook-zec.postinst @@ -9,10 +9,13 @@ case "$1" in useradd --system -M -U blockbook fi - if [ "$(stat -c '%U' /data/zec/blockbook)" != "blockbook" ] - then - chown -R blockbook:blockbook /data/zec/blockbook - fi + for dir in /data/zec/blockbook /opt/blockbook/zec/logs + do + if [ "$(stat -c '%U' $dir)" != "blockbook" ] + then + chown -R blockbook:blockbook $dir + fi + done ;; esac diff --git a/build/deb/debian/blockbook-zec.service b/build/deb/debian/blockbook-zec.service index 3cc3cd63..9db3aed7 100644 --- a/build/deb/debian/blockbook-zec.service +++ b/build/deb/debian/blockbook-zec.service @@ -9,15 +9,11 @@ Description=Blockbook daemon (ZEC mainnet) After=network.target [Service] -ExecStart=/opt/blockbook/zec/bin/blockbook -coin=zec -blockchaincfg=/opt/blockbook/zec/config/blockchaincfg.json -datadir=/data/zec/blockbook/db -sync -httpserver=:8235 -socketio=:8236 -certfile=/opt/blockbook/zec/cert/blockbook -explorer=https://zec-bitcore1.trezor.io/ -# Creates /run/blockbook owned by blockbook -RuntimeDirectory=blockbook +ExecStart=/opt/blockbook/zec/bin/blockbook -coin=zec -blockchaincfg=/opt/blockbook/zec/config/blockchaincfg.json -datadir=/data/zec/blockbook/db -sync -httpserver=:8235 -socketio=:8236 -certfile=/opt/blockbook/zec/cert/blockbook -explorer=https://zec-bitcore1.trezor.io/ -log_dir=/opt/blockbook/zec/logs User=blockbook -# Type=forking -# PIDFile=/run/bitcoind/zec.pid +Type=simple Restart=on-failure -StandardOutput=file:/opt/blockbook/zec/logs/blockbook.log -StandardError=file:/opt/blockbook/zec/logs/blockbook.log +WorkingDirectory=/opt/blockbook/zec # Hardening measures #################### diff --git a/build/deb/debian/control b/build/deb/debian/control index 292a1555..5ab64d64 100644 --- a/build/deb/debian/control +++ b/build/deb/debian/control @@ -2,20 +2,20 @@ Source: blockbook Section: satoshilabs Priority: optional Maintainer: jakub.matys@satoshilabs.com -Build-Depends: debhelper, dh-systemd, dh-exec, upx +Build-Depends: debhelper, dh-systemd, dh-exec Standards-Version: 3.9.5 Package: blockbook-btc Architecture: amd64 -Depends: ${shlibs:Depends}, ${misc:Depends} +Depends: ${shlibs:Depends}, ${misc:Depends}, coreutils, passwd, findutils Description: Satoshilabs blockbook server Package: blockbook-btc-testnet Architecture: amd64 -Depends: ${shlibs:Depends}, ${misc:Depends} +Depends: ${shlibs:Depends}, ${misc:Depends}, coreutils, passwd, findutils Description: Satoshilabs blockbook server Package: blockbook-zec Architecture: amd64 -Depends: ${shlibs:Depends}, ${misc:Depends} +Depends: ${shlibs:Depends}, ${misc:Depends}, coreutils, passwd, findutils Description: Satoshilabs blockbook server diff --git a/server/https.go b/server/https.go index e135818d..cf073e9e 100644 --- a/server/https.go +++ b/server/https.go @@ -8,12 +8,10 @@ import ( "errors" "fmt" "net/http" - "os" "strconv" "github.com/golang/glog" - "github.com/gorilla/handlers" "github.com/gorilla/mux" "github.com/prometheus/client_golang/prometheus/promhttp" ) @@ -30,8 +28,10 @@ type HTTPServer struct { // NewHTTPServer creates new REST interface to blockbook and returns its handle func NewHTTPServer(httpServerBinding string, certFiles string, db *db.RocksDB, chain bchain.BlockChain, txCache *db.TxCache) (*HTTPServer, error) { + r := mux.NewRouter() https := &http.Server{ - Addr: httpServerBinding, + Addr: httpServerBinding, + Handler: r, } s := &HTTPServer{ https: https, @@ -42,7 +42,6 @@ func NewHTTPServer(httpServerBinding string, certFiles string, db *db.RocksDB, c chainParser: chain.GetChainParser(), } - r := mux.NewRouter() r.HandleFunc("/", s.info) r.HandleFunc("/bestBlockHash", s.bestBlockHash) r.HandleFunc("/blockHash/{height}", s.blockHash) @@ -51,10 +50,6 @@ func NewHTTPServer(httpServerBinding string, certFiles string, db *db.RocksDB, c r.HandleFunc("/unconfirmedTransactions/{address}", s.unconfirmedTransactions) r.HandleFunc("/metrics", promhttp.Handler().ServeHTTP) - var h http.Handler = r - h = handlers.LoggingHandler(os.Stderr, h) - https.Handler = h - return s, nil } diff --git a/server/socketio.go b/server/socketio.go index 2e91a3bc..dc84af64 100644 --- a/server/socketio.go +++ b/server/socketio.go @@ -76,7 +76,7 @@ func NewSocketIoServer(binding string, certFiles string, db *db.RocksDB, chain b } // support for tests of socket.io interface - serveMux.Handle(path+"test.html", http.FileServer(http.Dir("./server/static/"))) + serveMux.Handle(path+"test.html", http.FileServer(http.Dir("./static/"))) // redirect to Bitcore for details of transaction serveMux.HandleFunc(path+"tx/", s.txRedirect) // handle socket.io From c5852d256e95107ba38e949b481f26bae624efa1 Mon Sep 17 00:00:00 2001 From: Jakub Matys Date: Fri, 13 Apr 2018 09:51:14 +0200 Subject: [PATCH 8/9] updated dependencies --- Gopkg.lock | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/Gopkg.lock b/Gopkg.lock index 4bab6d77..1cac8e92 100644 --- a/Gopkg.lock +++ b/Gopkg.lock @@ -5,7 +5,7 @@ branch = "master" name = "github.com/beorn7/perks" packages = ["quantile"] - revision = "4c0e84591b9aa9e6dcfdf3e020114cd81f89d5f9" + revision = "3a771d992973f24aa725d07868b467d1ddfceafb" [[projects]] branch = "master" @@ -34,8 +34,8 @@ [[projects]] name = "github.com/ethereum/go-ethereum" packages = [".","common","common/hexutil","common/math","core/types","crypto","crypto/secp256k1","crypto/sha3","ethclient","ethdb","log","metrics","params","rlp","rpc","trie"] - revision = "b8b9f7f4476a30a0aaf6077daade6ae77f969960" - version = "v1.8.2" + revision = "329ac18ef617d0238f71637bffe78f028b0f13f7" + version = "v1.8.3" [[projects]] name = "github.com/go-stack/stack" @@ -43,6 +43,12 @@ revision = "259ab82a6cad3992b4e21ff5cac294ccb06474bc" version = "v1.7.0" +[[projects]] + name = "github.com/gogo/protobuf" + packages = ["proto"] + revision = "1adfc126b41513cc696b209667c8656ea7aac67c" + version = "v1.0.0" + [[projects]] branch = "master" name = "github.com/golang/glog" @@ -67,12 +73,6 @@ revision = "1ea25387ff6f684839d82767c1733ff4d4d15d0a" version = "v1.1" -[[projects]] - name = "github.com/gorilla/handlers" - packages = ["."] - revision = "90663712d74cb411cbef281bc1e08c19d1a76145" - version = "v1.3.0" - [[projects]] name = "github.com/gorilla/mux" packages = ["."] @@ -107,7 +107,7 @@ branch = "master" name = "github.com/pebbe/zmq4" packages = ["."] - revision = "6decad45434f1cddeccf1dc5d9d86d8249decd19" + revision = "5b443b6471cea4b4f9f85025530c04c93233f76a" [[projects]] name = "github.com/prometheus/client_golang" @@ -125,13 +125,13 @@ branch = "master" name = "github.com/prometheus/common" packages = ["expfmt","internal/bitbucket.org/ww/goautoneg","model"] - revision = "e4aa40a9169a88835b849a6efb71e05dc04b88f0" + revision = "38c53a9f4bfcd932d1b00bfc65e256a7fba6b37a" [[projects]] branch = "master" name = "github.com/prometheus/procfs" packages = [".","internal/util","nfs","xfs"] - revision = "54d17b57dd7d4a3aa092476596b3f8a933bde349" + revision = "8b1c2da0d56deffdbb9e48d4414b4e674bd8083e" [[projects]] name = "github.com/rs/cors" @@ -143,7 +143,7 @@ branch = "master" name = "github.com/syndtr/goleveldb" packages = ["leveldb","leveldb/cache","leveldb/comparer","leveldb/errors","leveldb/filter","leveldb/iterator","leveldb/journal","leveldb/memdb","leveldb/opt","leveldb/storage","leveldb/table","leveldb/util"] - revision = "169b1b37be738edb2813dab48c97a549bcf99bb5" + revision = "714f901b98fdb3aa954b4193d8cbd64a28d80cad" [[projects]] branch = "master" @@ -155,13 +155,13 @@ branch = "master" name = "golang.org/x/crypto" packages = ["ripemd160"] - revision = "182114d582623c1caa54f73de9c7224e23a48487" + revision = "d6449816ce06963d9d136eee5a56fca5b0616e7e" [[projects]] branch = "master" name = "golang.org/x/net" packages = ["websocket"] - revision = "e0c57d8f86c17f0724497efcb3bc617e82834821" + revision = "61147c48b25b599e5b561d2e9c4f3e1ef489ca41" [[projects]] name = "gopkg.in/fatih/set.v0" @@ -184,6 +184,6 @@ [solve-meta] analyzer-name = "dep" analyzer-version = 1 - inputs-digest = "4b02d441181efce194d638a8c5ca005955d5cc4e4ff1f23d304429d415339ec7" + inputs-digest = "a463c234bc11d9917876a827f692392845ed89571edc1484ae3e932f555d484b" solver-name = "gps-cdcl" solver-version = 1 From e13164253ecc5261e108a41e8af64509bb4973e4 Mon Sep 17 00:00:00 2001 From: Jakub Matys Date: Fri, 13 Apr 2018 10:25:21 +0200 Subject: [PATCH 9/9] tests run in all subdirectories --- build/bin/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build/bin/Makefile b/build/bin/Makefile index 3bdee2f5..7d4efd84 100644 --- a/build/bin/Makefile +++ b/build/bin/Makefile @@ -9,7 +9,7 @@ build-debug: prepare-sources chown $(PACKAGER) /out/blockbook test: prepare-sources - cd $(GOPATH)/src/blockbook && go test -v ./bchain/coins/zec + cd $(GOPATH)/src/blockbook && go test -v ./... prepare-sources: @ [ -n "`ls /src 2> /dev/null`" ] || (echo "/src doesn't exist or is empty" 1>&2 && exit 1)