Auto merge of #4455 - benzcash:Dockerfile-contrib, r=ebfull

Added Dockerfile to contrib with README

Please ensure this checklist is followed for any pull requests for this repo. This checklist must be checked by both the PR creator and by anyone who reviews the PR.
* [ ] Relevant documentation for this PR has to be completed and reviewed by @mdr0id before the PR can be merged
* [ ] A test plan for the PR must be documented in the PR notes and included in the test plan for the next regular release

As a note, all buildbot tests need to be passing and all appropriate code reviews need to be done before this PR can be merged
This commit is contained in:
Homu 2020-05-07 14:53:42 +00:00
commit 93599b7ec8
7 changed files with 209 additions and 0 deletions

View File

@ -0,0 +1,2 @@
./zcash-data-dir/
./zcash-params-dir/

View File

@ -0,0 +1,12 @@
ZCASHD_NETWORK=testnet
ZCASHD_LOGIPS=1
ZCASHD_EXPERIMENTALFEATURES=1
ZCASHD_GEN=0
ZCASHD_RPCUSER=zcashrpc
ZCASHD_RPCPASSWORD=notsecure
ZCASHD_RPCBIND=0.0.0.0
ZCASHD_ALLOWIP=0.0.0.0/0
ZCASHD_TXINDEX=1
ZCASHD_INSIGHTEXPLORER=1
ZCASHD_ZMQPORT=9994
ZCASHD_ZMQBIND=0.0.0.0

3
contrib/docker/.gitignore vendored Normal file
View File

@ -0,0 +1,3 @@
./zcash-data-dir/
./zcash-params-dir/
.env

37
contrib/docker/Dockerfile Normal file
View File

@ -0,0 +1,37 @@
FROM debian:10
RUN apt-get update \
&& apt-get install -y gnupg2 apt-transport-https curl
ARG ZCASH_SIGNING_KEY_ID=6DEF3BAF272766C0
ARG ZCASH_VERSION=
# The empty string for ZCASH_VERSION will install the apt default version,
# which should be the latest stable release. To install a specific
# version, pass `--build-arg 'ZCASH_VERSION=<version>'` to `docker build`.
ARG ZCASHD_USER=zcashd
ARG ZCASHD_UID=2001
RUN apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys $ZCASH_SIGNING_KEY_ID \
&& echo "deb [arch=amd64] https://apt.z.cash/ stretch main" > /etc/apt/sources.list.d/zcash.list \
&& apt-get update
RUN if [ -z "$ZCASH_VERSION" ]; \
then apt-get install -y zcash; \
else apt-get install -y zcash=$ZCASH_VERSION; \
fi; \
zcashd --version
RUN useradd --home-dir /srv/$ZCASHD_USER \
--shell /bin/bash \
--create-home \
--uid $ZCASHD_UID\
$ZCASHD_USER
USER $ZCASHD_USER
WORKDIR /srv/$ZCASHD_USER
RUN mkdir -p /srv/$ZCASHD_USER/.zcash/ \
&& touch /srv/$ZCASHD_USER/.zcash/zcash.conf
ADD entrypoint.sh /entrypoint.sh
ENTRYPOINT ["/entrypoint.sh"]

91
contrib/docker/README.md Normal file
View File

@ -0,0 +1,91 @@
# zcash Dockerfile
This is an example Dockerfile to run the zcashd daemon in a containerized Debian base OS. The image pulls the apt package built by Electric Coin Company.
The output of building this image should be accessible at https://hub.docker.com/r/electriccoinco/zcashd
## Defaults
The image will run as a non-root user, `zcashd` with uid `2001`. When mapping volumes from the host into the container, these permissions must be used, or rebuild the image with your custom values.
## Run time configuration
The goal is to follow the default zcashd startup behavior as closely as possible.
At startup, the image will execute the [./entrypoint.sh](./entrypoint.sh) script. This script uses environmental variables to configure the command line parameters, do a little house cleaning, and start zcashd.
### Available environment variables
If defined, the value is assigned to the value of the corresponding flag.
```
ZCASHD_NETWORK
ZCASHD_LOGIPS
ZCASHD_EXPERIMENTALFEATURES
ZCASHD_GEN
ZCASHD_ZSHIELDCOINBASE
ZCASHD_RPCUSER
ZCASHD_RPCPASSWORD
ZCASHD_RPCBIND
ZCASHD_ALLOWIP
ZCASHD_TXINDEX
ZCASHD_INSIGHTEXPLORER
ZCASHD_ZMQPORT
ZCASHD_ZMQBIND
```
### Additional configuration
Any provided command line parameters are passed from the entrypoint.sh script to zcashd.
You can skip using environmental variables at all, and instead provide a fully configured `zcash.conf` file and map to `/srv/zcashd/.zcash/zcash.conf` at startup.
## Examples
### See the installed version
This command will create a container, print the version information of the zcashd software installed and then exit and remove the container.
Run
```
docker run --rm electriccoinco/zcashd --version
```
Output
```
Zcash Daemon version v2.1.0-1
In order to ensure you are adequately protecting your privacy when using Zcash,
please see <https://z.cash/support/security/>.
Copyright (C) 2009-2019 The Bitcoin Core Developers
Copyright (C) 2015-2019 The Zcash Developers
This is experimental software.
Distributed under the MIT software license, see the accompanying file COPYING
or <https://www.opensource.org/licenses/mit-license.php>.
This product includes software developed by the OpenSSL Project for use in the
OpenSSL Toolkit <https://www.openssl.org/> and cryptographic software written
by Eric Young.
```
### Persist data to the host
For this example, we'll create a place for zcashd to store the blockchain data, create a new container that uses that location, and run it in the background.
```
mkdir {./zcash-params-dir,./zcash-data-dir}
sudo chown -R 2001.2001 {./zcash-params-dir,./zcash-data-dir}
docker run -d --name my_zcashd \
-v $(pwd)/zcash-data-dir:/srv/zcashd/.zcash \
-v $(pwd)/zcash-params-dir/srv/zcashd/.zcash-params \
electriccoinco/zcashd
```
Follow the logs to see its activity.
```
docker logs -f my_zcashd
```

