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): add substrate docker images to dockerfile #2263

Merged
merged 38 commits into from
Mar 8, 2022
Merged
Show file tree
Hide file tree
Changes from 30 commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
6139712
feat: include substrate docker image
EclesioMeloJunior Jan 31, 2022
8c3fb1d
chore: add substrate docker images
EclesioMeloJunior Feb 2, 2022
c0be6dc
chore: formatting and add depends on yaml key
EclesioMeloJunior Feb 2, 2022
eda4e4a
chore: add datadog stuff again
EclesioMeloJunior Feb 2, 2022
dae59e2
chore: use alice peer id
EclesioMeloJunior Feb 2, 2022
6ccf8fb
chore: split substrate docker compose services into another file
EclesioMeloJunior Feb 2, 2022
1407b3a
chore: enable prometheus external and add datadog
EclesioMeloJunior Feb 2, 2022
0d59fac
Merge branch 'development' into eclesio/substrate-docker-image
EclesioMeloJunior Feb 4, 2022
5108412
chore: keep substrate ports same as gossamer node ports
EclesioMeloJunior Feb 4, 2022
9fa7ffb
chore: expose rpc and ws calls in substrate docker file
EclesioMeloJunior Feb 4, 2022
71a8f5e
chore: use same dns name and p2p id
EclesioMeloJunior Feb 4, 2022
f1fea2d
chore: use same key for both alice gossamer and substrate nodes
EclesioMeloJunior Feb 4, 2022
9b485f6
chore: fix dd golang cmd
EclesioMeloJunior Feb 4, 2022
cff9c8c
Update devnet/README.md
EclesioMeloJunior Feb 7, 2022
262b329
Update devnet/README.md
EclesioMeloJunior Feb 7, 2022
012b4b9
chore: update `substrate_alice` readme info
EclesioMeloJunior Feb 7, 2022
1d158a3
Update devnet/README.md
EclesioMeloJunior Feb 7, 2022
f0689ee
chore: add `/tcp` to expose ports
EclesioMeloJunior Feb 7, 2022
604ce4b
Merge branch 'eclesio/substrate-docker-image' of github.com:ChainSafe…
EclesioMeloJunior Feb 7, 2022
237647a
chore: adjust args and envs
EclesioMeloJunior Feb 7, 2022
ae0429e
chore: pin prometheus version, add read only volume and add trailing …
EclesioMeloJunior Feb 7, 2022
843d361
chore: improve README.md
EclesioMeloJunior Feb 7, 2022
bcb134e
Merge branch 'development' into eclesio/substrate-docker-image
EclesioMeloJunior Feb 7, 2022
579136c
chore: add port 7001 explicitly
EclesioMeloJunior Feb 7, 2022
c49bcf0
chore: remove prometheus `--config.file` flag
EclesioMeloJunior Feb 8, 2022
f03093a
chore: use env to chain
EclesioMeloJunior Feb 8, 2022
25946ca
update substrate_bob.Dockerfile
EclesioMeloJunior Feb 8, 2022
e8c1e9d
Merge branch 'development' into eclesio/substrate-docker-image
EclesioMeloJunior Feb 9, 2022
15f1377
chore: add datadog-agent start to gssmr alice node
EclesioMeloJunior Feb 9, 2022
94c6a87
Merge branch 'eclesio/substrate-docker-image' of github.com:ChainSafe…
EclesioMeloJunior Feb 9, 2022
17fd1f2
chore: add comment about different but same node keys
EclesioMeloJunior Feb 16, 2022
aacb438
chore: update substrate docker images to version 0.9.17
EclesioMeloJunior Mar 2, 2022
a382561
chore: include license header
EclesioMeloJunior Mar 2, 2022
ca63faa
Merge branch 'development' into eclesio/substrate-docker-image
EclesioMeloJunior Mar 3, 2022
a4bd83c
chore: make image smaller, start dd agent at entrypoint
EclesioMeloJunior Mar 3, 2022
e476e23
chore: use only one genesis
EclesioMeloJunior Mar 3, 2022
e12686d
chore: be more descriptive at genesis.json folder
EclesioMeloJunior Mar 4, 2022
03c89c6
chore: update image to use arg polkadot version
EclesioMeloJunior Mar 4, 2022
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
11 changes: 10 additions & 1 deletion devnet/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ docker-compose up --abort-on-container-exit
docker-compose down
```

>> optional: you can add the flag `-f` followed by the path to the docker-compose.yml file

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

## Prometheus Datadog Integration
Expand All @@ -39,7 +41,14 @@ export $DD_API_KEY=YourKey

### 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`.
There are four Docker files used in the devnet.

