Role rework plus deployment tests (#116)
* Role-rework * Update readme.
This commit is contained in:
parent
59564bd600
commit
11c1595dd6
@ -120,6 +120,20 @@ jobs:
|
|||||||
key: initialize-{{ .Environment.CIRCLE_SHA1 }}
|
key: initialize-{{ .Environment.CIRCLE_SHA1 }}
|
||||||
- run: yarn workspace ui run coverage
|
- run: yarn workspace ui run coverage
|
||||||
- run: yarn workspace ui run coveralls
|
- run: yarn workspace ui run coveralls
|
||||||
|
deployment:
|
||||||
|
machine:
|
||||||
|
image: circleci/classic:latest
|
||||||
|
docker_layer_caching: true
|
||||||
|
steps:
|
||||||
|
- checkout
|
||||||
|
- run: git submodule update --init
|
||||||
|
- run: sudo add-apt-repository ppa:jonathonf/python-3.6 -y
|
||||||
|
- run: sudo apt-get update
|
||||||
|
- run: sudo apt-get install python3.6 -y
|
||||||
|
- run: sudo apt-get install python3-pip python3.6-dev -y
|
||||||
|
- run: cd deployment && virtualenv -p python3.6 venv
|
||||||
|
- run: cd deployment && source venv/bin/activate && pip install -r requirements.txt
|
||||||
|
- run: cd deployment && source venv/bin/activate && molecule test
|
||||||
workflows:
|
workflows:
|
||||||
version: 2
|
version: 2
|
||||||
tokenbridge:
|
tokenbridge:
|
||||||
@ -148,3 +162,4 @@ workflows:
|
|||||||
- oracle-e2e
|
- oracle-e2e
|
||||||
- ui-e2e
|
- ui-e2e
|
||||||
- monitor-e2e
|
- monitor-e2e
|
||||||
|
- deployment
|
||||||
|
2
.gitignore
vendored
2
.gitignore
vendored
@ -43,6 +43,8 @@ hosts
|
|||||||
Vagrantfile
|
Vagrantfile
|
||||||
vagrant-hosts.yml
|
vagrant-hosts.yml
|
||||||
.vagrant
|
.vagrant
|
||||||
|
deployment/venv
|
||||||
|
__pycache__
|
||||||
|
|
||||||
#monitor
|
#monitor
|
||||||
monitor/responses/*
|
monitor/responses/*
|
||||||
|
11
deployment/.yamllint
Normal file
11
deployment/.yamllint
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
extends: default
|
||||||
|
|
||||||
|
rules:
|
||||||
|
braces:
|
||||||
|
max-spaces-inside: 1
|
||||||
|
level: error
|
||||||
|
brackets:
|
||||||
|
max-spaces-inside: 1
|
||||||
|
level: error
|
||||||
|
line-length: disable
|
||||||
|
truthy: disable
|
@ -25,6 +25,8 @@ cp hosts.yml.example hosts.yml
|
|||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
<bridge_name>:
|
<bridge_name>:
|
||||||
|
children:
|
||||||
|
oracle:
|
||||||
hosts:
|
hosts:
|
||||||
<host_ip>:
|
<host_ip>:
|
||||||
ansible_user: <user>
|
ansible_user: <user>
|
||||||
|
@ -14,11 +14,9 @@ Please refer to [Configuration](./CONFIGURATION.md).
|
|||||||
|
|
||||||
Please refer to [Execution](./EXECUTION.md).
|
Please refer to [Execution](./EXECUTION.md).
|
||||||
|
|
||||||
## Linting
|
## Testing
|
||||||
|
|
||||||
- [ansible-lint](https://github.com/ansible/ansible-lint) is required
|
Please refer to [Testing](./TESTING.md).
|
||||||
|
|
||||||
`yarn ansible-lint`
|
|
||||||
|
|
||||||
## Contributing
|
## Contributing
|
||||||
|
|
||||||
|
24
deployment/TESTING.md
Normal file
24
deployment/TESTING.md
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
# POA Token Bridge / Deployment Testing
|
||||||
|
|
||||||
|
The deployment playbooks are tested using [Molecule](https://molecule.readthedocs.io).
|
||||||
|
|
||||||
|
## Prepare virtual python environment
|
||||||
|
|
||||||
|
```
|
||||||
|
command -v virtualenv || pip3 install virtualenv
|
||||||
|
virtualenv -p python3 venv
|
||||||
|
source venv/bin/activate
|
||||||
|
pip install -r requirements.txt
|
||||||
|
```
|
||||||
|
|
||||||
|
## Run the tests
|
||||||
|
|
||||||
|
```
|
||||||
|
molecule test
|
||||||
|
```
|
||||||
|
|
||||||
|
## Exit the virtual environment
|
||||||
|
|
||||||
|
```
|
||||||
|
deactivate
|
||||||
|
```
|
@ -1,4 +1,6 @@
|
|||||||
sokol-kovan:
|
sokol-kovan:
|
||||||
|
children:
|
||||||
|
oracle:
|
||||||
hosts:
|
hosts:
|
||||||
127.0.0.1:
|
127.0.0.1:
|
||||||
ansible_user: ubuntu
|
ansible_user: ubuntu
|
||||||
|
14
deployment/molecule/default/Dockerfile.j2
Normal file
14
deployment/molecule/default/Dockerfile.j2
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
# Molecule managed
|
||||||
|
|
||||||
|
{% if item.registry is defined %}
|
||||||
|
FROM {{ item.registry.url }}/{{ item.image }}
|
||||||
|
{% else %}
|
||||||
|
FROM {{ item.image }}
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
RUN if [ $(command -v apt-get) ]; then apt-get update && apt-get install -y python sudo bash ca-certificates && apt-get clean; \
|
||||||
|
elif [ $(command -v dnf) ]; then dnf makecache && dnf --assumeyes install python sudo python-devel python*-dnf bash && dnf clean all; \
|
||||||
|
elif [ $(command -v yum) ]; then yum makecache fast && yum install -y python sudo yum-plugin-ovl bash && sed -i 's/plugins=0/plugins=1/g' /etc/yum.conf && yum clean all; \
|
||||||
|
elif [ $(command -v zypper) ]; then zypper refresh && zypper install -y python sudo bash python-xml && zypper clean -a; \
|
||||||
|
elif [ $(command -v apk) ]; then apk update && apk add --no-cache python sudo bash ca-certificates; \
|
||||||
|
elif [ $(command -v xbps-install) ]; then xbps-install -Syu && xbps-install -y python sudo bash ca-certificates && xbps-remove -O; fi
|
49
deployment/molecule/default/molecule.yml
Normal file
49
deployment/molecule/default/molecule.yml
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
---
|
||||||
|
dependency:
|
||||||
|
name: galaxy
|
||||||
|
driver:
|
||||||
|
name: docker
|
||||||
|
lint:
|
||||||
|
name: yamllint
|
||||||
|
enabled: False
|
||||||
|
platforms:
|
||||||
|
- name: oracle-host
|
||||||
|
groups:
|
||||||
|
- example
|
||||||
|
children:
|
||||||
|
- oracle
|
||||||
|
image: ubuntu:16.04
|
||||||
|
privileged: true
|
||||||
|
network_mode: host
|
||||||
|
volumes:
|
||||||
|
- /var/run/docker.sock:/var/run/docker.sock
|
||||||
|
provisioner:
|
||||||
|
name: ansible
|
||||||
|
lint:
|
||||||
|
name: ansible-lint
|
||||||
|
enabled: False
|
||||||
|
playbooks:
|
||||||
|
prepare: prepare.yml
|
||||||
|
converge: ../../site.yml
|
||||||
|
inventory:
|
||||||
|
host_vars:
|
||||||
|
oracle-host:
|
||||||
|
VALIDATOR_ADDRESS_PRIVATE_KEY: "8e829f695aed89a154550f30262f1529582cc49dc30eff74a6b491359e0230f9"
|
||||||
|
syslog_server_port: "udp://127.0.0.1:514"
|
||||||
|
verifier:
|
||||||
|
name: testinfra
|
||||||
|
lint:
|
||||||
|
name: flake8
|
||||||
|
scenario:
|
||||||
|
name: default
|
||||||
|
test_sequence:
|
||||||
|
- lint
|
||||||
|
- cleanup
|
||||||
|
- destroy
|
||||||
|
- dependency
|
||||||
|
- syntax
|
||||||
|
- create
|
||||||
|
- prepare
|
||||||
|
- converge
|
||||||
|
- verify
|
||||||
|
- destroy
|
13
deployment/molecule/default/prepare.yml
Normal file
13
deployment/molecule/default/prepare.yml
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
---
|
||||||
|
- name: prepare
|
||||||
|
hosts: all
|
||||||
|
tasks:
|
||||||
|
- name: install apt packages
|
||||||
|
apt:
|
||||||
|
name: "{{ packages }}"
|
||||||
|
vars:
|
||||||
|
packages:
|
||||||
|
- apt-transport-https
|
||||||
|
- rsyslog
|
||||||
|
- shell: service rsyslog start
|
||||||
|
- shell: groupadd docker && chgrp docker /var/run/docker.sock
|
20
deployment/molecule/default/tests/test_all.py
Normal file
20
deployment/molecule/default/tests/test_all.py
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
import os
|
||||||
|
import testinfra.utils.ansible_runner
|
||||||
|
|
||||||
|
testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner(
|
||||||
|
os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('all')
|
||||||
|
|
||||||
|
|
||||||
|
def test_repo(host):
|
||||||
|
assert host.file('/home/poadocker/bridge').exists
|
||||||
|
assert host.file('/home/poadocker/bridge').is_directory
|
||||||
|
assert host.file('/home/poadocker/bridge/package.json').exists
|
||||||
|
|
||||||
|
|
||||||
|
def test_docker_group(host):
|
||||||
|
assert host.group('docker').exists
|
||||||
|
|
||||||
|
|
||||||
|
def test_user(host):
|
||||||
|
assert host.user('poadocker').exists
|
||||||
|
assert 'docker' in host.user('poadocker').groups
|
37
deployment/molecule/default/tests/test_oracle.py
Normal file
37
deployment/molecule/default/tests/test_oracle.py
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
import os
|
||||||
|
import pytest
|
||||||
|
import testinfra.utils.ansible_runner
|
||||||
|
|
||||||
|
testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner(
|
||||||
|
os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('oracle')
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize("name", [
|
||||||
|
("oracle_rabbit_1"),
|
||||||
|
("oracle_redis_1"),
|
||||||
|
("oracle_bridge_request_1"),
|
||||||
|
("oracle_bridge_collected_1"),
|
||||||
|
("oracle_bridge_affirmation_1"),
|
||||||
|
("oracle_bridge_senderhome_1"),
|
||||||
|
("oracle_bridge_senderforeign_1"),
|
||||||
|
])
|
||||||
|
def test_docker_containers(host, name):
|
||||||
|
container = host.docker(name)
|
||||||
|
assert container.is_running
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize("service", [
|
||||||
|
("poabridge"),
|
||||||
|
("rsyslog")
|
||||||
|
])
|
||||||
|
def test_services(host, service):
|
||||||
|
assert host.service(service).is_enabled
|
||||||
|
assert host.service(service).is_running
|
||||||
|
|
||||||
|
|
||||||
|
def test_remote_logging(host):
|
||||||
|
assert host.file('/etc/rsyslog.d/35-remote-logging.conf').exists
|
||||||
|
|
||||||
|
|
||||||
|
def test_docker_config(host):
|
||||||
|
assert host.file('/etc/docker/daemon.json').exists
|
4
deployment/requirements.txt
Normal file
4
deployment/requirements.txt
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
# pre-release because it contains "CI Fixes for ansible 2.8"
|
||||||
|
molecule==2.22rc1
|
||||||
|
docker
|
||||||
|
flake8
|
@ -1,3 +1,5 @@
|
|||||||
|
docker_compose_version: 1.23.2
|
||||||
|
compose_service_user: poadocker
|
||||||
bridge_path: "/home/{{ compose_service_user }}/bridge"
|
bridge_path: "/home/{{ compose_service_user }}/bridge"
|
||||||
bridge_repo: https://github.com/poanetwork/tokenbridge.git
|
bridge_repo: https://github.com/poanetwork/tokenbridge.git
|
||||||
bridge_repo_branch: master
|
bridge_repo_branch: master
|
@ -67,7 +67,7 @@
|
|||||||
- name: Configure docker engine
|
- name: Configure docker engine
|
||||||
copy:
|
copy:
|
||||||
src: daemon.json
|
src: daemon.json
|
||||||
dest: /etc/docker/daemon.json
|
dest: /etc/docker/
|
||||||
owner: root
|
owner: root
|
||||||
group: root
|
group: root
|
||||||
mode: 0640
|
mode: 0640
|
3
deployment/roles/common/tasks/main.yml
Normal file
3
deployment/roles/common/tasks/main.yml
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
- include_tasks: python.yml
|
||||||
|
- include_tasks: dependencies.yml
|
||||||
|
- include_tasks: repo.yml
|
2
deployment/roles/common/tasks/python.yml
Normal file
2
deployment/roles/common/tasks/python.yml
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
- name: Install python if necessary
|
||||||
|
raw: "test -e {{ ansible_python_interpreter | default ('/usr/bin/python') }} || (sudo apt -y update && sudo apt install -y python-minimal)"
|
@ -1,17 +0,0 @@
|
|||||||
This role installs required dependencies:
|
|
||||||
|
|
||||||
* apt-transport-https
|
|
||||||
|
|
||||||
* ca-certificates
|
|
||||||
|
|
||||||
* curl
|
|
||||||
|
|
||||||
* software-properties-common
|
|
||||||
|
|
||||||
* docker-ce (+python library)
|
|
||||||
|
|
||||||
* docker-compose (+python library)
|
|
||||||
|
|
||||||
* git
|
|
||||||
|
|
||||||
* python-pip
|
|
@ -1,2 +0,0 @@
|
|||||||
docker_compose_version: 1.22.0
|
|
||||||
compose_service_user: poadocker
|
|
@ -1 +0,0 @@
|
|||||||
This role brings up a docker container using docker-compose.
|
|
@ -1 +0,0 @@
|
|||||||
bridge_path: "/home/{{ compose_service_user }}/bridge"
|
|
@ -1 +0,0 @@
|
|||||||
This role sets up remote logging for services.
|
|
@ -1,2 +0,0 @@
|
|||||||
bridge_path: "/home/{{ compose_service_user }}/bridge"
|
|
||||||
syslog_server_port: udp://127.0.0.1:514
|
|
@ -1,6 +1,7 @@
|
|||||||
bridge_path: "/home/{{ compose_service_user }}/bridge"
|
bridge_path: "/home/{{ compose_service_user }}/bridge"
|
||||||
|
|
||||||
ALLOW_HTTP: no
|
ALLOW_HTTP: no
|
||||||
QUEUE_URL: amqp://rabbit
|
QUEUE_URL: amqp://rabbit
|
||||||
REDIS_URL: redis://redis
|
REDIS_URL: redis://redis
|
||||||
REDIS_LOCK_TTL: 1000
|
REDIS_LOCK_TTL: 1000
|
||||||
|
syslog_server_port: udp://127.0.0.1:514
|
||||||
|
keyfile_path: "/root/.key"
|
2
deployment/roles/oracle/meta/main.yml
Normal file
2
deployment/roles/oracle/meta/main.yml
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
dependencies:
|
||||||
|
- role: common
|
5
deployment/roles/oracle/tasks/main.yml
Normal file
5
deployment/roles/oracle/tasks/main.yml
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
- include_tasks: pre_config.yml
|
||||||
|
- include_tasks: jumpbox.yml
|
||||||
|
- include_tasks: post_config.yml
|
||||||
|
- include_tasks: logging.yml
|
||||||
|
- include_tasks: servinstall.yml
|
17
deployment/roles/oracle/tasks/servinstall.yml
Normal file
17
deployment/roles/oracle/tasks/servinstall.yml
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
# This role creates a poabridge service which is designed to manage docker-compose bridge deployment.
|
||||||
|
# /etc/init.d/poabridge start, status, stop, restart - does what the services usually do in such cases.
|
||||||
|
# /etc/init.d/poabridge rebuild - builds a new bridge deployment from scratch.
|
||||||
|
---
|
||||||
|
- name: "Set poabridge service"
|
||||||
|
template:
|
||||||
|
src: poabridge.j2
|
||||||
|
dest: "/etc/init.d/poabridge"
|
||||||
|
owner: root
|
||||||
|
mode: 755
|
||||||
|
|
||||||
|
- name: "Start/Enable poabridge service"
|
||||||
|
service:
|
||||||
|
name: "poabridge"
|
||||||
|
state: started
|
||||||
|
enabled: yes
|
||||||
|
use: service
|
0
deployment/roles/logging/templates/docker-logs.j2 → deployment/roles/oracle/templates/docker-logs.j2
0
deployment/roles/logging/templates/docker-logs.j2 → deployment/roles/oracle/templates/docker-logs.j2
0
deployment/roles/servinstall/templates/poabridge.j2 → deployment/roles/oracle/templates/poabridge.j2
0
deployment/roles/servinstall/templates/poabridge.j2 → deployment/roles/oracle/templates/poabridge.j2
@ -1 +0,0 @@
|
|||||||
This role gets the start blocks for both home and foreign networks.
|
|
@ -1 +0,0 @@
|
|||||||
bridge_path: "/home/{{ compose_service_user }}/bridge"
|
|
@ -1 +0,0 @@
|
|||||||
This role sets the .env config (excluding starting blocks).
|
|
@ -1 +0,0 @@
|
|||||||
This role clones the repo from a specified URL.
|
|
@ -1,5 +0,0 @@
|
|||||||
This role creates a poabridge service which is designed to manage docker-compose bridge deployment.
|
|
||||||
|
|
||||||
/etc/init.d/poabridge start, status, stop, restart - does what the services usually do in such cases.
|
|
||||||
|
|
||||||
/etc/init.d/poabridge rebuild - builds a new bridge deployment from scratch.
|
|
@ -1,4 +0,0 @@
|
|||||||
---
|
|
||||||
# defaults
|
|
||||||
bridge_path: "/home/{{ compose_service_user }}/bridge"
|
|
||||||
keyfile_path: "/root/.key"
|
|
@ -1,14 +0,0 @@
|
|||||||
---
|
|
||||||
- name: "Set poabridge service"
|
|
||||||
template:
|
|
||||||
src: poabridge.j2
|
|
||||||
dest: "/etc/init.d/poabridge"
|
|
||||||
owner: root
|
|
||||||
mode: 755
|
|
||||||
|
|
||||||
- name: "Start/Enable poabridge service"
|
|
||||||
service:
|
|
||||||
name: "poabridge"
|
|
||||||
state: started
|
|
||||||
enabled: yes
|
|
||||||
use: service
|
|
@ -1,19 +1,5 @@
|
|||||||
- name: Install python if necessary
|
- name: Install Oracle
|
||||||
hosts: all
|
hosts: oracle
|
||||||
gather_facts: false
|
|
||||||
become: true
|
become: true
|
||||||
tasks:
|
|
||||||
- name: Install python
|
|
||||||
raw: "test -e {{ ansible_python_interpreter | default ('/usr/bin/python') }} || (sudo apt -y update && sudo apt install -y python-minimal)"
|
|
||||||
tags: install_dependencies
|
|
||||||
|
|
||||||
- name: Install bridge
|
|
||||||
hosts: all
|
|
||||||
roles:
|
roles:
|
||||||
- { role: dependencies, tags: install_dependencies, become: true }
|
- { role: oracle }
|
||||||
- { role: repo, tags: clone_repo, become: true }
|
|
||||||
- { role: pre_config, tags: pre_config, become: true }
|
|
||||||
- { role: jumpbox, tags: launch_jumpbox, become: true }
|
|
||||||
- { role: post_config, tags: post_config, become: true }
|
|
||||||
- { role: logging, tags: set_logging, become: true}
|
|
||||||
- { role: servinstall, tags: install_service, become: true }
|
|
||||||
|
Loading…
Reference in New Issue
Block a user