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

feat(devnet): Local Gossamer Devnet #2008

Merged
merged 42 commits into from
Nov 25, 2021
Merged
Show file tree
Hide file tree
Changes from 39 commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
89b4337
wip
timwu20 Nov 9, 2021
31b3494
revise function, add test
timwu20 Nov 9, 2021
b502b27
cleanup
timwu20 Nov 9, 2021
a515bae
more wip
timwu20 Nov 10, 2021
3afd167
add pubip flag to cli
timwu20 Nov 10, 2021
0469b5c
go mod tidy after upgrading to 1.17
timwu20 Nov 10, 2021
53f0d51
add config tests
timwu20 Nov 11, 2021
a94830d
devnet cmd test
timwu20 Nov 11, 2021
d71bc2b
fix bob
timwu20 Nov 11, 2021
d2fc4f8
fix confd command
timwu20 Nov 11, 2021
1526265
update dockerfiles
timwu20 Nov 11, 2021
276d7c4
use dev go.mod and go.sum
timwu20 Nov 11, 2021
edea601
fix logs
timwu20 Nov 11, 2021
4bb5719
update lint settings
timwu20 Nov 11, 2021
078eab3
fix linting
timwu20 Nov 11, 2021
37bc203
add readme
timwu20 Nov 11, 2021
f2b0c2a
update README
timwu20 Nov 12, 2021
d77c1fc
remove symlinking step
timwu20 Nov 16, 2021
fee9325
Update devnet/README.md
timwu20 Nov 16, 2021
4d3cfc6
Update devnet/README.md
timwu20 Nov 16, 2021
bc651d6
Update devnet/README.md
timwu20 Nov 16, 2021
2cfbb59
Update devnet/alice.Dockerfile
timwu20 Nov 16, 2021
ae168e1
Update devnet/alice.Dockerfile
timwu20 Nov 16, 2021
2048bea
Update devnet/alice.Dockerfile
timwu20 Nov 16, 2021
1e31f5d
Update devnet/alice.Dockerfile
timwu20 Nov 16, 2021
f059130
Update devnet/alice.Dockerfile
timwu20 Nov 16, 2021
d78d5ab
cr feedback, fix metrics on bob
timwu20 Nov 16, 2021
e3f4c08
fix go.mod
timwu20 Nov 16, 2021
c7fdbf7
go mod tidy
timwu20 Nov 16, 2021
50de22e
Update devnet/cmd/update-dd-agent-confd/main.go
timwu20 Nov 17, 2021
b44587c
Update devnet/cmd/update-dd-agent-confd/main.go
timwu20 Nov 17, 2021
7c9e88d
cr feedback
timwu20 Nov 17, 2021
a79cee7
Merge branch 'devnet' of github.com:ChainSafe/gossamer into devnet
timwu20 Nov 17, 2021
b20dbef
update readme
timwu20 Nov 17, 2021
baf937b
Update devnet/README.md
timwu20 Nov 18, 2021
9e8fe21
cr feedback
timwu20 Nov 18, 2021
0c0d2de
more cr feedback
timwu20 Nov 18, 2021
d9d07be
use embed
timwu20 Nov 18, 2021
3aed2bd
Merge branch 'devnet' of github.com:ChainSafe/gossamer into devnet
timwu20 Nov 18, 2021
a226b83
add license
timwu20 Nov 18, 2021
9a9bb10
trimpath
timwu20 Nov 19, 2021
0cbd42f
Update devnet/bob.Dockerfile
timwu20 Nov 23, 2021
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
1 change: 1 addition & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ linters-settings:
locale: UK
ignore-words:
- gossamer
- flavor
qdm12 marked this conversation as resolved.
Show resolved Hide resolved
gocritic:
# Which checks should be disabled; can't be combined with 'enabled-checks'; default is empty
disabled-checks:
Expand Down
5 changes: 5 additions & 0 deletions cmd/gossamer/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -671,6 +671,11 @@ func setDotNetworkConfig(ctx *cli.Context, tomlCfg ctoml.NetworkConfig, cfg *dot
cfg.NoMDNS = true
}

// check --pubip flag and update node configuration
if pubip := ctx.GlobalString(PublicIPFlag.Name); pubip != "" {
cfg.PublicIP = pubip
timwu20 marked this conversation as resolved.
Show resolved Hide resolved
}

if len(cfg.PersistentPeers) == 0 {
cfg.PersistentPeers = []string(nil)
}
Expand Down
15 changes: 15 additions & 0 deletions cmd/gossamer/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -515,6 +515,21 @@ func TestNetworkConfigFromFlags(t *testing.T) {
MinPeers: testCfg.Network.MinPeers,
},
},
{
"Test gossamer --pubip",
[]string{"config", "pubip"},
[]interface{}{testCfgFile.Name(), "10.0.5.2"},
dot.NetworkConfig{
Port: testCfg.Network.Port,
Bootnodes: testCfg.Network.Bootnodes,
ProtocolID: testCfg.Network.ProtocolID,
NoBootstrap: testCfg.Network.NoBootstrap,
NoMDNS: false,
DiscoveryInterval: time.Second * 10,
MinPeers: testCfg.Network.MinPeers,
PublicIP: "10.0.5.2",
},
},
}

for _, c := range testcases {
Expand Down
6 changes: 6 additions & 0 deletions cmd/gossamer/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,11 @@ var (
Name: "nomdns",
Usage: "Disables network mDNS discovery",
}
// PublicIPFlag uses the supplied IP for broadcasting
PublicIPFlag = cli.StringFlag{
Name: "pubip",
Usage: "Overrides public IP address used for peer to peer networking",
}
)

// RPC service configuration flags
Expand Down Expand Up @@ -392,6 +397,7 @@ var (
RolesFlag,
NoBootstrapFlag,
NoMDNSFlag,
PublicIPFlag,

// rpc flags
RPCEnabledFlag,
Expand Down
54 changes: 54 additions & 0 deletions devnet/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# Gossamer Devnet
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we have this file in the docs directory somewhere instead? 🤔


Docker container and Docker Compose for a Gossamer Devnet currently with three authority nodes running the `gssmr` chain with keys `alice`, `bob` and `charlie`.

## Requirements

- [Docker Compose](https://docs.docker.com/compose/install/)

## Running the Devnet

From the Gossamer root run the following commands to run the devnet

```sh
# will rebuild the containers based on the current code
docker-compose up --abort-on-container-exit --build

# will run the devnet without rebuilding
docker-compose up --abort-on-container-exit

# destroys the devnet
docker-compose down
```

> **_NOTE:_** The devnet is not stateful, so subsequent runs will start from the genesis block.

## Prometheus Datadog Integration

All Prometheus metrics from the nodes are piped to Datadog. You can setup your own dashboard and add additional tags by modifying the Dockerfiles. Currently the metrics are prefixed with `gossamer.local.devnet` and are tagged (Prometheus label) with a `key` tag for `alice`, `bob`, and `charlie`.

For metrics to be piped to Datadog, you will require a Datadog API key. Please contact Elizabeth or myself (Tim) for access to datadog if you don't already have it.

The Datadog API key must be an environment variable on your own machine, which Docker Compose will pick up and inject when building the node images.

```
export $DD_API_KEY=YourKey
```

## Files

### Dockerfiles

There are two Docker files used in the devnet. `alice.Dockerfile` is the lead node and is intiated with the `babe-lead` flag to build the first block. `bob.Dockerfile` is used for both `bob` and `charlie`.

### cmd/update-dd-agent-confd

A command line app to create a `confd.yml` file used by the Datadog agent when piping metrics to Datadog. It's used in the both `alice.Dockerfile` and `bob.Dockerfile` to create specific `confd.yml` files.

### alice.node.key

This key is injected in `alice.Dockerfile` so it uses the same public key for the `bootnodes` param in `bob.Dockerfile`.

### docker-compose.yml

The Docker Compose file. Specifies the IP addresses of all the nodes.
26 changes: 26 additions & 0 deletions devnet/alice.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
FROM golang:1.17

ARG DD_API_KEY=somekey
timwu20 marked this conversation as resolved.
Show resolved Hide resolved
RUN DD_API_KEY=${DD_API_KEY} DD_AGENT_MAJOR_VERSION=7 DD_INSTALL_ONLY=true DD_SITE="datadoghq.com" bash -c "$(curl -L https://s3.amazonaws.com/dd-agent/scripts/install_script.sh)"

WORKDIR /gossamer

COPY go.mod go.sum ./
RUN go mod download

COPY . .

RUN go install github.com/ChainSafe/gossamer/cmd/gossamer
timwu20 marked this conversation as resolved.
Show resolved Hide resolved

# use modified genesis-spec.json with only 3 authority nodes
RUN cp -f devnet/chain/gssmr/genesis-spec.json chain/gssmr/genesis-spec.json

RUN gossamer --key=alice init

# use a hardcoded key for alice, so we can determine what the peerID is for subsequent nodes
RUN cp devnet/alice.node.key ~/.gossamer/gssmr/node.key

RUN go run devnet/cmd/update-dd-agent-confd/main.go -n=gossamer.local.devnet -t=key:alice > /etc/datadog-agent/conf.d/openmetrics.d/conf.yaml

ENTRYPOINT service datadog-agent start && gossamer --key=alice --babe-lead --publish-metrics --rpc --rpc-external=true --pubip=10.5.0.2
EXPOSE 7001/tcp 8545/tcp 8546/tcp 8540/tcp 9876/tcp
32 changes: 32 additions & 0 deletions devnet/bob.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
FROM golang:1.17

ARG DD_API_KEY=somekey
RUN DD_API_KEY=${DD_API_KEY} DD_AGENT_MAJOR_VERSION=7 DD_INSTALL_ONLY=true DD_SITE="datadoghq.com" bash -c "$(curl -L https://s3.amazonaws.com/dd-agent/scripts/install_script.sh)"

WORKDIR /gossamer

COPY go.mod go.sum ./
RUN go mod download

COPY . .

RUN go install github.com/ChainSafe/gossamer/cmd/gossamer

# use modified genesis-spec.json with only 3 authority nodes
RUN cp -f devnet/chain/gssmr/genesis-spec.json chain/gssmr/genesis-spec.json
kishansagathiya marked this conversation as resolved.
Show resolved Hide resolved

ARG key
RUN test -n "$key"
ARG pubip
Comment on lines +21 to +23
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit usually build arguments and env variables are in uppercase out there, although lowercase works too.

RUN test -n "$pubip"

ENV key=${key}
ENV pubip=${pubip}

RUN gossamer --key=${key} init

RUN go run devnet/cmd/update-dd-agent-confd/main.go -n=gossamer.local.devnet -t=key:${key} > /etc/datadog-agent/conf.d/openmetrics.d/conf.yaml
kishansagathiya marked this conversation as resolved.
Show resolved Hide resolved

ENTRYPOINT service datadog-agent start && gossamer --key=${key} --bootnodes=/ip4/10.5.0.2/tcp/7001/p2p/12D3KooWMER5iow67nScpWeVqEiRRx59PJ3xMMAYPTACYPRQbbWU --publish-metrics --rpc --pubip=${pubip}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be nice to be able to fiddle with the bootnodes at runtime with i.e.:

Suggested change
ENTRYPOINT service datadog-agent start && gossamer --key=${key} --bootnodes=/ip4/10.5.0.2/tcp/7001/p2p/12D3KooWMER5iow67nScpWeVqEiRRx59PJ3xMMAYPTACYPRQbbWU --publish-metrics --rpc --pubip=${pubip}
ENV BOOTNODES=/ip4/10.5.0.2/tcp/7001/p2p/12D3KooWMER5iow67nScpWeVqEiRRx59PJ3xMMAYPTACYPRQbbWU
ENTRYPOINT service datadog-agent start && gossamer --key=${key} --bootnodes=${BOOTNODES} --publish-metrics --rpc --pubip=${pubip}

You could also split that string in multiple ENV if you want (i.e. BOOTNODE_PORT=7001) using sensible defaults.

Copy link
Contributor Author

@timwu20 timwu20 Nov 23, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see a case where we would want to adjust the bootnodes for the gssmr devnet.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At least the IP address 10.5.0.2 could be changed if we change the docker network right?

Copy link
Contributor Author

@timwu20 timwu20 Nov 24, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the next PR I do actually have to change the bootnode ports, so port will be configurable on bob.Dockerfile. I'm trying to hardcode the configuration for alice.Dockerfile since that is the lead node. I think being explicit in this case shows that everything is dependant on alice. The dockerfiles that I'm creating here aren't meant to be used standalone, but actually only orchestrated using the docker-compose.yml


EXPOSE 7001/tcp 8545/tcp 8546/tcp 8540/tcp 9876/tcp
timwu20 marked this conversation as resolved.
Show resolved Hide resolved
Loading