- `alice.Dockerfile` is the lead node and is initiated with the `babe-lead` flag to build the first block.
- `bob.Dockerfile` is used for both `bob` and `charlie` and shares the same genesis as alice docker file.
EclesioMeloJunior marked this conversation as resolved.
Show resolved Hide resolved
- `substrate_alice.Dockerfile` is the alice node initiated with explicit node key to keep a deterministic peer id (the same used by gossamer alice node)
- `substrate_bob.Dockerfile` is used for `bob` and `charlie` and shares the same genesis as alice docker file.
EclesioMeloJunior marked this conversation as resolved.
Show resolved Hide resolved

> **_NOTE:_**: It is possible to use the substrate alice node with the bob and charlie gossamer nodes or any combination of these since the nodes in the network contain different keys

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

Expand Down
9 changes: 6 additions & 3 deletions devnet/alice.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@

FROM golang:1.17

ARG CHAIN=gssmr
ARG DD_API_KEY=somekey

ENV DD_API_KEY=${DD_API_KEY}

RUN 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
Expand All @@ -17,7 +20,7 @@ COPY . .
RUN go install -trimpath 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
RUN cp -f devnet/chain/$CHAIN/genesis-raw.json chain/gssmr/genesis-spec.json

RUN gossamer --key=alice init

Expand All @@ -32,6 +35,6 @@ RUN go run cmd/update-dd-agent-confd/main.go -n=${METRICS_NAMESPACE} -t=key:alic

WORKDIR /gossamer

ENTRYPOINT service datadog-agent start && gossamer --key=alice --babe-lead --publish-metrics --rpc --rpc-external=true --pubdns=alice
ENTRYPOINT service datadog-agent start && gossamer --key=alice --babe-lead --publish-metrics --rpc --rpc-external=true --pubdns=alice --port 7001

EXPOSE 7001/tcp 8545/tcp 8546/tcp 8540/tcp 9876/tcp
EXPOSE 7001/tcp 8545/tcp 8546/tcp 8540/tcp 9876/tcp 6060/tcp
qdm12 marked this conversation as resolved.
Show resolved Hide resolved
14 changes: 11 additions & 3 deletions devnet/bob.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@

FROM golang:1.17

ARG CHAIN=gssmr
ARG DD_API_KEY=somekey

ENV DD_API_KEY=${DD_API_KEY}

RUN 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
Expand All @@ -17,7 +20,7 @@ COPY . .
RUN go install -trimpath 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
RUN cp -f devnet/chain/$CHAIN/genesis-raw.json chain/gssmr/genesis-spec.json

ARG key
RUN test -n "$key"
Expand All @@ -33,6 +36,11 @@ RUN go run cmd/update-dd-agent-confd/main.go -n=${METRICS_NAMESPACE} -t=key:${ke

WORKDIR /gossamer

ENTRYPOINT service datadog-agent start && gossamer --key=${key} --bootnodes=/dns/alice/tcp/7001/p2p/12D3KooWMER5iow67nScpWeVqEiRRx59PJ3xMMAYPTACYPRQbbWU --publish-metrics --rpc --pubdns=${key}
ENTRYPOINT service datadog-agent start && gossamer --key=${key} \
--bootnodes=/dns/alice/tcp/7001/p2p/12D3KooWMER5iow67nScpWeVqEiRRx59PJ3xMMAYPTACYPRQbbWU \
--publish-metrics \
--rpc \
--port 7001 \
--pubdns=${key}

EXPOSE 7001/tcp 8545/tcp 8546/tcp 8540/tcp 9876/tcp
EXPOSE 7001/tcp 8545/tcp 8546/tcp 8540/tcp 9876/tcp 6060/tcp
157 changes: 157 additions & 0 deletions devnet/chain/cross-client/genesis-raw.json

Large diffs are not rendered by default.

197 changes: 197 additions & 0 deletions devnet/chain/cross-client/genesis.json

Large diffs are not rendered by default.

57 changes: 57 additions & 0 deletions devnet/docker-compose-substrate.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
services:
prometheus:
Copy link
Contributor

Choose a reason for hiding this comment

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

why are we running prometheus in this docker-compose?

Copy link
Member Author

Choose a reason for hiding this comment

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

I added Prometheus while testing the exported metric data from authority nodes, I decided to keep it in the same file to easily start a Prometheus server with authorities nodes, should I remove it?

image: prom/prometheus:v2.33.1
volumes:
- ./../prometheus.yml:/etc/prometheus/prometheus.yml:ro
command:
- '--storage.tsdb.path=/prometheus'
- '--web.console.libraries=/usr/share/prometheus/console_libraries'
- '--web.console.templates=/usr/share/prometheus/consoles'
ports:
- 9090
restart: always

alice:
platform: linux/amd64
build:
context: ./..
dockerfile: devnet/substrate_alice.Dockerfile
args:
DD_API_KEY: ${DD_API_KEY}
ports:
- 7001
- 8545
- 8546
- 9876

bob:
platform: linux/amd64
build:
context: ./..
dockerfile: devnet/substrate_bob.Dockerfile
args:
key: bob
DD_API_KEY: ${DD_API_KEY}
ports:
- 7001
- 8545
- 8546
- 9876
depends_on:
- alice

charlie:
platform: linux/amd64
build:
context: ./..
dockerfile: devnet/substrate_bob.Dockerfile
args:
key: charlie
DD_API_KEY: ${DD_API_KEY}
ports:
- 7001
- 8545
- 8546
- 9876
depends_on:
- alice
7 changes: 6 additions & 1 deletion devnet/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
services:
alice:
platform: linux/amd64
build:
context: ./..
dockerfile: devnet/alice.Dockerfile
Expand All @@ -11,8 +12,10 @@ services:
- 8546
- 8540
- 9876
- 6060
qdm12 marked this conversation as resolved.
Show resolved Hide resolved

bob:
platform: linux/amd64
build:
context: ./..
dockerfile: devnet/bob.Dockerfile
Expand All @@ -25,10 +28,12 @@ services:
- 8546
- 8540
- 9876
- 6060
depends_on:
- alice

charlie:
platform: linux/amd64
build:
context: ./..
dockerfile: devnet/bob.Dockerfile
Expand All @@ -42,4 +47,4 @@ services:
- 8540
- 9876
depends_on:
- alice
- alice
40 changes: 40 additions & 0 deletions devnet/substrate_alice.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
FROM parity/polkadot:v0.9.10 AS polkadot
FROM golang:1.17

ARG CHAIN=cross-client
Copy link
Contributor

Choose a reason for hiding this comment

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

what is the difference between the gssmr chain that's within our codebase and this one?

Copy link
Member Author

Choose a reason for hiding this comment

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

Both have 3 authority nodes, however, the cross-client genesis file is accepted by the substrate node since it has staking and session json keys while gssmr chain has Babe and Grandpa json keys. The cross-client genesis file has the runtime version 09.10 that don't trigger errors like:

CRIT target=runtime message=panicked at 'Timestamp slot must match `CurrentSlot`'

Copy link
Contributor

@timwu20 timwu20 Feb 23, 2022

Choose a reason for hiding this comment

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

Ideally we should have one chain all cross client, and gossamer only setups. We may end up having multiple of these chains that differ based on number of authority nodes.

@kishansagathiya is working on secondary vrf slot mode for babe #2307. We need to ensure that the genesis file is using this mode and we should be updating to v0.9.16 of polkadot.

It would be nice to have some sort of readme or something in the devnet readme that describes how to generate these files. I know you were following the steps provided by Kishan, but where did the original genesis-spec.json come from? What pallets are in the runtime? These are questions we should have answers to. It may make sense to have another repo and associated github CI workflows to generate these genesis files that the devnets can pull down as part of the docker image build process. Rather than just putting arbitrary files in this repo.

Copy link
Contributor

Choose a reason for hiding this comment

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

where did the original genesis-spec.json come from?

./polkadot build-spec --disable-default-bootnode --dev > genesis-spec.json
And then you will have to modify it according to your requirements, like adding authorities.

And then you run something like this to get a genesis.json file
./polkadot build-spec --chain genesis-spec.json --raw --disable-default-bootnode > genesis.json

Will make a pr to add this to read me.

New versions have a different genesis-spec file than 0.9.10.
Also running cross-client dev net with newer version of polkadot gives runtime errors. So, yeah we need to update.

Copy link
Contributor

Choose a reason for hiding this comment

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

can we rename this to something more descriptive. 3-auth-node-0.9.10 or something.

Copy link
Contributor

Choose a reason for hiding this comment

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

Also we could have 0.9.10 as a build argument at the top global scope in the Dockerfile.

i.e.

ARG POLKADOT_VERSION=v0.9.10

FROM parity/polkadot:${POLKADOT_VERSION} AS polkadot
FROM golang:1.17

ARG CHAIN=3-auth-node-${POLKADOT_VERSION}

Copy link
Member Author

Choose a reason for hiding this comment

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

@qdm12 I was having problems trying to use arguments declared before FROM, following this issue (link) I could resolve and apply the suggestion.

Basically, all the ARG's declared/initialized before FROM needs to be redeclared after FROM to use its values otherwise will not be possible to get the value from ARG. I your suggestion we need to add

ARG POLKADOT_VERSION=v0.9.10

FROM parity/polkadot:${POLKADOT_VERSION} AS polkadot
FROM golang:1.17

+ ARG POLKADOT_VERSION
# Now its possible to use the value here
ARG CHAIN=3-auth-node-${POLKADOT_VERSION} 

ARG VERSION=v0.9.10
ARG DD_API_KEY=somekey
ARG METRICS_NAMESPACE=substrate.local.devnet

ENV CHAIN=${CHAIN}
qdm12 marked this conversation as resolved.
Show resolved Hide resolved
ENV DD_API_KEY=${DD_API_KEY}

RUN 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)"

COPY --from=polkadot /usr/bin/polkadot /usr/bin/polkadot

WORKDIR /gossamer

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

COPY . .

WORKDIR /gossamer/devnet

RUN go run cmd/update-dd-agent-confd/main.go -n=${METRICS_NAMESPACE} -t=key:alice > /etc/datadog-agent/conf.d/openmetrics.d/conf.yaml
Copy link
Contributor

Choose a reason for hiding this comment

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

what port is prometheus running on? update-dd-agent-config is currently expecting the prometheus endpoint to be http://127.0.0.1:9876/metrics.

Copy link
Member Author

Choose a reason for hiding this comment

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

Changed substrate nodes to expose Prometheus at port 9876

Copy link
Contributor

Choose a reason for hiding this comment

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

What port does substrate uses? Shouldn't we use the standard 9090 port for Gossamer as well 🤔

Copy link
Member Author

@EclesioMeloJunior EclesioMeloJunior Feb 8, 2022

Choose a reason for hiding this comment

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

by default the port 9090 is the one Prometheus docker image prom/prometheus uses to bootstrap its own server to collect metrics. I just standardized the port which substrate and gossamer will expose metrics

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes but by default what's the port substrate/polkadot uses for Prometheus? We force it to 9876 here it seems. I'm thinking we should change it in Gossamer (for end users experience).

As far as I know, applications usually have their Prom registry server listening on 9090, so maybe we want to use that instead? Although if polkadot uses 9876 for whatever weird reason, then sure we can match it as well I guess.


ENTRYPOINT service datadog-agent start && /usr/bin/polkadot \
--chain chain/$CHAIN/genesis-raw.json \
--alice \
--port 7001 \
--rpc-port 8545 \
--ws-port 8546 \
--node-key "93ce444331ced4d2f7bfb8296267544e20c2591dbf310c7ea3af672f2879cf8f" \
EclesioMeloJunior marked this conversation as resolved.
Show resolved Hide resolved
--tmp \
--prometheus-external \
qdm12 marked this conversation as resolved.
Show resolved Hide resolved
--prometheus-port 9876 \
--unsafe-rpc-external \
--unsafe-ws-external

EXPOSE 7001/tcp 8545/tcp 8546/tcp 9876/tcp
42 changes: 42 additions & 0 deletions devnet/substrate_bob.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
FROM parity/polkadot:v0.9.10 AS polkadot
FROM golang:1.17
qdm12 marked this conversation as resolved.
Show resolved Hide resolved

ARG key
ARG CHAIN=cross-client
ARG DD_API_KEY=somekey
ARG METRICS_NAMESPACE=substrate.local.devnet

ENV key=${key}
ENV CHAIN=${CHAIN}
ENV DD_API_KEY=${DD_API_KEY}
qdm12 marked this conversation as resolved.
Show resolved Hide resolved

RUN test -n "${key}"
RUN 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)"

COPY --from=polkadot /usr/bin/polkadot /usr/bin/polkadot

WORKDIR /gossamer

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

COPY . .

WORKDIR /gossamer/devnet
qdm12 marked this conversation as resolved.
Show resolved Hide resolved

RUN go run cmd/update-dd-agent-confd/main.go -n=${METRICS_NAMESPACE} -t=key:$key > /etc/datadog-agent/conf.d/openmetrics.d/conf.yaml

ENTRYPOINT service datadog-agent start && /usr/bin/polkadot \
--bootnodes /dns/alice/tcp/7001/p2p/12D3KooWMER5iow67nScpWeVqEiRRx59PJ3xMMAYPTACYPRQbbWU \
--chain chain/$CHAIN/genesis-raw.json \
--port 7001 \
--rpc-port 8545 \
--ws-port 8546 \
--${key} \
--tmp \
--prometheus-external \
--prometheus-port 9876 \
--unsafe-rpc-external \
--unsafe-ws-external

EXPOSE 7001/tcp 8545/tcp 8546/tcp 9876/tcp
7 changes: 5 additions & 2 deletions prometheus.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ scrape_configs:
- job_name: prometheus
static_configs:
- targets: ['localhost:9090']
- job_name: gossamer
- job_name: gossamer_alice
metrics_path: /metrics
static_configs:
- targets: ['host.docker.internal:9876']
- targets: ['alice:9876']
- job_name: substrate_bob
static_configs:
- targets: ['bob:9876']