Skip to content

Commit

Permalink
Merge pull request #1 from Vutov/master
Browse files Browse the repository at this point in the history
Docker for BTCPay
  • Loading branch information
shelvenzhou authored Jul 20, 2018
2 parents 04c203c + 3150fe2 commit 15cee06
Show file tree
Hide file tree
Showing 5 changed files with 113 additions and 9 deletions.
2 changes: 2 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Dockerfile
BTCPayServer.Dockerfile
4 changes: 4 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -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
43 changes: 43 additions & 0 deletions BTCPayServer.Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]
19 changes: 10 additions & 9 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
54 changes: 54 additions & 0 deletions docker-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 15cee06

Please sign in to comment.