diff --git a/.gitignore b/.gitignore index 2d4d343a..39b75505 100644 --- a/.gitignore +++ b/.gitignore @@ -24,7 +24,7 @@ _testmain.go *.test *.prof -lnd +/lnd cmd/cmd **.key diff --git a/docker/README.md b/docker/README.md new file mode 100644 index 00000000..8b137891 --- /dev/null +++ b/docker/README.md @@ -0,0 +1 @@ + diff --git a/docker/btcd/Dockerfile b/docker/btcd/Dockerfile new file mode 100644 index 00000000..088d474e --- /dev/null +++ b/docker/btcd/Dockerfile @@ -0,0 +1,25 @@ +FROM golang:1.6.2 + +MAINTAINER Olaoluwa Osuntokun + +# Grab and install the latest version of roasbeef's fork of btcd and all +# related dependencies. +RUN go get -u -v github.com/roasbeef/btcd/... + +# Expose the mainnet, testnet, simnet, and segnet listening ports. +EXPOSE 8333 18333 18335 28901 + +# Expose the mainnet, testnet, simnet, and segnet rpc ports. +EXPOSE 8333 18333 18336 28902 + +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 + +# 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"] diff --git a/docker/btcd/initrpc.go b/docker/btcd/initrpc.go new file mode 100644 index 00000000..331da39b --- /dev/null +++ b/docker/btcd/initrpc.go @@ -0,0 +1,64 @@ +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.") +} diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml new file mode 100644 index 00000000..e790fb36 --- /dev/null +++ b/docker/docker-compose.yml @@ -0,0 +1,21 @@ +version: '2' +services: + btcd: + container_name: btcd + build: btcd/ + ports: + # TODO(roasbeef): switch to testnet after fixing peer discovery. + - "28901:28901" + volumes: + - shared-volume:/data + lnd: + container_name: lnd + build: lnd/ + ports: + - "10009:10009" + volumes: + - shared-volume:/data + links: + - btcd +volumes: + shared-volume: {} diff --git a/docker/lnd/Dockerfile b/docker/lnd/Dockerfile new file mode 100644 index 00000000..4d2de759 --- /dev/null +++ b/docker/lnd/Dockerfile @@ -0,0 +1,14 @@ +FROM golang:1.6.2 + +MAINTAINER Olaoluwa Osuntokun + +# Grab and install the latest version of lnd and all related dependencies. +# TODO(roasbeef): replace with glide install +RUN go get -u -v github.com/lightningnetwork/lnd/... + +VOLUME ["/data"] + +# Expose the p2p listening port, and the current RPC port. +EXPOSE 10009 10011 + +ENTRYPOINT ["/go/bin/lnd", "--datadir=/data", "--logdir=/data", "--segnet", "--btcdhost=btcd", "--rpccert=/data/rpc.cert"]