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:
6 files changed
+61
-87
No files matched your search
+10
-7
@@ -1,4 +1,4 @@
|
||||
FROM golang:1.6.2
|
||||
FROM golang:1.7
|
||||
|
||||
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 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"]
|
||||
|
||||
RUN mkdir /root/.btcd && mkdir /root/.btcctl
|
||||
|
||||
# Generate an automatic RPC conf.
|
||||
ADD initrpc.go /root/
|
||||
WORKDIR /root
|
||||
RUN go build -o gen-config && ./gen-config
|
||||
COPY btcd-start.sh /
|
||||
|
||||
# TODO(roabeef): ENV or prog to parse --no-tls?
|
||||
ENTRYPOINT ["/go/bin/btcd", "--datadir=/data", "--logdir=/data", "--segnet", "--rpccert=/data/rpc.cert", "--rpckey=/data/rpc.key"]
|
||||
# Finally, execute the shell script that will start btcd. We use a shell script
|
||||
# rather than executing the command directly with ENTRYPOINT in order to ensure
|
||||
# environment variables get properly substitued.
|
||||
ENTRYPOINT ["/btcd-start.sh"]
|
||||
Executable
+7
@@ -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.")
|
||||
}
|
||||
Reference in new issue
Block a user