From 337d25c190218ae68a160c29f7e12b3cae4cbb38 Mon Sep 17 00:00:00 2001 From: tyzbit Date: Fri, 18 May 2018 23:48:15 -0400 Subject: [PATCH] docker: use alpine and multistage builds in btcd, ltcd images --- docker/btcd/Dockerfile | 52 +++++++++++++++++++++++++++--------------- docker/ltcd/Dockerfile | 45 +++++++++++++++++++++--------------- 2 files changed, 60 insertions(+), 37 deletions(-) diff --git a/docker/btcd/Dockerfile b/docker/btcd/Dockerfile index a570aa27..dc806b01 100644 --- a/docker/btcd/Dockerfile +++ b/docker/btcd/Dockerfile @@ -1,7 +1,23 @@ -FROM golang:1.10 +FROM golang:1.10-alpine as builder MAINTAINER Olaoluwa Osuntokun +# Install build dependencies such as git and glide. +RUN apk add --no-cache \ + git \ +&& go get -u github.com/Masterminds/glide + +WORKDIR $GOPATH/src/github.com/roasbeef/btcd + +# Grab and install the latest version of roasbeef's fork of btcd and all +# related dependencies. +RUN git clone https://github.com/roasbeef/btcd . \ +&& glide install \ +&& go install . ./cmd/... + +# Start a new image +FROM alpine as final + # Expose mainnet ports (server, rpc) EXPOSE 8333 8334 @@ -14,21 +30,26 @@ EXPOSE 18555 18556 # Expose segnet ports (server, rpc) EXPOSE 28901 28902 -# Grab and install the latest version of roasbeef's fork of btcd and all -# related dependencies. -RUN go get -u github.com/Masterminds/glide +# Copy the compiled binaries from the builder image. +COPY --from=builder /go/bin/addblock /bin/ +COPY --from=builder /go/bin/btcctl /bin/ +COPY --from=builder /go/bin/btcd /bin/ +COPY --from=builder /go/bin/findcheckpoint /bin/ +COPY --from=builder /go/bin/gencerts /bin/ -WORKDIR $GOPATH/src/github.com/roasbeef/btcd -RUN git clone https://github.com/roasbeef/btcd . -RUN glide install -RUN go install . ./cmd/... - -RUN mkdir "/rpc" "/root/.btcd" "/root/.btcctl" -RUN touch "/root/.btcd/btcd.conf" +COPY "start-btcctl.sh" . +COPY "start-btcd.sh" . +RUN apk add --no-cache \ + bash \ + ca-certificates \ +&& mkdir "/rpc" "/root/.btcd" "/root/.btcctl" \ +&& touch "/root/.btcd/btcd.conf" \ +&& chmod +x start-btcctl.sh \ +&& chmod +x start-btcd.sh \ # Manually generate certificate and add all domains, it is needed to connect # "btcctl" and "lnd" to "btcd" over docker links. -RUN "/go/bin/gencerts" --host="*" --directory="/rpc" --force +&& "/bin/gencerts" --host="*" --directory="/rpc" --force # Create a volume to house pregenerated RPC credentials. This will be # shared with any lnd, btcctl containers so they can securely query btcd's RPC @@ -37,10 +58,3 @@ RUN "/go/bin/gencerts" --host="*" --directory="/rpc" --force # Otherwise manually generated certificate will be overridden with shared # mounted volume! For more info read dockerfile "VOLUME" documentation. VOLUME ["/rpc"] - -COPY "start-btcctl.sh" . -COPY "start-btcd.sh" . - -RUN chmod +x start-btcctl.sh -RUN chmod +x start-btcd.sh - diff --git a/docker/ltcd/Dockerfile b/docker/ltcd/Dockerfile index d27d46ba..b07f901e 100644 --- a/docker/ltcd/Dockerfile +++ b/docker/ltcd/Dockerfile @@ -1,7 +1,19 @@ -FROM golang:1.10 +FROM golang:1.10-alpine as builder MAINTAINER Olaoluwa Osuntokun +# Grab and install the latest version of roasbeef's fork of ltcd and all +# related dependencies. +WORKDIR $GOPATH/src/github.com/ltcsuite/ltcd +RUN apk add --no-cache git \ +&& git clone https://github.com/ltcsuite/ltcd ./ \ +&& go get -u github.com/Masterminds/glide \ +&& glide install \ +&& go install . ./cmd/ltcctl ./cmd/gencerts + +# Start a new image +FROM alpine as final + # Expose mainnet ports (server, rpc) EXPOSE 8333 8334 @@ -14,19 +26,23 @@ EXPOSE 18555 18556 # Expose segnet ports (server, rpc) EXPOSE 28901 28902 -# Grab and install the latest version of roasbeef's fork of ltcd and all -# related dependencies. -WORKDIR $GOPATH/src/github.com/ltcsuite/ltcd -RUN git clone https://github.com/ltcsuite/ltcd ./ -RUN go get -u github.com/Masterminds/glide -RUN glide install -RUN go install . ./cmd/ltcctl ./cmd/gencerts +# Copy the compiled binaries from the builder image. +COPY --from=builder /go/bin/ltcctl /bin/ +COPY --from=builder /go/bin/ltcd /bin/ +COPY --from=builder /go/bin/gencerts /bin/ -RUN mkdir "/rpc" "/root/.ltcd" "/root/.ltcctl" -RUN touch "/root/.ltcd/ltcd.conf" +COPY "start-ltcctl.sh" . +COPY "start-ltcd.sh" . +RUN apk add --no-cache \ + bash \ + ca-certificates \ +&& chmod +x start-ltcctl.sh \ +&& chmod +x start-ltcd.sh \ +&& mkdir "/rpc" "/root/.ltcd" "/root/.ltcctl" \ +&& touch "/root/.ltcd/ltcd.conf" \ # "ltcctl" and "lnd" to "ltcd" over docker links. -RUN "/go/bin/gencerts" --host="*" --directory="/rpc" --force +&& "/bin/gencerts" --host="*" --directory="/rpc" --force # Create a volume to house pregenerated RPC credentials. This will be # shared with any lnd, btcctl containers so they can securely query ltcd's RPC @@ -35,10 +51,3 @@ RUN "/go/bin/gencerts" --host="*" --directory="/rpc" --force # Otherwise manually generated certificate will be overridden with shared # mounted volume! For more info read dockerfile "VOLUME" documentation. VOLUME ["/rpc"] - -COPY "start-ltcctl.sh" . -COPY "start-ltcd.sh" . - -RUN chmod +x start-ltcctl.sh -RUN chmod +x start-ltcd.sh -