View File

@ -0,0 +1,11 @@
---
version: '3'
services:
zcashd:
build: .
env_file:
- .env
volumes:
- ./zcash-params-dir:/srv/zcashd/.zcash-params
- ./zcash-data-dir:/srv/zcashd/.zcash

53
contrib/docker/entrypoint.sh Executable file
View File

@ -0,0 +1,53 @@
#!/bin/bash
set -eo pipefail
if [[ ${1} == "--version" ]];then
zcashd --version
exit 0
fi
env | sort | grep ZCASHD || true
export ZCASHD_CMD='zcashd -printtoconsole'
if [[ ! -n ${ZCASHD_NETWORK} ]];then
export ZCASHD_NETWORK=mainnet
fi
case ${ZCASHD_NETWORK} in
testnet)
ZCASHD_CMD+=" -testnet -addnode=testnet.z.cash "
;;
mainnet)
ZCASHD_CMD+=" -addnode=mainnet.z.cash "
;;
*)
echo "Error, unknown network: ${ZCASHD_NETWORK}"
exit 1
;;
esac
if [[ -n "${ZCASHD_SHOWMETRICS}" ]];then ZCASHD_CMD+=" -showmetrics=${ZCASHD_SHOWMETRICS}";fi
if [[ -n "${ZCASHD_LOGIPS}" ]];then ZCASHD_CMD+=" -logips=${ZCASHD_LOGIPS}";fi
if [[ -n "${ZCASHD_EXPERIMENTALFEATURES}" ]];then ZCASHD_CMD+=" -experimentalfeatures=${ZCASHD_EXPERIMENTALFEATURES}";fi
if [[ -n "${ZCASHD_GEN}" ]];then ZCASHD_CMD+=" -gen=${ZCASHD_GEN}";fi
if [[ -n "${ZCASHD_ZSHIELDCOINBASE}" ]];then ZCASHD_CMD+=" -zshieldcoinbase=${ZCASHD_ZSHIELDCOINBASE}";fi
if [[ -n "${ZCASHD_RPCUSER}" ]];then ZCASHD_CMD+=" -rpcuser=${ZCASHD_RPCUSER}";fi
if [[ -n "${ZCASHD_RPCPASSWORD}" ]];then ZCASHD_CMD+=" -rpcpassword=${ZCASHD_RPCPASSWORD}";fi
if [[ -n "${ZCASHD_RPCBIND}" ]];then ZCASHD_CMD+=" -rpcbind=${ZCASHD_RPCBIND}";fi
if [[ -n "${ZCASHD_RPCPORT}" ]];then ZCASHD_CMD+=" -rpcport=${ZCASHD_RPCPORT}";fi
if [[ -n "${ZCASHD_ALLOWIP}" ]];then ZCASHD_CMD+=" -rpcallowip=${ZCASHD_ALLOWIP}";fi
if [[ -n "${ZCASHD_TXINDEX}" ]];then ZCASHD_CMD+=" -txindex";fi
if [[ -n "${ZCASHD_INSIGHTEXPLORER}" ]];then ZCASHD_CMD+=" -insightexplorer";fi
if [[ -n "${ZCASHD_ZMQPORT}" && -n "${ZCASHD_ZMQBIND}" ]];then
ZCASHD_CMD+=" -zmqpubhashblock=tcp://${ZCASHD_ZMQBIND}:${ZCASHD_ZMQPORT}"
ZCASHD_CMD+=" -zmqpubhashtx=tcp://${ZCASHD_ZMQBIND}:${ZCASHD_ZMQPORT}"
ZCASHD_CMD+=" -zmqpubrawblock=tcp://${ZCASHD_ZMQBIND}:${ZCASHD_ZMQPORT}"
ZCASHD_CMD+=" -zmqpubrawtx=tcp://${ZCASHD_ZMQBIND}:${ZCASHD_ZMQPORT}"
ZCASHD_CMD+=" -zmqpubhashblock=tcp://${ZCASHD_ZMQBIND}:${ZCASHD_ZMQPORT}"
fi
zcash-fetch-params
touch .zcash/zcash.conf
echo "Starting: ${ZCASHD_CMD}"
eval exec "${ZCASHD_CMD}" "${@}"