From 7883f305e769acb2fb79bf50f627020c64fe48b2 Mon Sep 17 00:00:00 2001 From: Steven Jack Date: Mon, 16 Apr 2018 09:41:23 +0100 Subject: [PATCH] Docker setup (#70) * Adds docker setup * Add build args * Remove spaec * Bump version * Adds run prefix --- .dockerignore | 3 +++ Dockerfile | 15 +++++++++++ Makefile | 10 ++++++++ README.md | 15 +++++++++++ VERSION | 2 +- circle.yml | 71 ++++++++++++++++++++++++++++++++++++++++++++++++++- 6 files changed, 114 insertions(+), 2 deletions(-) create mode 100644 .dockerignore create mode 100644 Dockerfile diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 000000000..8f94841fb --- /dev/null +++ b/.dockerignore @@ -0,0 +1,3 @@ +vendor +.git +chains diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 000000000..0d1c6bf7e --- /dev/null +++ b/Dockerfile @@ -0,0 +1,15 @@ +FROM vidsyhq/go-base:latest +LABEL maintainers="anthdm,stevenjack" + +ENV NETMODE=testnet + +ARG VERSION +LABEL version=$VERSION + +ADD bin/neo-go /usr/bin/neo-go +ADD config /config + +RUN chmod u+x /usr/bin/neo-go + +ENTRYPOINT ["neo-go"] +CMD ["node", "--config-path", "./config", "--testnet"] diff --git a/Makefile b/Makefile index cb5a3d3d0..1f2c1cc14 100644 --- a/Makefile +++ b/Makefile @@ -1,11 +1,15 @@ BRANCH = "master" BUILD_TIME = "$(shell date -u +\"%Y-%m-%dT%H:%M:%SZ\")" VERSION = $(shell cat ./VERSION) +REPONAME = "neo-go" NETMODE ?= "privnet" build: @go build -ldflags "-X github.com/CityOfZion/neo-go/config.Version=${VERSION}-dev -X github.com/CityOfZion/neo-go/config.BuildTime=${BUILD_TIME}" -o ./bin/neo-go ./cli/main.go +build-image: + docker build -t cityofzion/neo-go --build-arg VERSION=${VERSION} . + check-version: git fetch && (! git rev-list ${VERSION}) @@ -18,6 +22,12 @@ push-tag: git tag ${VERSION} git push origin ${VERSION} +push-to-registry: + @docker login -e ${DOCKER_EMAIL} -u ${DOCKER_USER} -p ${DOCKER_PASS} + @docker tag CityOfZion/${REPONAME}:latest CityOfZion/${REPONAME}:${CIRCLE_TAG} + @docker push CityOfZion/${REPONAME}:${CIRCLE_TAG} + @docker push CityOfZion/${REPONAME} + run: build ./bin/neo-go node -config-path ./config -${NETMODE} diff --git a/README.md b/README.md index ff89e070a..9e1c156d9 100644 --- a/README.md +++ b/README.md @@ -49,6 +49,21 @@ make deps ## How to setup a node +### Docker + +Each tagged build is built to docker hub and the `:latest` tag pointing at the latest tagged build. + +By default the `CMD` is set to run a node on `testnet`, so to do this simply run: + +```bash + docker run -d --name neo-go -p 20332:20332 -p 20333:20333 cityofzion/neo-go +``` + +Which will start a node on `testnet` and expose the nodes port `20333` and `20332` for the `JSON-RPC` server. + + +### Building + Build the **neo-go** CLI: ``` diff --git a/VERSION b/VERSION index 385bb682d..72a8a6313 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.40.2 +0.41.0 diff --git a/circle.yml b/circle.yml index ecc2dc343..e8d40e47d 100644 --- a/circle.yml +++ b/circle.yml @@ -16,6 +16,29 @@ jobs: paths: - vendor - /go/pkg + build_image: + working_directory: /go/src/github.com/CityOfZion/neo-go + docker: + - image: alpine + steps: + - run: apk update && apk add git make curl tar + - checkout + - restore_cache: + keys: + - dependency-cache-{{ .Revision }} + - restore_cache: + keys: + - dependency-cache-cli-{{ checksum "Gopkg.toml" }}-{{ checksum "VERSION" }} + - setup_remote_docker + - run: + name: Install Docker client + command: | + set -x + VER="17.03.0-ce" + curl -L -o /tmp/docker-$VER.tgz https://get.docker.com/builds/Linux/x86_64/docker-$VER.tgz + tar -xz -C /tmp -f /tmp/docker-$VER.tgz + mv /tmp/docker/* /usr/bin + - run: make build-image test: working_directory: /go/src/github.com/CityOfZion/neo-go docker: @@ -50,7 +73,34 @@ jobs: - restore_cache: key: dependency-cache-{{ checksum "Gopkg.toml" }}-{{ checksum "VERSION" }} - run: make build - + - save_cache: + key: dependency-cache-cli-{{ checksum "Gopkg.toml" }}-{{ checksum "VERSION" }} + paths: + - bin/neo-go + deploy: + working_directory: /go/src/github.com/CityOfZion/neo-go + docker: + - image: alpine + steps: + - run: apk update && apk add git make + - checkout + - restore_cache: + key: dependency-cache-{{ checksum "Gopkg.toml" }}-{{ checksum "VERSION" }} + - restore_cache: + key: dependency-cache-cli-{{ checksum "Gopkg.toml" }}-{{ checksum "VERSION" }} + - setup_remote_docker + - run: + name: Install Docker client + command: | + set -x + VER="17.03.0-ce" + curl -L -o /tmp/docker-$VER.tgz https://get.docker.com/builds/Linux/x86_64/docker-$VER.tgz + tar -xz -C /tmp -f /tmp/docker-$VER.tgz + mv /tmp/docker/* /usr/bin + - run: make build-image + - deploy: + name: deploy + command: make push-to-registry workflows: version: 2 workflow: @@ -81,3 +131,22 @@ workflows: filters: tags: only: /[0-9]+\.[0-9]+\.[0-9]+/ + - build_image: + requires: + - install_deps + - build_cli + filters: + tags: + only: /[0-9]+\.[0-9]+\.[0-9]+/ + - deploy: + requires: + - build_image + - test + - vet + - check_version + filters: + tags: + only: + - /[0-9]+\.[0-9]+\.[0-9]+/ + branches: + ignore: /.*/