Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deploy local-setup on virtual machine using Packer & Vagrant #12

Merged
merged 29 commits into from
Jul 24, 2020
Merged
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
668386a
Build VM box using Packer
lukasz-zimnoch Jul 10, 2020
4766ac3
Remaining Packer provisioning scripts
lukasz-zimnoch Jul 13, 2020
fed4466
Add wrapper script for provisioning
lukasz-zimnoch Jul 13, 2020
1d56c9a
Revert "Add wrapper script for provisioning"
lukasz-zimnoch Jul 13, 2020
308435e
Invoke bash with -l option
lukasz-zimnoch Jul 13, 2020
b80ecfe
Don't install python and testnet relay
lukasz-zimnoch Jul 14, 2020
47bc3ee
Merge branch 'e2e-assertions' into local-setup-vm
lukasz-zimnoch Jul 16, 2020
3aec7b0
Vagrant provisioning scripts
lukasz-zimnoch Jul 16, 2020
8d0aa63
Make sed invocations cross-platform
lukasz-zimnoch Jul 16, 2020
d171258
Make install.sh pass
lukasz-zimnoch Jul 16, 2020
5c361a1
Clients provisioning script
lukasz-zimnoch Jul 16, 2020
cf2035d
Add Docker builder
lukasz-zimnoch Jul 17, 2020
4b0ea3b
Update gitignore
lukasz-zimnoch Jul 17, 2020
9a9110b
Improve Docker builder
lukasz-zimnoch Jul 17, 2020
85cc840
Fetch workdirs for transient services
lukasz-zimnoch Jul 17, 2020
8dbe15b
Align artifacts naming
lukasz-zimnoch Jul 17, 2020
293454c
Rename `packer` and `vagrant` directories
lukasz-zimnoch Jul 17, 2020
1ed577c
Fix docker-tag post processor
lukasz-zimnoch Jul 17, 2020
bc20d9a
Make all scripts executable
lukasz-zimnoch Jul 20, 2020
ab36583
Auto update of submodules
lukasz-zimnoch Jul 20, 2020
4f2b720
Docs update
lukasz-zimnoch Jul 20, 2020
a3fe830
Fix readme typo
lukasz-zimnoch Jul 20, 2020
bfb72b8
Add note about core/ecdsa clients versions
lukasz-zimnoch Jul 23, 2020
033cc31
Add readme introduction
lukasz-zimnoch Jul 23, 2020
ed1c00c
Add checks to install-commons.sh
lukasz-zimnoch Jul 23, 2020
117c390
Add note about vagrant-disksize plugin
lukasz-zimnoch Jul 23, 2020
5e0b1e4
Add note about tbtc-dapp local config
lukasz-zimnoch Jul 23, 2020
c48e441
Change note about tbtc-dapp local config
lukasz-zimnoch Jul 23, 2020
3b1434d
Add missing sudo to clone-repository.sh
lukasz-zimnoch Jul 24, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
.idea
/ethereum/data/geth/
/storage/
node_modules
node_modules
vagrant-box
.vagrant
*.log
148 changes: 8 additions & 140 deletions README.adoc
Original file line number Diff line number Diff line change
@@ -1,148 +1,16 @@
= KEEP & tBTC local setup

== Setting up development environment
If you’re on macOS, install Homebrew and https://github.com/keep-network/keep-core/blob/master/scripts/macos-setup.sh[macos-setup.sh] script to setup all necessary tools.
== Installation

If you are not on macOS or you don't have Homebrew, you need to install:
This repository can be used in two different ways described below:
pdyraga marked this conversation as resolved.
Show resolved Hide resolved

- Go compiler, at least 1.14
- Geth (Ethereum client) 1.9.9-stable
- Solidity, at least 0.5.17
- Truffle, at least 5.1.18
- Protobuf compiler, at least 3.11.4
- `protoc-gen-gogoslick` toolchain
- `jq`
=== Automatic installation on separate virtual machine

Regardless you use `macos-setup.sh` or not, you should also install:
To install everything automatically on a separate VirtualBox machine using Packer and
Vagrant, please follow the <<./docs/auto-setup.adoc#title, automatic setup guide>>.

- https://github.com/pyenv/pyenv[pyenv], at least 1.2.18
- https://github.com/pypa/pipenv[pipenv], at least 2018.11.26
- https://docs.docker.com/get-docker[Docker] & https://docs.docker.com/compose/install/[Docker Compose]
=== Manual installation on your local machine

== Node.js version notice
To install everything on your local machine by hand,
please follow the <<./docs/manual-setup.adoc#title, manual setup guide>>.

Please use Node `v11.15.0` for everything but E2E test script.
To run the test script, please use Node `v14.3.0`.

We recommend using https://github.com/nvm-sh/nvm[nvm] to manage node versions easily.
You can install both versions by doing:
```
nvm install 11.15.0
nvm install 14.3.0
```
And use the specific version:
```
nvm use 11.15.0
nvm use 14.3.0
```

== Installing the system
. Initialize local `geth` using:
+
```
./initialize-geth.sh
```
+
You can skip this step if your local geth is already initialized. This script clears all Ethereum client data, initilizes genesis block, and funds five accounts. All client data are kept in the working directory of this project so all the data used for other projects stay untouched.

