• This repository has been archived on 08/Jul/2022
  • Stars
    star
    101
  • Rank 338,166 (Top 7 %)
  • Language
    JavaScript
  • License
    Apache License 2.0
  • Created over 5 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Tool for deploying polkadot networks

CircleCI

polkadot-deployer

polkadot-deployer is a general tool for deploying Polkadot nodes, aiming to make it easy to deploy a network of nodes. To learn more about Polkadot explore the wiki or join the conversation at Riot.

polkadot-deployer allows you to create local or remote cloud deployments of polkadot. Currently it supports local deployments using Kind and remote deployments using Google Cloud Platform, Amazon's AWS, Microsoft's Azure and Digital Ocean for the infrastructure deployment and Cloudflare for the DNS settings that make your network accessible through websockets RPC.

Requirements

The tool is meant to work on Linux and MacOS machines. In order to be able to use the tool you will require to have installed recent versions of node (developed and tested with v10.7.0 and v10.15.1) and docker for local deployments (developed and tested with 18.09.5). Once installed, you should also be able to run docker as a regular user. See the Troubleshooting section in case you have problems running the tool.

Installation and execution

There are two methods to successfully install and operate polkadot-deployer in order to deploy a number of polkadot nodes.

  • Using yarn packet manager by issuing the following commands: yarn global add polkadot-deployer and polkadot-deployer CMD to run a command.
  • By downloading the latest version from git and then issuing the following commands from within the project directory: git clone [email protected]:w3f/polkadot-deployer.git, execute yarn install to install all requirements and node . CMD to run a command.

Local deployments

After you have succesfully installed polkadot validator using either method, you may follow the next steps to guide you through the proccess of deployng polkadot validator locally on your hardware. This can be done either using the interactive menu or by using a config file.

  • In order to create a validator through the interactive menu issue the following command:
    node . create --verbose
  • In order to deploy polkadot using the preset configuration file: config/create.local.sample.json issue the following command:
    node . create --config config/create.local.sample.json --verbose

The process will start creating an instance of polkadot inside a your local kubernetes cluster that will be created as part of the procedure using kubernetes-sigs/kind. The entire procedure will take some time, so it might be a good idea to get some coffee at this point. Once the procces is done you can also view all your local deployments using the command: node . list

At this point you can attach to the local polkadot web socket by visiting the websockets endpoint available at ws://127.0.0.1:11000 Furthermore you at this point you will be presented with the raw seeds for the created accounts, including the nodeKey, peerId, stash address and seed etc. Once you are done with your local deployment of polkadot, you can delete your deployment using the destroy [name] command: node . destroy testnet5 More information on the polkadot-deployer usage commands can be found in the usage section.

Check the Troubleshooting section if something goes wrong with the installation.

Remote deployments

To perform a remote deployment of polkadot to a public cloud provider we will follow the same general path. The process differs with each public infrastructure provider. Currently we support GCP, AWS, Azure and Digital Ocean. To successfuly deploy polkadot these infrastructure providers you will first need to setup a cloudflare account and a GCP account. Cloudflare is used to provide a domain name for your deployment and the GCP for maintaining the state of your deployment. Then you will need to provide the specific attributes required for your deployment in each of the supported providers. The required steps are as follows:

  • A Linux machine to run this tool (macOS may fail, see the Troubleshooting section in case you have problems running the tool).

  • Cloudflare credentials as two environment variables CLOUDFLARE_EMAIL and CLOUDFLARE_API_KEY (see here) for details about the API key, the email should be the one used for registration. Also, your domain name registrar should be Cloudflare since this tool relies on Cloudflare for generating SSL certification). The process will register your deployment on Cloudflare and create the required subdomains and certificates.

  • GCP service account and credentials in the form of the environment variable GOOGLE_APPLICATION_CREDENTIALS with the path of the json credentials file for your service account (see here). The GCP configuration is required for use by the process to keep the built state.

  • A project on GCP. Keep the projectID and domain handly as you will need to edit the config files so that they contain this information. A bucket will be created under the particular projectID that will be used to store the project's terraform backend.

  • An account on opsgenie that will be used for notifications. Once you have created the account you will need to set the environmental variables OPSGENIE_TOKEN to that of your token (see here for details) and also set the OPSGENIE_API_URL variable (see here for details).

  • Configure specific requirements that depend on your infrastructure provider. More details on this subject are described on the following section for each of the specific providers.

  • Read through the usage section.


