From f640dbb3318d19482e66efdcd2d36d1437212f96 Mon Sep 17 00:00:00 2001 From: Evgeniy Kulikov Date: Fri, 15 Nov 2019 20:41:40 +0300 Subject: [PATCH] DockerCompose: update environment - rewrite Dockerfile - four nodes, custom network, volume - p2p, rpc and metrics port forwarded - make: env_vendor, env_image, env_up, env_down and env_restart - cleanup Makefile commands - remove old docker-compose file fix #497 --- .docker/docker-compose.yml | 75 ++++++++++++++++++++++++ Dockerfile | 14 ++--- Makefile | 43 +++++++++----- config/protocol.privnet.docker.four.yml | 28 +++++---- config/protocol.privnet.docker.one.yml | 27 ++++++--- config/protocol.privnet.docker.three.yml | 27 ++++++--- config/protocol.privnet.docker.two.yml | 27 ++++++--- docker-compose.yml | 38 ------------ 8 files changed, 180 insertions(+), 99 deletions(-) create mode 100644 .docker/docker-compose.yml delete mode 100644 docker-compose.yml diff --git a/.docker/docker-compose.yml b/.docker/docker-compose.yml new file mode 100644 index 000000000..97e386c37 --- /dev/null +++ b/.docker/docker-compose.yml @@ -0,0 +1,75 @@ +version: '2.4' + +networks: + neo_go_network: + name: neo_go_network + ipam: + config: + - subnet: 172.200.0.0/24 + gateway: 172.200.0.254 + +volumes: + volume_chain: + driver: local + +services: + node_one: + container_name: neo_go_node_one + image: env_neo_go_image + command: "node --config-path /config --privnet" + volumes: + - ../config/protocol.privnet.docker.one.yml:/config/protocol.privnet.yml + - volume_chain:/chains + networks: + neo_go_network: + ipv4_address: 172.200.0.1 + ports: + - 20331:20331 + - 20341:20341 + - 20351:20351 + node_two: + container_name: neo_go_node_two + image: env_neo_go_image + command: "node --config-path /config --privnet" + volumes: + - ../config/protocol.privnet.docker.two.yml:/config/protocol.privnet.yml + - volume_chain:/chains + networks: + neo_go_network: + ipv4_address: 172.200.0.2 + ports: + - 20332:20332 + - 20342:20342 + - 20352:20352 + node_three: + container_name: neo_go_node_three + image: env_neo_go_image + command: "node --config-path /config --privnet" + volumes: + - ../config/protocol.privnet.docker.three.yml:/config/protocol.privnet.yml + - volume_chain:/chains + networks: + neo_go_network: + ipv4_address: 172.200.0.3 + ports: + - 20333:20333 + - 20343:20343 + - 20353:20353 + node_four: + container_name: neo_go_node_four + image: env_neo_go_image + command: "node --config-path /config --privnet" + volumes: + - ../config/protocol.privnet.docker.four.yml:/config/protocol.privnet.yml + - volume_chain:/chains + networks: + neo_go_network: + ipv4_address: 172.200.0.4 + ports: + - 20334:20334 + - 20344:20344 + - 20354:20354 + depends_on: + - node_one + - node_two + - node_three diff --git a/Dockerfile b/Dockerfile index 35bee36a2..2fc68c4e3 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,5 @@ # Builder image -FROM golang:1.12-alpine3.10 as builder +FROM golang:1-alpine as builder RUN set -x \ && apk add --no-cache git \ @@ -19,22 +19,18 @@ RUN set -x \ && export GO111MODULE=on \ && export CGO_ENABLED=0 \ && export LDFLAGS="-X ${REPO}/config.Version=${VERSION}" \ - && go mod tidy -v \ - && go mod vendor \ - && go build -v -mod=vendor -ldflags "${LDFLAGS}" -o /go/bin/neo-go ./cli/main.go + && go build -v -mod=vendor -ldflags "${LDFLAGS}" -o /go/bin/neo-go ./cli # Executable image -FROM alpine:3.10 +FROM scratch -ENV NETMODE=testnet ARG VERSION LABEL version=$VERSION WORKDIR / -ENV NETMODE=testnet -COPY --from=builder /neo-go/config /config -COPY --from=builder /go/bin/neo-go /usr/bin/neo-go +COPY --from=builder /neo-go/config /config +COPY --from=builder /go/bin/neo-go /usr/bin/neo-go COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ ENTRYPOINT ["/usr/bin/neo-go"] diff --git a/Makefile b/Makefile index 02eb1966a..e7214847d 100644 --- a/Makefile +++ b/Makefile @@ -8,6 +8,8 @@ BINDIR = "/usr/bin" SYSTEMDUNIT_DIR = "/lib/systemd/system" UNITWORKDIR = "/var/lib/neo-go" +DC_FILE=.docker/docker-compose.yml + REPO ?= "$(shell go list -m)" VERSION ?= "$(shell git describe --tags 2>/dev/null | sed 's/^v//')" BUILD_FLAGS = "-X $(REPO)/config.Version=$(VERSION)" @@ -52,12 +54,6 @@ image: check-version: git fetch && (! git rev-list ${VERSION}) -clean-cluster: - @echo "=> Removing all containers and chain storage" - @rm -rf chains/privnet-docker-one chains/privnet-docker-two chains/privnet-docker-three chains/privnet-docker-four - @docker-compose stop - @docker-compose rm -f - deps: @go mod tidy -v @go mod vendor @@ -77,14 +73,6 @@ push-to-registry: run: build ${BINARY} node -config-path ./config -${NETMODE} -run-cluster: build-linux - @echo "=> Starting docker-compose cluster" - @echo "=> Building container image" - @docker-compose build - @docker-compose up -d - @echo "=> Tailing logs, exiting this prompt will not stop the cluster" - @docker-compose logs -f - test: @go test ./... -cover @@ -100,3 +88,30 @@ fmt: cover: @go test -v -race ./... -coverprofile=coverage.txt -covermode=atomic @go tool cover -html=coverage.txt -o coverage.html + +# --- Environment --- +env_vendor: + @echo "=> Update vendor" + @go mod tidy + @go mod download + @go mod vendor + +env_image: env_vendor + @echo "=> Building env image" + @docker build \ + -t env_neo_go_image \ + --build-arg REPO=$(REPO) \ + --build-arg VERSION=$(VERSION) . + +env_up: + @echo "=> Bootup environment" + @docker-compose -f $(DC_FILE) up -d node_four + +env_down: + @echo "=> Stop and cleanup environment" + @docker-compose -f $(DC_FILE) down + +env_restart: + @echo "=> Stop and cleanup environment" + @docker-compose -f $(DC_FILE) restart + diff --git a/config/protocol.privnet.docker.four.yml b/config/protocol.privnet.docker.four.yml index aba719273..33250ee26 100644 --- a/config/protocol.privnet.docker.four.yml +++ b/config/protocol.privnet.docker.four.yml @@ -1,15 +1,18 @@ ProtocolConfiguration: Magic: 56753 AddressVersion: 23 + SecondsPerBlock: 15 + LowPriorityThreshold: 0.000 StandbyValidators: - - 02b3622bf4017bdfe317c58aed5f4c753f206b7db896046fa7d774bbc4bf7f8dc2 - - 02103a7f7dd016558597f7960d27c516a4394fd968b9e65155eb4b013e4040406e - - 03d90c07df63e690ce77912e10ab51acc944b66860237b608c4f8f8309e71ee699 - - 02a7bc55fe8684e0119768d104ba30795bdcc86619e864add26156723ed185cd62 + - 02b3622bf4017bdfe317c58aed5f4c753f206b7db896046fa7d774bbc4bf7f8dc2 + - 02103a7f7dd016558597f7960d27c516a4394fd968b9e65155eb4b013e4040406e + - 03d90c07df63e690ce77912e10ab51acc944b66860237b608c4f8f8309e71ee699 + - 02a7bc55fe8684e0119768d104ba30795bdcc86619e864add26156723ed185cd62 SeedList: - - node_one:20334 - - node_two:20335 - - node_three:20336 + - 172.20.0.1:20331 + - 172.20.0.2:20332 + - 172.20.0.3:20333 + - 172.20.0.4:20334 SystemFee: EnrollmentTransaction: 1000 IssueTransaction: 500 @@ -25,7 +28,7 @@ ApplicationConfiguration: Type: "leveldb" #other options: 'inmemory','redis','boltdb'. # DB type options. Uncomment those you need in case you want to switch DB type. LevelDBOptions: - DataDirectoryPath: "./chains/privnet" + DataDirectoryPath: "/chains/four" # RedisDBOptions: # Addr: "localhost:6379" # Password: "" @@ -34,7 +37,7 @@ ApplicationConfiguration: # FilePath: "./chains/privnet.bolt" # Uncomment in order to set up custom address for node. # Address: 127.0.0.1 - NodePort: 20337 + NodePort: 20334 Relay: true DialTimeout: 3 ProtoTickInterval: 2 @@ -44,7 +47,10 @@ ApplicationConfiguration: RPC: Enabled: true EnableCORSWorkaround: false - Port: 20336 + Port: 20344 Monitoring: Enabled: true - Port: 2112 + Port: 20354 + UnlockWallet: + Path: "6PYRXVwHSqFSukL3CuXxdQ75VmsKpjeLgQLEjt83FrtHf1gCVphHzdD4nc" + Password: "four" diff --git a/config/protocol.privnet.docker.one.yml b/config/protocol.privnet.docker.one.yml index 1e2365ce9..0a6d50d5b 100644 --- a/config/protocol.privnet.docker.one.yml +++ b/config/protocol.privnet.docker.one.yml @@ -1,12 +1,18 @@ ProtocolConfiguration: Magic: 56753 AddressVersion: 23 + SecondsPerBlock: 15 + LowPriorityThreshold: 0.000 StandbyValidators: - - 02b3622bf4017bdfe317c58aed5f4c753f206b7db896046fa7d774bbc4bf7f8dc2 - - 02103a7f7dd016558597f7960d27c516a4394fd968b9e65155eb4b013e4040406e - - 03d90c07df63e690ce77912e10ab51acc944b66860237b608c4f8f8309e71ee699 - - 02a7bc55fe8684e0119768d104ba30795bdcc86619e864add26156723ed185cd62 - SeedList: [] + - 02b3622bf4017bdfe317c58aed5f4c753f206b7db896046fa7d774bbc4bf7f8dc2 + - 02103a7f7dd016558597f7960d27c516a4394fd968b9e65155eb4b013e4040406e + - 03d90c07df63e690ce77912e10ab51acc944b66860237b608c4f8f8309e71ee699 + - 02a7bc55fe8684e0119768d104ba30795bdcc86619e864add26156723ed185cd62 + SeedList: + - 172.200.0.1:20331 + - 172.200.0.2:20332 + - 172.200.0.3:20333 + - 172.200.0.4:20334 SystemFee: EnrollmentTransaction: 1000 IssueTransaction: 500 @@ -22,7 +28,7 @@ ApplicationConfiguration: Type: "leveldb" #other options: 'inmemory','redis','boltdb'. # DB type options. Uncomment those you need in case you want to switch DB type. LevelDBOptions: - DataDirectoryPath: "./chains/privnet" + DataDirectoryPath: "/chains/one" # RedisDBOptions: # Addr: "localhost:6379" # Password: "" @@ -31,7 +37,7 @@ ApplicationConfiguration: # FilePath: "./chains/privnet.bolt" # Uncomment in order to set up custom address for node. # Address: 127.0.0.1 - NodePort: 20334 + NodePort: 20331 Relay: true DialTimeout: 3 ProtoTickInterval: 2 @@ -41,7 +47,10 @@ ApplicationConfiguration: RPC: Enabled: true EnableCORSWorkaround: false - Port: 20333 + Port: 20341 Monitoring: Enabled: true - Port: 2112 + Port: 20351 + UnlockWallet: + Path: "6PYLmjBYJ4wQTCEfqvnznGJwZeW9pfUcV5m5oreHxqryUgqKpTRAFt9L8Y" + Password: "one" diff --git a/config/protocol.privnet.docker.three.yml b/config/protocol.privnet.docker.three.yml index 9d1c82ef7..135f83c4b 100644 --- a/config/protocol.privnet.docker.three.yml +++ b/config/protocol.privnet.docker.three.yml @@ -1,12 +1,18 @@ ProtocolConfiguration: Magic: 56753 AddressVersion: 23 + SecondsPerBlock: 15 + LowPriorityThreshold: 0.000 StandbyValidators: - - 02b3622bf4017bdfe317c58aed5f4c753f206b7db896046fa7d774bbc4bf7f8dc2 - - 02103a7f7dd016558597f7960d27c516a4394fd968b9e65155eb4b013e4040406e - - 03d90c07df63e690ce77912e10ab51acc944b66860237b608c4f8f8309e71ee699 - - 02a7bc55fe8684e0119768d104ba30795bdcc86619e864add26156723ed185cd62 - SeedList: [] + - 02b3622bf4017bdfe317c58aed5f4c753f206b7db896046fa7d774bbc4bf7f8dc2 + - 02103a7f7dd016558597f7960d27c516a4394fd968b9e65155eb4b013e4040406e + - 03d90c07df63e690ce77912e10ab51acc944b66860237b608c4f8f8309e71ee699 + - 02a7bc55fe8684e0119768d104ba30795bdcc86619e864add26156723ed185cd62 + SeedList: + - 172.200.0.1:20331 + - 172.200.0.2:20332 + - 172.200.0.3:20333 + - 172.200.0.4:20334 SystemFee: EnrollmentTransaction: 1000 IssueTransaction: 500 @@ -22,7 +28,7 @@ ApplicationConfiguration: Type: "leveldb" #other options: 'inmemory','redis','boltdb'. # DB type options. Uncomment those you need in case you want to switch DB type. LevelDBOptions: - DataDirectoryPath: "./chains/privnet" + DataDirectoryPath: "/chains/three" # RedisDBOptions: # Addr: "localhost:6379" # Password: "" @@ -31,7 +37,7 @@ ApplicationConfiguration: # FilePath: "./chains/privnet.bolt" # Uncomment in order to set up custom address for node. # Address: 127.0.0.1 - NodePort: 20336 + NodePort: 20333 Relay: true DialTimeout: 3 ProtoTickInterval: 2 @@ -41,7 +47,10 @@ ApplicationConfiguration: RPC: Enabled: true EnableCORSWorkaround: false - Port: 20335 + Port: 20343 Monitoring: Enabled: true - Port: 2112 + Port: 20353 + UnlockWallet: + Path: "6PYX86vYiHfUbpD95hfN1xgnvcSxy5skxfWYKu3ztjecxk6ikYs2kcWbeh" + Password: "three" diff --git a/config/protocol.privnet.docker.two.yml b/config/protocol.privnet.docker.two.yml index 7f5bf917d..eb4694d33 100644 --- a/config/protocol.privnet.docker.two.yml +++ b/config/protocol.privnet.docker.two.yml @@ -1,12 +1,18 @@ ProtocolConfiguration: Magic: 56753 AddressVersion: 23 + SecondsPerBlock: 15 + LowPriorityThreshold: 0.000 StandbyValidators: - - 02b3622bf4017bdfe317c58aed5f4c753f206b7db896046fa7d774bbc4bf7f8dc2 - - 02103a7f7dd016558597f7960d27c516a4394fd968b9e65155eb4b013e4040406e - - 03d90c07df63e690ce77912e10ab51acc944b66860237b608c4f8f8309e71ee699 - - 02a7bc55fe8684e0119768d104ba30795bdcc86619e864add26156723ed185cd62 - SeedList: [] + - 02b3622bf4017bdfe317c58aed5f4c753f206b7db896046fa7d774bbc4bf7f8dc2 + - 02103a7f7dd016558597f7960d27c516a4394fd968b9e65155eb4b013e4040406e + - 03d90c07df63e690ce77912e10ab51acc944b66860237b608c4f8f8309e71ee699 + - 02a7bc55fe8684e0119768d104ba30795bdcc86619e864add26156723ed185cd62 + SeedList: + - 172.200.0.1:20331 + - 172.200.0.2:20332 + - 172.200.0.3:20333 + - 172.200.0.4:20334 SystemFee: EnrollmentTransaction: 1000 IssueTransaction: 500 @@ -22,7 +28,7 @@ ApplicationConfiguration: Type: "leveldb" #other options: 'inmemory','redis','boltdb'. # DB type options. Uncomment those you need in case you want to switch DB type. LevelDBOptions: - DataDirectoryPath: "./chains/privnet" + DataDirectoryPath: "/chains/two" # RedisDBOptions: # Addr: "localhost:6379" # Password: "" @@ -31,7 +37,7 @@ ApplicationConfiguration: # FilePath: "./chains/privnet.bolt" # Uncomment in order to set up custom address for node. # Address: 127.0.0.1 - NodePort: 20335 + NodePort: 20332 Relay: true DialTimeout: 3 ProtoTickInterval: 2 @@ -41,7 +47,10 @@ ApplicationConfiguration: RPC: Enabled: true EnableCORSWorkaround: false - Port: 20334 + Port: 20342 Monitoring: Enabled: true - Port: 2112 + Port: 20352 + UnlockWallet: + Path: "6PYXHjPaNvW8YknSXaKsTWjf9FRxo1s4naV2jdmSQEgzaqKGX368rndN3L" + Password: "two" diff --git a/docker-compose.yml b/docker-compose.yml deleted file mode 100644 index 605351961..000000000 --- a/docker-compose.yml +++ /dev/null @@ -1,38 +0,0 @@ -version: '3' -services: - node_one: - build: . - volumes: - - ./config/protocol.privnet.docker.one.yml:/config/protocol.privnet.yml - - ./chains/privnet-docker-one:/chains/privnet - ports: - - 20334:20334 - command: "node --config-path /config --privnet" - node_two: - build: . - volumes: - - ./config/protocol.privnet.docker.two.yml:/config/protocol.privnet.yml - - ./chains/privnet-docker-two:/chains/privnet - ports: - - 20335:20335 - command: "node --config-path /config --privnet" - node_three: - build: . - volumes: - - ./config/protocol.privnet.docker.three.yml:/config/protocol.privnet.yml - - ./chains/privnet-docker-three:/chains/privnet - ports: - - 20336:20336 - command: "node --config-path /config --privnet" - node_four: - build: . - volumes: - - ./config/protocol.privnet.docker.four.yml:/config/protocol.privnet.yml - - ./chains/privnet-docker-four:/chains/privnet - ports: - - 20337:20337 - command: "node --config-path /config --privnet" - depends_on: - - node_one - - node_two - - node_three