From 25970bc11323f66a4f80afe1b8271cdcd5f3fac3 Mon Sep 17 00:00:00 2001 From: Andrey Samokhvalov Date: Sat, 13 May 2017 23:21:57 +0300 Subject: [PATCH] docker: add ltcd image Intoduce the Litecoin network daemon, which will be needed in order to interact with Litecoin blockchain. --- docker/ltcd/Dockerfile | 45 ++++++++++++++++++++++++ docker/ltcd/start-ltcctl.sh | 52 +++++++++++++++++++++++++++ docker/ltcd/start-ltcd.sh | 70 +++++++++++++++++++++++++++++++++++++ 3 files changed, 167 insertions(+) create mode 100644 docker/ltcd/Dockerfile create mode 100755 docker/ltcd/start-ltcctl.sh create mode 100755 docker/ltcd/start-ltcd.sh diff --git a/docker/ltcd/Dockerfile b/docker/ltcd/Dockerfile new file mode 100644 index 00000000..16c0a7ce --- /dev/null +++ b/docker/ltcd/Dockerfile @@ -0,0 +1,45 @@ +FROM golang:1.7 + +MAINTAINER Andrey Samokhvalov + +# Expose mainnet ports (server, rpc) +EXPOSE 8333 8334 + +# Expose testnet ports (server, rpc) +EXPOSE 18333 18334 + +# Expose simnet ports (server, rpc) +EXPOSE 18555 18556 + +# Expose segnet ports (server, rpc) +EXPOSE 28901 28902 + +# Grab and install the latest version of roasbeef's fork of btcd and all +# related dependencies. +WORKDIR $GOPATH/src/github.com/ltcsuite/ltcd +RUN git clone https://github.com/ltcsuite/ltcd ./ +RUN go get -u github.com/Masterminds/glide +RUN glide install +RUN go install . ./cmd/ltcctl ./cmd/gencerts + +RUN mkdir "/rpc" "/root/.ltcd" "/root/.ltcctl" +RUN touch "/root/.ltcd/ltcd.conf" + +# Manually generate certificate and add all domains, it is needed to connect +# "ltcctl" and "lnd" to "ltcd" over docker links. +RUN "/go/bin/gencerts" --host="*" --directory="/rpc" --force + +# Create a volume to house pregenerated RPC credentials. This will be +# shared with any lnd, btcctl containers so they can securely query btcd's RPC +# server. +# You should NOT do this before certificate generation! +# Otherwise manually generated certificate will be overriden with shared +# mounted volume! For more info read dockerfile "VOLUME" documentation. +VOLUME ["/rpc"] + +COPY "start-ltcctl.sh" . +COPY "start-ltcd.sh" . + +RUN chmod +x start-ltcctl.sh +RUN chmod +x start-ltcd.sh + diff --git a/docker/ltcd/start-ltcctl.sh b/docker/ltcd/start-ltcctl.sh new file mode 100755 index 00000000..beb12bd9 --- /dev/null +++ b/docker/ltcd/start-ltcctl.sh @@ -0,0 +1,52 @@ +#!/usr/bin/env bash + +# exit from script if error was raised. +set -e + +# error function is used within a bash function in order to send the error +# message directly to the stderr output and exit. +error() { + echo "$1" > /dev/stderr + exit 0 +} + +# return is used within bash function in order to return the value. +return() { + echo "$1" +} + +# set_default function gives the ability to move the setting of default +# env variable from docker file to the script thereby giving the ability to the +# user override it durin container start. +set_default() { + # docker initialized env variables with blank string and we can't just + # use -z flag as usually. + BLANK_STRING='""' + + VARIABLE="$1" + DEFAULT="$2" + + if [[ -z "$VARIABLE" || "$VARIABLE" == "$BLANK_STRING" ]]; then + + if [ -z "$DEFAULT" ]; then + error "You should specify default variable" + else + VARIABLE="$DEFAULT" + fi + fi + + return "$VARIABLE" +} + +# Set default variables if needed. +RPCUSER=$(set_default "$RPCUSER" "devuser") +RPCPASS=$(set_default "$RPCPASS" "devpass") +NETWORK=$(set_default "$NETWORK" "simnet") + +ltcctl \ + "--$NETWORK" \ + --rpccert="/rpc/rpc.cert" \ + --rpcuser="$RPCUSER" \ + --rpcpass="$RPCPASS" \ + --rpcserver="rpcserver" \ + "$@" diff --git a/docker/ltcd/start-ltcd.sh b/docker/ltcd/start-ltcd.sh new file mode 100755 index 00000000..fb9ef6e8 --- /dev/null +++ b/docker/ltcd/start-ltcd.sh @@ -0,0 +1,70 @@ +#!/usr/bin/env bash + +# exit from script if error was raised. +set -e + +# error function is used within a bash function in order to send the error +# message directly to the stderr output and exit. +error() { + echo "$1" > /dev/stderr + exit 0 +} + +# return is used within bash function in order to return the value. +return() { + echo "$1" +} + +# set_default function gives the ability to move the setting of default +# env variable from docker file to the script thereby giving the ability to the +# user override it durin container start. +set_default() { + # docker initialized env variables with blank string and we can't just + # use -z flag as usually. + BLANK_STRING='""' + + VARIABLE="$1" + DEFAULT="$2" + + if [[ -z "$VARIABLE" || "$VARIABLE" == "$BLANK_STRING" ]]; then + + if [ -z "$DEFAULT" ]; then + error "You should specify default variable" + else + VARIABLE="$DEFAULT" + fi + fi + + return "$VARIABLE" +} + +# Set default variables if needed. +RPCUSER=$(set_default "$RPCUSER" "devuser") +RPCPASS=$(set_default "$RPCPASS" "devpass") +DEBUG=$(set_default "$DEBUG" "info") +NETWORK=$(set_default "$NETWORK" "simnet") + +PARAMS=$(echo \ + "--$NETWORK" \ + "--debuglevel=$DEBUG" \ + "--rpcuser=$RPCUSER" \ + "--rpcpass=$RPCPASS" \ + "--datadir=/data" \ + "--logdir=/data" \ + "--rpccert=/rpc/rpc.cert" \ + "--rpckey=/rpc/rpc.key" \ + "--rpclisten=0.0.0.0" +) + +# Set the mining flag only if address is non empty. +if [[ -n "$MINING_ADDRESS" ]]; then + PARAMS="$PARAMS --miningaddr=$MINING_ADDRESS" +fi + +# Add user parameters to command. +PARAMS="$PARAMS $@" + +# Print command and start bitcoin node. +echo "Command: ltcd $PARAMS" +ltcd $PARAMS +