NOTE

  • Optionally if you wish to use opsgenie to receive notifications regarding alerts from your deployment, you will need to edit the configuration file of your deployment and set opsgenie.enabled": true and also set an environmental variable OPSGENIE_TOKEN with your token. By default the deployment will use 'https://api.eu.opsgenie.com/v2/alerts' as the API's URL. In case you require a different API endpoint you will need to also set the variable opsgenie.url in the configuration file appropriately (see here for details).


NOTE

Running the following configurations will cause charges by the providers. You should run the corresponding destroy command as soon as you are finished with your testing to avoid unwanted expenses.


The required steps to successfully deploy polkadot validator are as follows:

Download the latest polkadot deployer from git issuing the following command:
git clone [email protected]:w3f/polkadot-deployer.git and run yarn install to install all requirements.

GCP

To make a deployment on GCP you are required to have the aforementioned GCP service account and project properly configured and meet the following requirements:

  • Make sure the service account has sufficient privileges for GKE.

  • Enough quota on GCP to create the required resources (terraform will show the exact errors if this condition is not met).

  • Kubernetes Engine API and billing enabled for your project (see here).

In order to deploy polkadot on GCP you need to edit the preset configuration file: config/create.remote.sample-GCP.json so that it contains your projectID and domain. Then you can issue the following command:

node . create --config config/create.remote.sample-GCP.json --verbose

The process will start creating an instance of polkadot on GCP. By default a new cluster will be created with the name polkadot-deployer at your default location with 2 n1-standard-2 nodes under the specified project ID.

If you wish to delete your remote deployment of polkadot, you can use the destroy [name] command:

node . destroy gcp-testnet

AWS

To make a deployment on AWS you're required to configure your AWS credentials. It's recommended to do so using the corresponding AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY and AWS_DEFAULT_REGION environment variables. You can set the required values for these variables following the provided documentation.

In order to deploy polkadot on GCP you need to edit the preset configuration file: config/create.remote.sample-AWS.json so that it contains your projectID and domain. The domain must be a domain that can be controlled by the given cloudflare account. Then you can issue the following command:

node . create --config config/create.remote.sample-AWS.json --verbose

The process will start creating an instance of polkadot on AWS. The process with create a 2 node cluster using m4.large machines. An IAM role and a VPC will be created that will contain the Amazon EKS for the deployment along with the required security groups and ingress rules. You may review the entire process here.

If you wish to delete your remote deployment of polkadot, you can use the destroy [name] command:

node . destroy aws-testnet

Azure

To deploy polkadot on Azure you're required to set ARM_CLIENT_ID, ARM_CLIENT_SECRET, ARM_SUBSCRIPTION_ID, ARM_TENANT_ID, TF_VAR_client_id and TF_VAR_client_secret environmental variables. You can find your's by following the documentation.

In order to deploy polkadot on GCP you need to edit the preset configuration file: config/create.remote.sample-AZURE.json so that it contains your projectID and domain. The domain must be a domain that can be controlled by the given cloudflare account. Then you can issue the following command:

node . create --config config/create.remote.sample-AZURE.json --verbose

The process will start creating an instance of polkadot on Azure, deployed as a 2 Standard_D2s_v3 node kubernetes cluster on your default location connected through a virtual network. Furthermore the required security groups and inbound rules will be applied to your deployment. You may review the entire process here.

If you wish to delete your remote deployment of polkadot, you can use the destroy [name] command:

node . destroy azure-testnet

Digital Ocean

To make a deployment on Digital Ocean you're required to configure your Digital Ocean's credentials. You can do this by setting the DIGITALOCEAN_ACCESS_TOKEN environment variable. You can get your access token by following the documentation.

In order to deploy polkadot on GCP you need to edit the preset configuration file: config/create.remote.sample-DO.json so that it contains your projectID and domain. The domain must be a domain that can be controlled by the given cloudflare account. Then you can issue the following command:

node . create --config config/create.remote.sample-DO.json --verbose

The process will start creating an instance of polkadot on Digital Ocean, using a 2 node kubernetes cluster of s-4vcpu-8gb machines. You may review the entire process here.

If you wish to delete your remote deployment of polkadot, you can use the destroy [name] command:

node . destroy do-testnet

Multi provider deployment

You may also wish to run a multi AZ multi-provider deployment. In order to do so, you can create a configuration file based on your requirements and create your deployment from there. Keep in mind that you can use any combination of these providers as you see fit. The configuration file: create.remote.sample.json exists only for the purpose of the tutorial and as an example of what you can do. In order to deploy polkadot on GCP you need to edit the preset configuration file: config/create.remote.sample.json so that it contains your projectID and domain. The domain must be a domain that can be controlled by the given cloudflare account. Then you can issue the following command:

node . create --config config/create.remote.sample.json --verbose

The process will start creating an instance of polkadot on AWS, AZURE and GCP.

If you wish to delete your remote deployment of polkadot, you can use the destroy [name] command:

node . destroy testnet9

More information on the polkadot-deployer usage commands can be found in the usage section.

Usage

polkadot-deployer allows you to create, list, update and delete Polkadot networks of nodes, which we'll call deployments from now on. All the interaction with the command line tool is done through the following sub-commands:

create [options]

Creates a deployment. It accepts a --config option with the path of a json file containing the definition of the deployment, like this for local deployments:

{
  "name": "testnet1",
  "type": "local",
  "nodes": 4
}

or this for remote deployments:

{
  "name": "testnet6",
  "type": "gcp",
  "nodes": 1,
  "remote": {
    "monitoring": true,
    "clusters": [
      {
        "location": "europe-west1-b",
        "projectID": "polkadot-benchmarks",
        "domain": "foo.bar"
      }
    ]
  }
}

These are the fields you can use:

  • name: unique string to distinguish your deployment in subsequent commands.

  • type: either local or remote, local or gcp allowed.

  • nodes: number of validators of the network, an integer between 2 and 20.

  • remote.monitoring: enable monitoring stack, see the Monitoring section

  • remote.clusters[i].location: region or zone to use for the deployment.

  • remote.clusters[i].projectID: id of the GCP project.

  • remote.clusters[i].domain: under which domain the tool will create the websockets endpoint.

You can also omit the --config option the tool will launch a wizard utility to get the deployment details.

Each deployment consists of two components, a cluster and a network.

  • The cluster is the common platform on top of which the network runs, and is currently based on kubernetes v1.13.

  • The network is composed of a set of polkadot nodes connected together, each of them created from this polkadot Helm chart. Helm charts are application packages for kubernetes, more about them here.

Once the deployment is created, the tool sets up a port forwarding process, so that one of the network nodes' websockets endpoint is available on your local host. The location of this port is shown at the end of the polkadot-deployer create call:

*********************************************************
 Websockets endpoint available at ws://127.0.0.1:11000
*********************************************************

You can use that url to access the network from PolkadotJS -> Settings

UI Settings

list

Shows details of all the created deployments:

┌──────────────┬─────────────────┬──────────────────────┬──────────┬─────────┬────────────────┐
│ Network name │ Deployment type │ WebSockets endpoint  │ Provider │ Workers │ Polkadot nodes │
├──────────────┼─────────────────┼──────────────────────┼──────────┼─────────┼────────────────┤
│ testnet1     │ local           │ ws://127.0.0.1:11000 │ kind     │ 1       │ 4              │
└──────────────┴─────────────────┴──────────────────────┴──────────┴─────────┴────────────────┘

redeploy [name]

Recreates a network on an existing cluster. It resets all the Polkadot nodes to their initial state, without having to creating the cluster again.

You can either pass the name of the deployment to recreate or let the wizard show a list of existing deployments.

destroy [name]

Destroy a deployment including cluster, network and portforwarding process.

You can either pass the name of the deployment to destroy or let the wizard show a list of existing deployments.

benchmark

Creates deployments and runs benchmarks on them. These are the type of benchmarks curretly supported:

  • finality: measures the mean time to finality on several networks with different number of validators. It accepts a --config option with the path of a json file containing the definition of the benchmark, like this:

    {
      "name": "bm1",
      "type": "local",
      "benchmark": "finality",
      "startNodes": 2,
      "endNodes": 10,
      "blocks": {
        "offset": 10,
        "measure": 10
      },
      "reuseCluster": true
    }
    

    With this definition, the test will spin up deployments of 2 nodes through 10, measuring for each of them the mean time to finality of 10 consecutive blocks. These are the fields specific to this benchmark that you can use:

    • benchmark: which tests to run, currently only finality implemented.

    • startNodes: how many validators will be used in the first run.

    • endNodes: how many validators will be used in the last run, the process will increment the number of nodes in 1 on each run.

    • blocks.offset: number of blocks to wait before starting to the measurements.

    • blocks.measure: number of blocks on which the metrics will be recorded.

    • reuseCluster: if true the cluster will be cleaned but not deleted after the benchmark is finished and can be used in subsequent runs, this can speed up the execution.

    You can pass also the destination directory of the result files in the --output parameter (current directory by default).

    After the benchmarks are done the results are written to a json file, which includes all the metrics and the details of the execution, and to a file compatible with gnuplot, that can generate a png file with a plot of the results:

    $ node . benchmark -c ./config/benchmark.finality.sample.json
    Initializing nodes...
    Done
    Waiting for nodes ready...
    Done
    ***************************************
     Starting benchmarks with 2 nodes
    ***************************************
    New produced block: 1, timestamp: 1558369995883
    Last finalized block: 1, finalized at: 1558370001258
    
    ...
    
    ***************************************
     Finished benchmarks with 6 nodes
    ***************************************
    Done
    Results writen to ./polkadot-deployer.benchmark.finality.20190520-063948.json
    gnuplot writen to ./polkadot-deployer.benchmark.finality.20190520-063948.gnuplot
    
    $ gnuplot /polkadot-deployer.benchmark.finality.20190520-063948.gnuplot
    

    The previous gnuplot command will generate a benchmark.png file with the benchmark plot on the current directory.

Monitoring

You can enable monitoring for remote deployments, by setting remote.monitoring to true in the configuration. When enabled, polkadot-deployer will install a generic monitoring stack composed of prometheus, alertmanager, grafana and loki, and a more polkadot-specific set of tools around substrate-telemetry.

There will be a grafana instance deployed per cluster, and they will be accessible at https://grafana.<deployment_name>-<n>.<domain>, being n the order of the cluster in the config starting with 0, and can be accessed with username admin and password controlled by the envirnment variable GRAFANA_PASSWORD (grafanapassword if not set).

All the nodes in the deployment will be sending operational data to a substrate-telemetry backend deployed on the first cluster (according to the config definition order). Connected to that backend is also a frontend accessible at https://telemetry.<deployment_name>-0.<domain>.

A prometheus exporter is also deployed as part of the substrate-telemetry pod, there is a grafana dashboard called Polkadot Metrics showing information from the exposed metrics.

Troubleshooting

Below are some common problems found by users. If you have an issue and this suggestions don't help don't hesitate to open an issue. You can get more information about what is the actual adding the --verbose option to any polkadot-deployer command.

  • In some cases the installation process can produce errors from the secp256k1 dependency with messages related to the required python version, like:

    gyp ERR! configure error
    gyp ERR! stack Error: Python executable "/usr/local/opt/python/libexec/bin/python" is v3.7.3, which is not supported by gyp.
    

    To solve this problem you can either define some alias from the command line before installing:

    alias python=python2
    alias pip=pip2
    

    or call the install command with an additional option:

    npm i -g --python=python2.7 polkadot-deployer
    

    See this issue for details.

  • For local deployments, if after issuing a create command you find the deployer stuck with a message like:

    wait-on(537) waiting for: http://127.0.0.1:10080/kubernetes-ready
    

    then it is possible that the cluster is not able to be created using your local docker installation. Make sure that:

    • The system has enough free disk space (at least 10Gb).

    • There are no leftovers on your docker installation. You can clean up with:

      docker system prune -a --volumes
      
  • If you installed gcloud cli tool via homewbrew on mac os, you may face this issue:

    Unable to connect to the server: error executing access token command "/usr/bin/gcloud config config-helper --format=json": err=fork/exec /usr/bin/gcloud: no such file or directory output= stderr=
    

    Locate your gcloud installation with the following command:

    which gcloud
    /usr/local/bin/gcloud
    

    Add this path as an optional variable in the config/create.remote.*.json

    "name": "gcp-testnet",
    "type": "gcp",
    "gcloudPath": "/usr/local/bin/gcloud",
    "nodes": 2,
    "keep": true,
     ...
    
  • Certain files from folder config need to be set with 0600 permission due to security reasons.
    You may experience this error from your local deployment:

    node . create --config ./config/create.local.sample.json --verbose
    Expected file permission 600, found 644 for file ./config/create.local.sample.json
    

    Fix it like this:

    chmod 0600 ./config/create.local.sample.json
    node . create --config ./config/create.local.sample.json --verbose
    