. Run local `geth` node using:
+
```
./run-geth.sh
```
. Run local Bitcoin Core node and ElectrumX using:
+
```
./run-bitcoin.sh
```
. Run Keep & tBTC installation script:
+
```
./install.sh
```
+
This script will fetch `keep-core`, `keep-ecdsa`, and `tbtc` source code, deploy contracts of `keep-core`, `keep-ecdsa`, and `tbtc`. It will also build `keep-core` and `keep-ecdsa` off-chain clients.
+
Later on, if you decide to update `tbtc`, you can run just `install-tbtc.sh`.
+
Keep in mind, `tbtc` depends on `keep-ecdsa` and `keep-ecdsa` depends on `keep-core` so if you decide to update `keep-ecdsa`, you can run `install-keep-ecdsa.sh` followed by `install-tbtc.sh`.
+
If you decide to update `keep-core`, you have to run `install-keep-core.sh` followed by `install-keep-ecdsa.sh` followed by `install-tbtc.sh` or just the entire `install.sh` again.

== Run clients
The above installation script will configure:

- 1 `keep-core` client
- 3 `keep-ecdsa` clients

To run the `keep-core` client use:
```
./run-core-1.sh
```

It is enough to run one `keep-core` client to generate a group and produce relay entries. Setting up more than one client locally is possible but consumes more resources.

To run `keep-ecdsa` clients use:
```
./run-ecdsa-1.sh
```
```
./run-ecdsa-2.sh
```
```
./run-ecdsa-3.sh
```

There are at least 3 `keep-ecdsa` clients needed to open a keep. Setting up more than three clients locally is possible but consumes more resources.

== Beacon genesis

Before the beacon is able to produce a first relay entry, genesis needs to happen. Genesis triggers the first random beacon group selection.

Genesis should be triggered after `keep-core` client started with:
```
cd keep-core
KEEP_ETHEREUM_PASSWORD="password" ./keep-core --config configs/config.local.1.toml relay genesis
```

Bonded ECDSA keep factory from `keep-ecdsa` contracts requests for new relay entry to reseed after each signer selection but it is also possible to request for a new relay entry manually with:
```
cd keep-core
KEEP_ETHEREUM_PASSWORD="password" ./keep-core --config configs/config.local.1.toml relay request
```

= How to interact with the system

You can interact with the system through the tBTC dApp or automated
end-to-end tests. Before you start interacting, make sure you:

- Installed all system components using `install.sh` script
- Have a local Geth instance (`run-geth.sh`) working
- Have local Bitcoin Core and ElectrumX instances (`run-bitcoin.sh`) working
- Have 1 `keep-core` and 3 `keep-ecdsa` clients up and running

== Keep Dashboard dApp

To run the Keep Dashboard dApp invoke:
```
./run-keep-dashboard.sh
```

== tBTC dApp

To run the tBTC dApp against the local Bitcoin network,
make sure the tBTC dApp is configured to work with the local ElectrumX instance.
You can configure this in `./tbtc-dapp/src/wrappers/web3.js` file,
where `TBTC.withConfig` line occurs.
Then, you can invoke:
```
./run-tbtc-dapp.sh
```
The application will be available on `http://localhost:3000`.

== E2E tests

