docker: revamp docker set up to allow for an LN test cluster

This commit revamps the existing docker configuration to allow for
developer’s to easily bring up/down a Lightning Network testbed
environment.

Configuration related bugs within the prior swarm set up have been
fixed. The launched lnd nodes are now able to properly communicate with
the primary btcd node over RPC. The auto-generated RPC script has been
scrapped in favor of hard-coding a developer-only set of RPC
credentials. With this change, it’s now possible to add/remove
additional lnd nodes in order to test more complex scenarios.

Additionally, the containers now build off of the latest Go version
(1.7).
This commit is contained in:
Olaoluwa Osuntokun 2016-08-29 15:17:48 -07:00
parent 4e416da4cd
commit 9a4a52ed89
No known key found for this signature in database
GPG Key ID: 9CC5B105D03521A2
6 changed files with 61 additions and 87 deletions

@ -1,4 +1,4 @@
FROM golang:1.6.2 FROM golang:1.7
MAINTAINER Olaoluwa Osuntokun <laolu@lightning.network> MAINTAINER Olaoluwa Osuntokun <laolu@lightning.network>
@ -12,14 +12,17 @@ EXPOSE 8333 18333 18335 28901
# Expose the mainnet, testnet, simnet, and segnet rpc ports. # Expose the mainnet, testnet, simnet, and segnet rpc ports.
EXPOSE 8333 18333 18336 28902 EXPOSE 8333 18333 18336 28902
# Create a volume to house the RPC credentials. This will be shared with any
# lnd containers so they can securely query btcd's RPC server.
VOLUME ["/rpc"]
VOLUME ["/data"] VOLUME ["/data"]
RUN mkdir /root/.btcd && mkdir /root/.btcctl RUN mkdir /root/.btcd && mkdir /root/.btcctl
# Generate an automatic RPC conf. COPY btcd-start.sh /
ADD initrpc.go /root/
WORKDIR /root
RUN go build -o gen-config && ./gen-config
# TODO(roabeef): ENV or prog to parse --no-tls? # Finally, execute the shell script that will start btcd. We use a shell script
ENTRYPOINT ["/go/bin/btcd", "--datadir=/data", "--logdir=/data", "--segnet", "--rpccert=/data/rpc.cert", "--rpckey=/data/rpc.key"] # rather than executing the command directly with ENTRYPOINT in order to ensure
# environment variables get properly substitued.
ENTRYPOINT ["/btcd-start.sh"]

7
docker/btcd/btcd-start.sh Executable file

@ -0,0 +1,7 @@
#!/bin/bash
/go/bin/btcd --datadir=/data --logdir=/data --simnet \
--rpccert=/rpc/rpc.cert --rpckey=/rpc/rpc.key \
--rpcuser=${RPCUSER} --rpcpass=${RPCPASS} --rpclisten=0.0.0.0 \
--debuglevel=debug

@ -1,64 +0,0 @@
package main
import (
"bytes"
"crypto/rand"
"encoding/base64"
"flag"
"fmt"
"io/ioutil"
"log"
"text/template"
"github.com/roasbeef/btcutil"
)
var (
numRandBytes = flag.Int("num_rand_bytes", 32, "Number of random bytes to read for both the username and password")
)
const (
autoRpcTemplate = "[Application Options]\nrpcuser={{.Username}}\nrpcpass={{.Password}}"
)
type basicRpcOptions struct {
Username string
Password string
}
func randBase64string(numBytes int) string {
randBuf := make([]byte, numBytes)
if _, err := rand.Read(randBuf); err != nil {
log.Fatalf("unable to read random bytes: %v", err)
}
return base64.StdEncoding.EncodeToString(randBuf)
}
func main() {
fmt.Println("Creating random rpc config for btcd")
t := template.Must(template.New("rpcOptions").Parse(autoRpcTemplate))
randRpcOptions := basicRpcOptions{
Username: randBase64string(*numRandBytes),
Password: randBase64string(*numRandBytes),
}
var autoAuth bytes.Buffer
if err := t.Execute(&autoAuth, randRpcOptions); err != nil {
log.Fatalf("unable to generate random auth: %v")
}
btcdHomeDir := btcutil.AppDataDir("btcd", false)
btcctlHomeDir := btcutil.AppDataDir("btcctl", false)
btcdConfigPath := fmt.Sprintf("%s/btcd.conf", btcdHomeDir)
btcctlConfigPath := fmt.Sprintf("%s/btcctl.conf", btcctlHomeDir)
if err := ioutil.WriteFile(btcdConfigPath, autoAuth.Bytes(), 0644); err != nil {
log.Fatalf("unable to write config for btcd: %v", err)
}
if err := ioutil.WriteFile(btcctlConfigPath, autoAuth.Bytes(), 0644); err != nil {
log.Fatalf("unable to write config for btcctl: %v", err)
}
fmt.Println("fin.")
}

@ -1,20 +1,27 @@
version: '2' version: '2'
services: services:
btcd: btcd:
container_name: btcd environment:
build: btcd/ - RPCUSER=devuser
ports: - RPCPASS=devpass
# TODO(roasbeef): switch to testnet after fixing peer discovery. build:
- "28901:28901" context: btcd/
expose:
- "18336"
volumes: volumes:
- shared-volume:/data - shared-volume:/rpc
lnd: lnd:
container_name: lnd environment:
build: lnd/ - RPCUSER=devuser
ports: - RPCPASS=devpass
- "10009:10009" build:
context: ../
dockerfile: docker/lnd/Dockerfile
expose:
- "10009"
- "10011"
volumes: volumes:
- shared-volume:/data - shared-volume:/rpc
links: links:
- btcd - btcd
volumes: volumes:

@ -1,14 +1,30 @@
FROM golang:1.6.2 FROM golang:1.7
MAINTAINER Olaoluwa Osuntokun <laolu@lightning.network> MAINTAINER Olaoluwa Osuntokun <laolu@lightning.network>
# Grab and install the latest version of lnd and all related dependencies. # TODO(roasbeef): just mount a volume from the build context to the GOPATH?
# TODO(roasbeef): replace with glide install ADD . /go/src/github.com/lightningnetwork/lnd
RUN go get -u -v github.com/lightningnetwork/lnd/... WORKDIR /go/src/github.com/lightningnetwork/lnd
# 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
RUN go build
RUN go install . ./cmd/...
# Mount a volume where btcd's RPC credentials are stored. We'll need to read
# the TLS cert from this directory.
VOLUME ["/rpc"]
VOLUME ["/data"] VOLUME ["/data"]
# Expose the p2p listening port, and the current RPC port. # Expose the p2p listening port, and the current RPC port.
EXPOSE 10009 10011 EXPOSE 10009 10011
ENTRYPOINT ["/go/bin/lnd", "--datadir=/data", "--logdir=/data", "--segnet", "--btcdhost=btcd", "--rpccert=/data/rpc.cert"] COPY docker/lnd/lnd-start.sh /
# Finally, execute the shell script that will start lnd. We use a shell script
# rather than executing the command directly with ENTRYPOINT in order to ensure
# environment variables get properly substitued.
ENTRYPOINT ["/lnd-start.sh"]

5
docker/lnd/lnd-start.sh Executable file

@ -0,0 +1,5 @@
#!/bin/bash
/go/bin/lnd --datadir=/data --logdir=/data --simnet \
--btcdhost=btcd --rpccert=/rpc/rpc.cert \
--rpcuser=${RPCUSER} --rpcpass=${RPCPASS} --debuglevel=debug