In case you are experiencing problems and any of the above solution works for you don't hesitate to open an issue.

CI/CD Workflow

When a PR is proposed to this repo, the npm test task is run, this includes linting and unit tests.

After the PR is merged into master, when a semantic version tag (vX.Y.Z) is pushed the tests are run again and, if all is ok, the package is published to npm registry

More Repositories

1

Grants-Program

Web3 Foundation Grants Program
JavaScript
1,018
star
2

General-Grants-Program

Web3 Foundation General Grants Program
590
star
3

polkadot-wiki

The source of truth for Polkadot.
JavaScript
370
star
4

schnorrkel

Schnorr VRFs and signatures on the Ristretto group
Rust
309
star
5

polkadot-validator-setup

Polkadot Validator Secure Setup
JavaScript
215
star
6

polkadot-spec

The Polkadot Protocol Specification
TeX
178
star
7

messaging

Messaging for Web3
TeX
167
star
8

PSPs

Polkadot Smart Contract Proposals
152
star
9

unbounded

Open source, freely available and on-chain funded font.
152
star
10

Grant-Milestone-Delivery

Repository to submit finished milestones
104
star
11

research

Overview of W3F research initatives
JavaScript
95
star
12

consensus

Consensus for Web3
TeX
88
star
13

staking-rewards-collector

JavaScript
78
star
14

bls

Aggregatable BLS sigantures
Rust
65
star
15

1k-validators-be

Thousand Validators Program backend.
TypeScript
63
star
16

polkadot-wiki-old

The Polkadot wiki.
HTML
55
star
17

apk-proofs

Rust
50
star
18

polkadot-legacy-spec

A more technical description of Polkadot protocol
47
star
19

ring-vrf

TeX
36
star
20

jamtestvectors

The latest test vectors for JAM.
Python
31
star
21

substrate-telemetry-exporter

JavaScript
30
star
22

polkadot

Rust
30
star
23

hd-ed25519

Hierarchical derivations on Ed25519
Rust
25
star
24

polkadot-charts

Helm charts for deploying Polkadot networks.
Smarty
22
star
25

CardsAgainstBlockchain

Cards Against Blockchain
TeX
22
star
26

mooc-exercises

Exercises for Web3 MOOC
Rust
21
star
27

fflonk

Rust
21
star
28

validator-security

A collaborative document for good practice with validator security
20
star
29

1KC

Thousand Contributors Programme
20
star
30

polkadot-payouts

TypeScript
19
star
31

polkadot-watcher-validator

TypeScript
18
star
32

offences-monitor

Monitors slashable offences registered on a Substrate based chain.
JavaScript
18
star
33

w3f-education

Technical Education at Web3 Foundation
JavaScript
17
star
34

polkadot-registrar-challenger

Polkadot Registrar Service (beta)
Rust
15
star
35

ring-proof

ring-vrf ring proof v2.5
Rust
14
star
36

educhain

Parachain developed and maintained by Tech Ed team
Rust
14
star
37

polkadot-registrar-watcher

TypeScript
13
star
38

polkadot-light-paper

Light Polkadot info
12
star
39

ipfs-cluster-chart

