From 32a0006acc7d7ca873025ba52eeff841a7b9f72d Mon Sep 17 00:00:00 2001 From: sveneh Date: Wed, 18 Feb 2015 17:17:05 +0100 Subject: [PATCH] adjusted to support Go networking poc-8, using the automatic Docker build from gitub go-ethereum, refactored global variables into separate file. Closes #30 , again. --- .gitignore | 2 + ansible/client-reset-debug.yml | 18 ++++++++ ansible/client-start-debug.yml | 2 +- ansible/client-stop-debug.yml | 2 +- ansible/group_vars/all | 10 ++++ .../boot/files/docker-go-boot/Dockerfile | 9 ++++ ansible/roles/boot/tasks/main.yml | 39 ++++++++++++++-- ansible/roles/boot/vars/main.yml | 2 + ansible/roles/clients/tasks/init.yml | 4 +- ansible/roles/clients/tasks/setup.yml | 4 +- ansible/roles/clients/tasks/start.yml | 30 ++++++++++-- ansible/roles/clients/tasks/stop.yml | 4 +- ansible/roles/clients/vars/main.yml | 2 +- ansible/roles/ec2/tasks/setup.yml | 8 +++- docker-go/Dockerfile | 46 ------------------- scenarios/clients.py | 42 +++++++++++------ 16 files changed, 144 insertions(+), 80 deletions(-) create mode 100644 ansible/client-reset-debug.yml create mode 100644 ansible/group_vars/all create mode 100644 ansible/roles/boot/files/docker-go-boot/Dockerfile create mode 100644 ansible/roles/boot/vars/main.yml delete mode 100644 docker-go/Dockerfile diff --git a/.gitignore b/.gitignore index 4a20803..40abe29 100644 --- a/.gitignore +++ b/.gitignore @@ -1,9 +1,11 @@ system-testing.pem ping.yml testing.yml +test.yml venv/ *.pyc *.sw? +*.bak *~ roles/aws/tasks/add_host.yml roles/aws/tasks/check_ssh.yml diff --git a/ansible/client-reset-debug.yml b/ansible/client-reset-debug.yml new file mode 100644 index 0000000..3665ca3 --- /dev/null +++ b/ansible/client-reset-debug.yml @@ -0,0 +1,18 @@ +--- +# this is just for testing. +- name: Ansible-only testing scenario +# hosts: tag_Name_client-01 + hosts: tag_Role_client + remote_user: ubuntu + gather_facts: false + roles: + - clients + + tasks: + - include: roles/clients/tasks/reset.yml + vars: + + # these are normally set from the python controller + docker_container_id: + go: container_go + python: container_python diff --git a/ansible/client-start-debug.yml b/ansible/client-start-debug.yml index b1dd9ae..6f08ca1 100644 --- a/ansible/client-start-debug.yml +++ b/ansible/client-start-debug.yml @@ -21,7 +21,7 @@ python: container_python docker_run_args: - go: -loglevel=5 -seednode={{ groups['tag_Name_boot'][0] }}:30303 -maxpeer={{ dbg_req_num_peers }} + go: -loglevel=5 -port=30000 -bootnodes=enode://{{ g_boot_public_key }}@{{ groups['tag_Name_boot'][0] }}:30303 -maxpeer={{ dbg_req_num_peers }} python: --logging :debug --log_json 1 --remote {{ groups['tag_Name_boot'][0] }} --port 30303 --mining {{ dbg_mining_cpu_percentage }} --peers {{ dbg_req_num_peers }} docker_tee_args: diff --git a/ansible/client-stop-debug.yml b/ansible/client-stop-debug.yml index e2d750b..b8e96d2 100644 --- a/ansible/client-stop-debug.yml +++ b/ansible/client-stop-debug.yml @@ -9,7 +9,7 @@ - clients tasks: - - include: roles/clients/tasks/reset.yml + - include: roles/clients/tasks/stop.yml vars: # these are normally set from the python controller diff --git a/ansible/group_vars/all b/ansible/group_vars/all new file mode 100644 index 0000000..a2b0702 --- /dev/null +++ b/ansible/group_vars/all @@ -0,0 +1,10 @@ +--- +# these are variables needed in multiple places in the playbooks. They are all name-space'd with g_lobal + +# the docker images we use for client +g_docker_image: + go: ethereum/client-go + python: sveneh/pyethereum-develop + +# the private key of the bootstrap node is defined in roles/boot/vars/main.yml, this is only the public key +g_boot_public_key: 829bb728a1b38d2e3bb8288d750502f7dce2ee329aaebf48ddc54e0cfc8003b3068fe57e20277ba50e42826c4d2bfcb172699e108d9e90b3339f8b6589449faf diff --git a/ansible/roles/boot/files/docker-go-boot/Dockerfile b/ansible/roles/boot/files/docker-go-boot/Dockerfile new file mode 100644 index 0000000..91a6438 --- /dev/null +++ b/ansible/roles/boot/files/docker-go-boot/Dockerfile @@ -0,0 +1,9 @@ +# ethereum go bootnode +FROM ethereum/client-go + +WORKDIR $GOPATH/src/github.com/ethereum/go-ethereum +RUN git checkout develop +RUN godep restore +RUN go install -v ./cmd/bootnode + +ENTRYPOINT ["bootnode"] diff --git a/ansible/roles/boot/tasks/main.yml b/ansible/roles/boot/tasks/main.yml index bea0d1d..1cb5a5a 100644 --- a/ansible/roles/boot/tasks/main.yml +++ b/ansible/roles/boot/tasks/main.yml @@ -6,12 +6,41 @@ # ports: 30303:30303 # command: --client-name bootstrap --mining off +- name: download / updates latest Go clients base via docker + sudo: true + # the official ansible docker module does not have the option to just pull the image, it will also run it + shell: docker pull {{ g_docker_image['go'] }} + register: docker_pull_out + changed_when: '"Downloaded newer image" in docker_pull_out.stdout' -- name: Start bootstrapping node (python client) +- name: Prepare building go bootstrap image + copy: src=../files/docker-go-boot dest=/tmp + +- name: Build go bootstrap image locally + sudo: yes + docker_image: + path: /tmp/docker-go-boot + name: local/eth-go-boot + state: build + + +- name: Start bootstrapping node (go) sudo: yes docker: - image: sveneh/pyethereum-develop - expose: 30303 - ports: 30303:30303 - command: --peers 0 --mining 0 + image: local/eth-go-boot + expose: + - 30303/tcp + - 30303/udp + ports: + - 30303:30303/tcp + - 30303:30303/udp + command: -nodekeyhex={{ boot_private_key }} -addr=:30303 + +#- name: Start bootstrapping node (python client) +# sudo: yes +# docker: +# image: sveneh/pyethereum-develop +# expose: 30303 +# ports: 30303:30303 +# command: --peers 0 --mining 0 diff --git a/ansible/roles/boot/vars/main.yml b/ansible/roles/boot/vars/main.yml new file mode 100644 index 0000000..4efba60 --- /dev/null +++ b/ansible/roles/boot/vars/main.yml @@ -0,0 +1,2 @@ +--- +boot_private_key: 4742e32d05c9f8b7016db3444664f4cf82c3362e002d09429cad411569b07763 diff --git a/ansible/roles/clients/tasks/init.yml b/ansible/roles/clients/tasks/init.yml index 7beacc1..08b0fcf 100644 --- a/ansible/roles/clients/tasks/init.yml +++ b/ansible/roles/clients/tasks/init.yml @@ -1,7 +1,7 @@ --- - name: initial start of ethereum go client, connection to bootstrapping node docker: - image: "{{ docker_image['go'] }}" + image: "{{ g_docker_image['go'] }}" name: "{{ dbg_container_id }}_go" expose: ["8080", "30303"] ports: ["20000:30203", "30000:30303"] @@ -13,7 +13,7 @@ - name: initial start of ethereum python client, connection to bootstrapping node docker: - image: "{{ docker_image['python'] }}" + image: "{{ g_docker_image['python'] }}" name: "{{ dbg_container_id }}_python" expose: ["30203", "30303"] ports: ["22000:30203", "32000:30303"] diff --git a/ansible/roles/clients/tasks/setup.yml b/ansible/roles/clients/tasks/setup.yml index 0a4f5fb..a4c55b6 100644 --- a/ansible/roles/clients/tasks/setup.yml +++ b/ansible/roles/clients/tasks/setup.yml @@ -2,10 +2,12 @@ - name: download latest clients via docker sudo: true # the official ansible docker module does not have the option to just pull the image, it will also run it - shell: docker pull {{ docker_image[item] }} + shell: docker pull {{ g_docker_image[item] }} with_items: - go - python + register: docker_pull_out + changed_when: '"Downloaded newer image" in docker_pull_out.stdout' - name: checkout git system-testing repo git: diff --git a/ansible/roles/clients/tasks/start.yml b/ansible/roles/clients/tasks/start.yml index 92e3930..29ab728 100644 --- a/ansible/roles/clients/tasks/start.yml +++ b/ansible/roles/clients/tasks/start.yml @@ -4,17 +4,23 @@ - name: start go client with parameters from inventory file docker: - image: "{{ docker_image['go'] }}" + image: "{{ g_docker_image['go'] }}" name: "{{ docker_container_id['go'] }}" - expose: ["8080", "30303"] - ports: ["20000:30203", "30000:30303"] + expose: + - 8545 + - 30000/udp + - 30000/tcp + ports: + - 20000:8545/tcp + - 30000:30000/udp + - 30000:30000/tcp command: "{{ docker_run_args['go'] }}" tags: - go - name: start python client with parameters from inventory file docker: - image: "{{ docker_image['python'] }}" + image: "{{ g_docker_image['python'] }}" name: "{{ docker_container_id['python'] }}" expose: ["30203", "30303"] ports: ["22000:30203", "32000:30303"] @@ -22,6 +28,22 @@ tags: - python + +- name: ensure the go clients runs, check cmd-line parameters if this fails + shell: docker ps + register: docker_ps_out + failed_when: not docker_container_id['go'] in docker_ps_out.stdout + tags: + - go + + +- name: ensure the python clients runs, check cmd-line parameters if this fails + shell: docker ps + register: docker_ps_out + failed_when: not docker_container_id['python'] in docker_ps_out.stdout + tags: + - python + - name: Forward go logfiles with parameters from inventory file # fire and forget, don't wait to finish, run for one day async: 86400 diff --git a/ansible/roles/clients/tasks/stop.yml b/ansible/roles/clients/tasks/stop.yml index 845f180..870a7f2 100644 --- a/ansible/roles/clients/tasks/stop.yml +++ b/ansible/roles/clients/tasks/stop.yml @@ -11,7 +11,7 @@ - name: Persist state of stopped go client # ansible docker module does not support this ... - shell: docker commit {{ docker_container_id['go'] }} {{ docker_image['go'] }} + shell: docker commit {{ docker_container_id['go'] }} {{ g_docker_image['go'] }} ignore_errors: true tags: - go @@ -33,7 +33,7 @@ - name: Persist state of stopped python client # ansible docker module does not support this ... - shell: docker commit {{ docker_container_id['python'] }} {{ docker_image['python'] }} + shell: docker commit {{ docker_container_id['python'] }} {{ g_docker_image['python'] }} ignore_errors: true tags: - python diff --git a/ansible/roles/clients/vars/main.yml b/ansible/roles/clients/vars/main.yml index 93da9fd..aa162cf 100644 --- a/ansible/roles/clients/vars/main.yml +++ b/ansible/roles/clients/vars/main.yml @@ -3,5 +3,5 @@ repo_path: /home/ubuntu/git docker_image: - go: sveneh/go-ethereum + go: ethereum/client-go python: sveneh/pyethereum-develop diff --git a/ansible/roles/ec2/tasks/setup.yml b/ansible/roles/ec2/tasks/setup.yml index 9a403f0..4bb165d 100644 --- a/ansible/roles/ec2/tasks/setup.yml +++ b/ansible/roles/ec2/tasks/setup.yml @@ -15,10 +15,14 @@ from_port: 20000 to_port: 22999 cidr_ip: "{{ ec2_ip_access_range }}" - # ethereum incoming connection port + # ethereum incoming connection ports + - proto: udp + from_port: 30000 + to_port: 32999 + cidr_ip: "{{ ec2_ip_access_range }}" - proto: tcp from_port: 30000 - to_port: 33303 + to_port: 32999 cidr_ip: "{{ ec2_ip_access_range }}" rules_egress: - proto: all diff --git a/docker-go/Dockerfile b/docker-go/Dockerfile deleted file mode 100644 index 730708f..0000000 --- a/docker-go/Dockerfile +++ /dev/null @@ -1,46 +0,0 @@ -# Adjusted from https://github.com/ethereum/go-ethereum/blob/develop/Dockerfile -FROM ubuntu:14.04 - -## Environment setup -ENV HOME /root -ENV GOPATH /root/go -ENV PATH /golang/bin:/root/go/bin:/usr/local/go/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games -ENV PKG_CONFIG_PATH /opt/qt54/lib/pkgconfig - -RUN mkdir -p /root/go -ENV DEBIAN_FRONTEND noninteractive - -## Install base dependencies -RUN apt-get update && apt-get upgrade -y -RUN apt-get install -y git mercurial build-essential software-properties-common pkg-config libgmp3-dev libreadline6-dev libpcre3-dev libpcre++-dev mesa-common-dev libglu1-mesa-dev - -## Install Qt5.4 dependencies from PPA -RUN add-apt-repository ppa:beineri/opt-qt54-trusty -y -RUN apt-get update -y -RUN apt-get install -y qt54quickcontrols qt54webengine - -## Build and install latest Go -RUN git clone https://go.googlesource.com/go golang -RUN cd golang && git checkout go1.4.1 -RUN cd golang/src && ./make.bash && go version - -## Fetch and install QML -RUN go get -u -v -d github.com/obscuren/qml -WORKDIR $GOPATH/src/github.com/obscuren/qml -RUN git checkout v1 -RUN go install -v - -# this is a workaround, to make sure that docker's cache is invalidated whenever the git repo changes -ADD https://api.github.com/repos/ethereum/go-ethereum/git/refs/heads/develop unused.txt - -## Fetch and install go-ethereum -RUN go get -u -v -d github.com/ethereum/go-ethereum/... -WORKDIR $GOPATH/src/github.com/ethereum/go-ethereum - -RUN git checkout develop -RUN git pull - -RUN ETH_DEPS=$(go list -f '{{.Imports}} {{.TestImports}} {{.XTestImports}}' github.com/ethereum/go-ethereum/... | sed -e 's/\[//g' | sed -e 's/\]//g' | sed -e 's/C //g'); if [ "$ETH_DEPS" ]; then go get $ETH_DEPS; fi -RUN go install -v ./cmd/ethereum - -ENTRYPOINT ["ethereum"] diff --git a/scenarios/clients.py b/scenarios/clients.py index 86c06fd..9f008e1 100644 --- a/scenarios/clients.py +++ b/scenarios/clients.py @@ -3,9 +3,8 @@ ansible --overwrite http://docs.ansible.com/developing_inventory.html http://docs.ansible.com/playbooks_variables.html#passing-variables-on-the-command-line - -docker_run_args = [] """ + from base import Inventory import nodeid_tool import json @@ -16,15 +15,21 @@ key_file = '../ansible/system-testing.pem' -# needs some for go, too -docker_run_args = '--logging :debug --log_json 1 --remote {bootstrap_ip} --port 30303 ' \ +use_impls = ['go'] + +# this must be the same as in ../ansible/group_vars/all +g_boot_public_key = '829bb728a1b38d2e3bb8288d750502f7dce2ee329aaebf48ddc54e0cfc8003b3068fe57e20277ba50e42826c4d2bfcb172699e108d9e90b3339f8b6589449faf' + +docker_run_args = {} +docker_run_args['go'] = '-port=30000 -loglevel=5 -bootnodes=enode://{bootstrap_public_key}@{bootstrap_ip}:30303 -maxpeer={req_num_peers}' +docker_run_args['python'] = '--logging :debug --log_json 1 --remote {bootstrap_ip} --port 30303 ' \ '--mining {mining_cpu_percentage} --peers {req_num_peers} --address {coinbase}' teees_args = '{elarch_ip} guid,{pubkey_hex}' mining_cpu_percentage = 50 req_num_peers = 4 -ansible_args = ['-u', 'ubuntu', '--private-key=../ansible/system-testing.pem'] +ansible_args = ['-u', 'ubuntu', '--private-key=../ansible/system-testing.pem', '-vv'] def mk_inventory_executable(inventory): @@ -39,7 +44,8 @@ def mk_inventory_executable(inventory): def exec_playbook(inventory, playbook): fn = mk_inventory_executable(inventory) # replace for go with --tags=go or delete to address both - args = ['ansible-playbook', '../ansible/%s' % playbook, '-i', fn, '--tags=python'] + ansible_args + impls = ','.join(use_impls) + args = ['ansible-playbook', '../ansible/%s' % playbook, '-i', fn, '--tags=%s' % impls] + ansible_args print 'executing', ' '.join(args) result = subprocess.call(args) if result: @@ -55,6 +61,8 @@ def start_clients(clients=[]): inventory = Inventory() clients = clients or list(inventory.clients) inventory.inventory['client_start_group'] = dict(children=clients, hosts=[]) + # print clients + # quit() assert inventory.es assert inventory.boot for client in clients: @@ -63,19 +71,23 @@ def start_clients(clients=[]): pubkey = nodeid_tool.topub(ext_id) coinbase = nodeid_tool.coinbase(ext_id) d = dict(hosts=inventory.inventory[client], vars=dict()) - dra = docker_run_args.format(bootstrap_ip=inventory.boot, + dra_go = docker_run_args['go'].format(bootstrap_public_key=g_boot_public_key, bootstrap_ip=inventory.boot, + req_num_peers=req_num_peers) + dra_python = docker_run_args['python'].format(bootstrap_ip=inventory.boot, mining_cpu_percentage=mining_cpu_percentage, req_num_peers=req_num_peers, coinbase=coinbase) - # add here go parmeters d['vars']['docker_run_args'] = {} - d['vars']['docker_run_args']['python'] = dra + d['vars']['docker_run_args']['go'] = dra_go + d['vars']['docker_run_args']['python'] = dra_python d['vars']['docker_container_id'] = {} - d['vars']['docker_container_id']['python'] = client + d['vars']['docker_container_id']['go'] = 'docker_go' + d['vars']['docker_container_id']['python'] = 'docker_python' d['vars']['docker_tee_args'] = {} + d['vars']['docker_tee_args']['go'] = teees_args.format(elarch_ip=inventory.es, pubkey_hex=pubkey) d['vars']['docker_tee_args']['python'] = teees_args.format(elarch_ip=inventory.es, pubkey_hex=pubkey) inventory.inventory[client] = d -# print json.dumps(inventory.inventory, indent=2) + print json.dumps(inventory.inventory, indent=2) exec_playbook(inventory.inventory, playbook='client-start.yml') @@ -89,10 +101,9 @@ def stop_clients(clients=[]): for client in clients: assert client d = dict(hosts=inventory.inventory[client], vars=dict()) - # add the same for go d['vars']['docker_container_id'] = {} - d['vars']['docker_container_id']['python'] = client - # add the same container id for go + d['vars']['docker_container_id']['go'] = 'docker_go' + d['vars']['docker_container_id']['python'] = 'docker_python' inventory.inventory[client] = d # print json.dumps(inventory.inventory, indent=2) exec_playbook(inventory.inventory, playbook='client-stop.yml') @@ -103,7 +114,8 @@ def stop_clients(clients=[]): args = sys.argv[1:] sys.argv = sys.argv[:1] # ec2.py peeks into args, so delete passing-variables-on-the-command-line if 'start' in args: - start_clients() + start_clients() + # start_clients([u'tag_Name_client-01']) elif 'stop' in args: stop_clients() else: