diff --git a/.dockerignore b/.dockerignore index 5b6f95a1..9e86672b 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,2 +1,3 @@ *~ vendor +Dockerfile* diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..4c9e9893 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,12 @@ +FROM golang:1.10.3 + +WORKDIR /go/src/github.com/decred/dcrd +COPY . . + +RUN go get -u github.com/golang/dep/cmd/dep +RUN dep ensure +RUN go install . ./cmd/... + +EXPOSE 9108 + +CMD dcrd diff --git a/Dockerfile-1.10 b/Dockerfile-1.10 deleted file mode 100644 index 347cb78e..00000000 --- a/Dockerfile-1.10 +++ /dev/null @@ -1,52 +0,0 @@ -#decred-golang-builder-1.10 -# This image may be called with the run_tests.sh script included in any of the -# supported go repos. -# ./run_tests.sh 1.10 - -FROM golang:1.10 - -LABEL description="Decred golang builder image" -LABEL version="1.0" -LABEL maintainer "dhill@mindcry.org" - -ENV TERM linux -ENV USER build - -# create user -RUN adduser --disabled-password --gecos '' $USER - -# update base distro & install build tooling -ENV DEBIAN_FRONTEND noninteractive - -RUN apt-get update && \ - apt-get install -qy rsync - -# create directory for build artifacts, adjust user permissions -RUN mkdir /release && \ - chown $USER /release - -# create directory to get source from -RUN mkdir /src && \ - chown $USER /src && \ - mkdir -p /go/src/github.com/decred/dcrd && \ - mkdir -p /go/src/github.com/decred/dcrwallet && \ - chown -R $USER /go/src - -# switch user -USER $USER -ENV HOME /home/$USER - -# get deps -ENV DEP_TAG v0.4.1 -ENV GOMETALINTER_TAG v2.0.5 - -WORKDIR /go/src -RUN go get -v github.com/alecthomas/gometalinter && \ - cd /go/src/github.com/alecthomas/gometalinter && \ - git checkout $GOMETALINTER_TAG && \ - go install && \ - gometalinter --install && \ - go get -v github.com/golang/dep && \ - cd /go/src/github.com/golang/dep && \ - git checkout $DEP_TAG && \ - go install -i diff --git a/Dockerfile-1.9 b/Dockerfile-1.9 deleted file mode 100644 index cad34c34..00000000 --- a/Dockerfile-1.9 +++ /dev/null @@ -1,52 +0,0 @@ -#decred-golang-builder-1.9 -# This image may be called with the run_tests.sh script included in any of the -# supported go repos. -# ./run_tests.sh 1.9 - -FROM golang:1.9.4 - -LABEL description="Decred golang builder image" -LABEL version="1.0" -LABEL maintainer "dhill@mindcry.org" - -ENV TERM linux -ENV USER build - -# create user -RUN adduser --disabled-password --gecos '' $USER - -# update base distro & install build tooling -ENV DEBIAN_FRONTEND noninteractive - -RUN apt-get update && \ - apt-get install -qy rsync - -# create directory for build artifacts, adjust user permissions -RUN mkdir /release && \ - chown $USER /release - -# create directory to get source from -RUN mkdir /src && \ - chown $USER /src && \ - mkdir -p /go/src/github.com/decred/dcrd && \ - mkdir -p /go/src/github.com/decred/dcrwallet && \ - chown -R $USER /go/src - -# switch user -USER $USER -ENV HOME /home/$USER - -# get deps -ENV DEP_TAG v0.4.1 -ENV GOMETALINTER_TAG v2.0.5 - -WORKDIR /go/src -RUN go get -v github.com/alecthomas/gometalinter && \ - cd /go/src/github.com/alecthomas/gometalinter && \ - git checkout $GOMETALINTER_TAG && \ - go install && \ - gometalinter --install && \ - go get -v github.com/golang/dep && \ - cd /go/src/github.com/golang/dep && \ - git checkout $DEP_TAG && \ - go install ./... diff --git a/Dockerfile.alpine b/Dockerfile.alpine new file mode 100644 index 00000000..2e6150a5 --- /dev/null +++ b/Dockerfile.alpine @@ -0,0 +1,19 @@ +# Build image +FROM golang:1.10.3 + +WORKDIR /go/src/github.com/decred/dcrd +COPY . . + +RUN go get -u github.com/golang/dep/cmd/dep +RUN dep ensure +RUN CGO_ENABLED=0 GOOS=linux go install . ./cmd/... + +# Production image +FROM alpine:3.6 + +RUN apk add --no-cache ca-certificates +COPY --from=0 /go/bin/* /bin/ + +EXPOSE 9108 + +CMD dcrd diff --git a/README.md b/README.md index c54653b9..550c986f 100644 --- a/README.md +++ b/README.md @@ -13,8 +13,8 @@ dcrd maintains the entire past transactional ledger of Decred and allows about Decred please see the [project documentation](https://docs.decred.org/#overview). -Note: To send or receive funds and join Proof-of-Stake mining, you will also need -[dcrwallet](https://github.com/decred/dcrwallet). +Note: To send or receive funds and join Proof-of-Stake mining, you will also +need [dcrwallet](https://github.com/decred/dcrwallet). This project is currently under active development and is in a Beta state. It is extremely stable and has been in production use since February 2016. @@ -80,10 +80,59 @@ go install . ./cmd/... ``` For more information about Decred and how to set up your software please go to -our docs page at [docs.decred.org](https://docs.decred.org/getting-started/beginner-guide/). +our docs page at +[docs.decred.org](https://docs.decred.org/getting-started/beginner-guide/). ## Docker +### Running dcrd + +You can run a decred node from inside a docker container. To build the image +yourself, use the following command: + +``` +docker build -t decred/dcrd . +``` + +Or you can create an alpine based image (requires Docker 17.05 or higher): + +``` +docker build -t decred/dcrd:alpine -f Dockerfile.alpine . +``` + +You can then run the image using: + +``` +docker run decred/dcrd +``` + +You may wish to use an external volume to customise your config and persist the +data in an external volume: + +``` +docker run --rm -v /home/user/dcrdata:/root/.dcrd/data decred/dcrd +``` + +For a minimal image, you can use the decred/dcrd:alpine tag. This is typically +a more secure option while also being a much smaller image. + +You can run dcrctl from inside the image. For example, run an image (mounting +your data from externally) with: + +``` +docker run --rm -ti --name=dcrd-1 -v /home/user/.dcrd:/root/.dcrd \ + decred/dcrd:alpine +``` + +And then run dcrctl commands against it. For example: + +``` +docker exec -ti dcrd-1 dcrctl getbestblock +``` + + +### Running Tests + All tests and linters may be run in a docker container using the script `run_tests.sh`. This script defaults to using the current supported version of go. You can run it with the major version of Go you would like to use as the