Helm Chart for: https://cluster.ipfs.io/documentation/guides/k8s/
Shell
11
star
40

polkadot-tests

Polkadot Protocol Conformance Tests
Rust
11
star
41

polkadot-lab

Testing framework for Polkadot networks
TypeScript
11
star
42

polkadot-watcher-csv-exporter

polkadot-watcher-csv-exporter
TypeScript
11
star
43

chainspec-generator

CLI for generating the Polkadot and Kusama chain specification from Ethereum state.
TypeScript
11
star
44

faucet-bot

A DOTs-giving bot frontend to the faucet.
JavaScript
10
star
45

parachain-implementers-guide

9
star
46

ark-scale

Arkworks serialization wrapped in Parity SCALE codec
Rust
8
star
47

helm-charts

8
star
48

substrate-legacy

Rust
8
star
49

xcmp_prototype_playground

Prototyping several xcmp approaches
Rust
8
star
50

matrixbot

ChatBot for infrastructure interactions
Python
8
star
51

substrate-telemetry-chart

Smarty
7
star
52

polkadot-api-client-ts

TypeScript
7
star
53

polkadot-watcher-transaction

TypeScript
7
star
54

polkadot-dashboard

6
star
55

matrix-server-charts

Shell
6
star
56

injection-tool

Tools, scripts and utilities for making injections.
TypeScript
6
star
57

substrate-benchmarks-role

Ansible role for substrate runtime module benchmarking
Python
6
star
58

algorithmacs

Algorithmic style for Texmacs
TypeScript
6
star
59

ethereum-tracker

JavaScript
6
star
60

polkadot-docs

Polkadot Developer Documentation
6
star
61

validator-selection-tool

TypeScript
6
star
62

polkadot-claims

Claim a DOT allocation to a Polkadot public key.
Solidity
6
star
63

KTFPs

Kusama Treasury Funding Proposals
6
star
64

terraform-digitalocean-polkadot-deployer

Go
5
star
65

polkadot-react-icons

TypeScript
5
star
66

PPPs

Polkadot Protocol Proposals
TypeScript
5
star
67

terraform-ts

TypeScript
4
star
68

test-utils-ts

TypeScript
4
star
69

matrix-recorder-chart

HTML
4
star
70

helm-ts

TypeScript
4
star
71

substrate-alertrules-chart

Shell
4
star
72

polkadot-account-monitoring

Rust
4
star
73

kusama-guide-staging

staging server for kusama guide
HTML
4
star
74

components-ts

TypeScript
4
star
75

kusama-guide-hosting

Repository to deploy the Kusama Guide for hosting on GitHub Pages.
HTML
4
star
76

ethberlin4

Solidity
4
star
77

terraform-google-polkadot-lab

Creates the infrastructure for running polkadot network tests
HCL
3
star
78

polkadot-wiki-staging

polkadot wiki dev server build branch (github pages deployment)
JavaScript
3
star
79

edgeware-deployment

Dockerfile
3
star
80

cloudflare-ts

TypeScript
3
star
81

web3

3
star
82

terratest-polkadot-deployer

Go
3
star
83

polkadot-checker

JavaScript
3
star
84

terraform-google-polkadot-deployer

Go
3
star
85

teleport-role

HTML
3
star
86

terraform-azure-polkadot-deployer

HCL
3
star
87

node-docker

Dockerfile
3
star
88

NPoS-Economics

Jupyter Notebook
3
star
89

node-exporter-dashboard

3
star
90

polkadot-validator-ansible

Python
3
star
91

harvester-chart

Smarty
3
star
92

uptime-probe

Rust
3
star
93

1k-validators-candidate-verification

Rust
3
star
94

ghost-staging

Shell
3
star
95

disc2020-scalability-and-interoperability-workshop

HTML
3
star
96

algebraic-torus

A library to facilitate comptutation with algebraic torus
Sage
3
star
97

hs-p4p

p2p networking library in Haskell
Haskell
3
star
98

terraform-aws-polkadot-deployer

HCL
3
star
99

1k-watcher-claimed-payouts

A tool for generating reports about reward claims of all the 1k Validator Programme candidates.
Rust
3
star
100

crypto-ts

TypeScript
3
star