diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000000..095b6f1a40 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,2 @@ +Dockerfile +BTCPayServer.Dockerfile \ No newline at end of file diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000000..6fcdd9127c --- /dev/null +++ b/.gitattributes @@ -0,0 +1,4 @@ +# Declare files that will always have CRLF line endings on checkout. +*.sh text eol=lf +*.go text eol=lf +Makefile text eol=lf diff --git a/BTCPayServer.Dockerfile b/BTCPayServer.Dockerfile new file mode 100644 index 0000000000..1120cfb2da --- /dev/null +++ b/BTCPayServer.Dockerfile @@ -0,0 +1,43 @@ +FROM golang:alpine as builder + +# Force Go to use the cgo based DNS resolver. This is required to ensure DNS +# queries required to connect to linked containers succeed. +ENV GODEBUG netdns=cgo + +# Install dependencies and build the binaries. +RUN apk add --no-cache \ + git \ + make + +WORKDIR /go/src/github.com/shelvenzhou/lnd +COPY . . + +RUN make \ +&& make install + +# Start a new, final image. +FROM alpine as final + +# Add bash and ca-certs, for quality of life and SSL-related reasons. +RUN apk --no-cache add \ + bash \ + ca-certificates + +ENV LND_DATA /data +ENV LND_BITCOIND /deps/.bitcoingold +ENV LND_BTCD /deps/.btcd + +RUN mkdir "$LND_DATA" && mkdir "/deps" && mkdir "$LND_BITCOIND" && mkdir "$LND_BTCD" && \ + ln -sfn "$LND_DATA" /root/.lnd && ln -sfn "$LND_BITCOIND" /root/.bitcoingold && ln -sfn "$LND_BTCD" /root/.btcd + +# Define a root volume for data persistence. +VOLUME /data + +# Copy the binaries from the builder image. +COPY --from=builder /go/bin/lncli /bin/ +COPY --from=builder /go/bin/lnd /bin/ + +COPY docker-entrypoint.sh /docker-entrypoint.sh +# Specify the start command and entrypoint as the lnd daemon. +ENTRYPOINT ["/docker-entrypoint.sh"] +CMD ["lnd"] diff --git a/config.go b/config.go index 7bfcad9083..b370e262dc 100644 --- a/config.go +++ b/config.go @@ -1021,14 +1021,7 @@ func parseRPCParams(cConfig *chainConfig, nodeConfig interface{}, net chainCode, case bitcoingoldChain: daemonName = "bgoldd" } - // If only one or two of the parameters are set, we assume the - // user did that unintentionally. - if conf.RPCUser != "" || conf.RPCPass != "" || conf.ZMQPath != "" { - return fmt.Errorf("please set all or none of "+ - "%[1]v.rpcuser, %[1]v.rpcpass, "+ - "and %[1]v.zmqpath", daemonName) - } - + switch net { case bitcoingoldChain: confDir = conf.Dir @@ -1075,7 +1068,15 @@ func parseRPCParams(cConfig *chainConfig, nodeConfig interface{}, net chainCode, " %v, cannot start w/o RPC connection", err) } - nConf.RPCUser, nConf.RPCPass, nConf.ZMQPath = rpcUser, rpcPass, zmqPath + if nConf.RPCUser == "" { + nConf.RPCUser = rpcUser + } + if nConf.RPCPass == "" { + nConf.RPCPass = rpcPass + } + if nConf.ZMQPath == "" { + nConf.ZMQPath = zmqPath + } } fmt.Printf("Automatically obtained %v's RPC credentials\n", daemonName) diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh new file mode 100755 index 0000000000..1e2ded1e22 --- /dev/null +++ b/docker-entrypoint.sh @@ -0,0 +1,54 @@ +#!/bin/bash +set -e + +if [[ "$1" == "lnd" || "$1" == "lncli" ]]; then + mkdir -p "$LND_DATA" + + cat <<-EOF > "$LND_DATA/lnd.conf" + ${LND_EXTRA_ARGS} + EOF + + if [[ $LND_CHAIN && $LND_ENVIRONMENT ]]; then + echo "LND_CHAIN=$LND_CHAIN" + echo "LND_ENVIRONMENT=$LND_ENVIRONMENT" + + NETWORK="" + + shopt -s nocasematch + if [[ $LND_CHAIN == "btg" ]]; then + NETWORK="bitcoingold" + else + echo "Unknwon value for LND_CHAIN, expected btc or ltc" + fi + + ENV="" + # Make sure we use correct casing for LND_Environment + if [[ $LND_ENVIRONMENT == "mainnet" ]]; then + ENV="mainnet" + elif [[ $LND_ENVIRONMENT == "testnet" ]]; then + ENV="testnet" + elif [[ $LND_ENVIRONMENT == "regtest" ]]; then + ENV="regtest" + else + echo "Unknwon value for LND_ENVIRONMENT, expected mainnet, testnet or regtest" + fi + shopt -u nocasematch + + if [[ $ENV && $NETWORK ]]; then + echo " + $NETWORK.active=1 + $NETWORK.$LND_ENVIRONMENT=1 + " >> "$LND_DATA/lnd.conf" + echo "Added $NETWORK.active and $NETWORK.$LND_ENVIRONMENT to config file $LND_DATA/lnd.conf" + else + echo "LND_CHAIN or LND_ENVIRONMENT is not set correctly" + fi + fi + + ln -sfn "$LND_DATA" /root/.lnd + ln -sfn "$LND_BITCOIND" /root/.bitcoingold + ln -sfn "$LND_BTCD" /root/.btcd + exec "$@" +else + exec "$@" +fi