To run the automated end-to-end scenario invoke:
```
./run-e2e-test.sh
```
67 changes: 67 additions & 0 deletions deployments/local-setup-environment/packerfile.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
{
"builders": [
{
"type": "vagrant",
"source_path": "ubuntu/xenial64",
"provider": "virtualbox",
"communicator": "ssh",
"output_dir": "vagrant-box"
},
{
"type": "docker",
"image": "ubuntu:xenial",
"commit": true,
"run_command": [
"-d", "-i", "-t",
"-w=/root",
"--entrypoint=/bin/bash",
"--",
"{{.Image}}"
],
"changes": [
"WORKDIR /root",
"ENTRYPOINT /bin/bash -l"
]
}
],
"provisioners": [
{
"type": "shell",
"execute_command": "chmod +x {{ .Path }}; {{ .Vars }} bash -l {{ .Path }}",
"inline": ["apt-get update && apt-get -y install sudo"],
"only": ["docker"]
},
{
"type": "shell",
"execute_command": "chmod +x {{ .Path }}; {{ .Vars }} bash -l {{ .Path }}",
"scripts": [
"./provisioning/install-commons.sh",
"./provisioning/install-nodejs.sh",
"./provisioning/install-go.sh",
"./provisioning/install-geth.sh",
"./provisioning/install-solidity.sh",
"./provisioning/install-protobuf.sh",
"./provisioning/install-docker.sh",
"./provisioning/install-docker-compose.sh"
]
},
{
"type": "shell",
"execute_command": "chmod +x {{ .Path }}; {{ .Vars }} bash -l {{ .Path }}",
"inline": ["npm -g config set user root"],
"only": ["docker"]
},
{
"type": "shell",
"execute_command": "chmod +x {{ .Path }}; {{ .Vars }} bash -l {{ .Path }}",
"script": "./provisioning/install-truffle.sh"
}
],
"post-processors": [
{
"type": "docker-tag",
"repository": "local-setup-environment",
"only": ["docker"]
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/bin/bash

set -e

echo "Installing common tools..."

sudo apt-get update

sudo apt-get install -y \
curl \
wget \
git \
unzip \
jq \
python \
build-essential

if ! [ -x "$(command -v unzip)" ]; then echo "unzip installation failed"; exit 1; fi
if ! [ -x "$(command -v jq)" ]; then echo "jq installation failed"; exit 1; fi
pdyraga marked this conversation as resolved.
Show resolved Hide resolved

echo "Common tools have been installed successfully!"
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/bash

set -e

echo "Installing Docker Compose..."

sudo curl -L "https://github.com/docker/compose/releases/download/1.26.2/docker-compose-$(uname -s)-$(uname -m)" \
-o /usr/local/bin/docker-compose

sudo chmod +x /usr/local/bin/docker-compose

if ! [ -x "$(command -v docker-compose)" ]; then echo "Docker compose installation failed"; exit 1; fi

echo "Docker Compose has been installed successfully!"
26 changes: 26 additions & 0 deletions deployments/local-setup-environment/provisioning/install-docker.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/bin/bash

set -e

echo "Installing Docker..."

sudo apt-get install -y \
apt-transport-https \
ca-certificates \
curl \
gnupg-agent \
software-properties-common

curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -

sudo add-apt-repository \
"deb [arch=amd64] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) \
stable"

sudo apt-get update
sudo apt-get install -y docker-ce docker-ce-cli containerd.io

if ! [ -x "$(command -v docker)" ]; then echo "Docker installation failed"; exit 1; fi

echo "Docker has been installed successfully!"
18 changes: 18 additions & 0 deletions deployments/local-setup-environment/provisioning/install-geth.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/bash

set -e

echo "Installing go-ethereum..."

GETH_PACKAGE=geth-alltools-linux-amd64-1.9.9-01744997.tar.gz

curl -O https://gethstore.blob.core.windows.net/builds/$GETH_PACKAGE
pdyraga marked this conversation as resolved.
Show resolved Hide resolved

tar -xvf $GETH_PACKAGE
mkdir ./go-ethereum && tar -xzf $GETH_PACKAGE -C ./go-ethereum --strip-components=1
sudo chown -R root:root ./go-ethereum
sudo mv ./go-ethereum/* /usr/local/bin

if ! [ -x "$(command -v geth)" ]; then echo "go-ethereum installation failed"; exit 1; fi

echo "go-ethereum has been installed successfully!"
21 changes: 21 additions & 0 deletions deployments/local-setup-environment/provisioning/install-go.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/bin/bash

set -e

echo "Installing Go..."

GOLANG_PACKAGE=go1.13.4.linux-amd64.tar.gz

curl -O https://storage.googleapis.com/golang/$GOLANG_PACKAGE

tar -xvf $GOLANG_PACKAGE
sudo chown -R root:root ./go
sudo mv go /usr/local

echo 'GOPATH="$HOME/go"' >> ~/.profile
echo 'PATH="$PATH:/usr/local/go/bin:$GOPATH/bin"' >> ~/.profile
source ~/.profile

if ! [ -x "$(command -v go)" ]; then echo "Go installation failed"; exit 1; fi

echo "Go has been installed successfully!"
21 changes: 21 additions & 0 deletions deployments/local-setup-environment/provisioning/install-nodejs.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/bin/bash

set -e

echo "Installing Node.js and NPM..."

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.3/install.sh | bash

echo 'export NVM_DIR="$HOME/.nvm"' >> ~/.profile
echo '[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"' >> ~/.profile
source ~/.profile

nvm install 14.3.0
nvm install 11.15.0
pdyraga marked this conversation as resolved.
Show resolved Hide resolved
nvm alias default 11.15.0
nvm use default

if ! [ -x "$(command -v node)" ]; then echo "Node installation failed"; exit 1; fi
if ! [ -x "$(command -v npm)" ]; then echo "NPM installation failed"; exit 1; fi

echo "Node.js and NPM have been installed successfully!"
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/bin/bash

set -e

echo "Installing Protobuf..."

PROTOC_VERSION=3.11.4
PROTOC_PACKAGE=protoc-$PROTOC_VERSION-linux-x86_64.zip

wget https://github.com/protocolbuffers/protobuf/releases/download/v$PROTOC_VERSION/$PROTOC_PACKAGE

mkdir ./protoc && unzip $PROTOC_PACKAGE -d ./protoc
chmod 755 -R ./protoc
sudo mv protoc/bin/protoc /usr/local/bin
sudo mv protoc/include/* /usr/local/include

go get -u github.com/gogo/protobuf/protoc-gen-gogoslick

if ! [ -x "$(command -v protoc)" ]; then echo "protoc installation failed"; exit 1; fi
if ! [ -x "$(command -v protoc-gen-gogoslick)" ]; then echo "protoc-gen-gogoslick installation failed"; exit 1; fi

echo "Protobuf has been installed successfully!"
Loading