Skip to content

Commit

Permalink
feat(devnet): add substrate docker images to dockerfile (#2263)
Browse files Browse the repository at this point in the history
* feat: include substrate docker image

* chore: add substrate docker images

* chore: formatting and add depends on yaml key

* chore: add datadog stuff again

* chore: use alice peer id

* chore: split substrate docker compose services into another file

* chore: enable prometheus external and add datadog

* chore: keep substrate ports same as gossamer node ports

* chore: expose rpc and ws calls in substrate docker file

* chore: use same dns name and p2p id

* chore: use same key for both alice gossamer and substrate nodes

* chore: fix dd golang cmd

chore: keep both cross-client and gssmr chain genesis raw

chore: mistakes

* Update devnet/README.md

Co-authored-by: Quentin McGaw <quentin.mcgaw@gmail.com>

* Update devnet/README.md

Co-authored-by: Quentin McGaw <quentin.mcgaw@gmail.com>

* chore: update `substrate_alice` readme info

* Update devnet/README.md

Co-authored-by: Quentin McGaw <quentin.mcgaw@gmail.com>

* chore: add `/tcp` to expose ports

* chore: adjust args and envs

* chore: pin prometheus version, add read only volume and add trailing new line

* chore: improve README.md

* chore: add port 7001 explicitly

* chore: remove prometheus `--config.file` flag

Co-authored-by: Quentin McGaw <quentin.mcgaw@gmail.com>

* chore: use env to chain

This is needed since ARG cannot be used inside ENTRYPOINT

* update substrate_bob.Dockerfile

* chore: add datadog-agent start to gssmr alice node

* chore: add comment about different but same node keys

* chore: update substrate docker images to version 0.9.17

* chore: include license header

* chore: make image smaller, start dd agent at entrypoint

* chore: use only one genesis

* chore: be more descriptive at genesis.json folder

* chore: update image to use arg polkadot version

Co-authored-by: Quentin McGaw <quentin.mcgaw@gmail.com>
  • Loading branch information
EclesioMeloJunior and qdm12 authored Mar 8, 2022
1 parent 567c1ab commit b7b2a66
Show file tree
Hide file tree
Showing 11 changed files with 564 additions and 308 deletions.
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.
- `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.

> **_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
12 changes: 9 additions & 3 deletions devnet/alice.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,14 @@

FROM golang:1.17

ARG POLKADOT_VERSION=v0.9.10

# Using a genesis file with 3 authority nodes (alice, bob, charlie) generated using polkadot $POLKADOT_VERSION
ARG CHAIN=3-auth-node-${POLKADOT_VERSION}
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 +23,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 +38,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
18 changes: 15 additions & 3 deletions devnet/bob.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
# Copyright 2021 ChainSafe Systems (ON)
# SPDX-License-Identifier: LGPL-3.0-only


FROM golang:1.17

ARG POLKADOT_VERSION=v0.9.10

# Using a genesis file with 3 authority nodes (alice, bob, charlie) generated using polkadot $POLKADOT_VERSION
ARG CHAIN=3-auth-node-${POLKADOT_VERSION}
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 +24,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 +40,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/3-auth-node-v0.9.10/genesis-raw.json

Large diffs are not rendered by default.

197 changes: 197 additions & 0 deletions devnet/chain/3-auth-node-v0.9.10/genesis.json

Large diffs are not rendered by default.

298 changes: 0 additions & 298 deletions devnet/chain/gssmr/genesis-spec.json

This file was deleted.

45 changes: 45 additions & 0 deletions devnet/docker-compose-substrate.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
services:
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

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
61 changes: 61 additions & 0 deletions devnet/substrate_alice.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# Copyright 2022 ChainSafe Systems (ON)
# SPDX-License-Identifier: LGPL-3.0-only

ARG POLKADOT_VERSION=v0.9.10

FROM golang:1.17 as openmetrics
ARG METRICS_NAMESPACE=substrate.local.devnet

WORKDIR /devnet

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

COPY ./devnet .
RUN go run cmd/update-dd-agent-confd/main.go -n=${METRICS_NAMESPACE} -t=key:alice > conf.yaml

FROM parity/polkadot:${POLKADOT_VERSION}

ARG POLKADOT_VERSION
# Using a genesis file with 3 authority nodes (alice, bob, charlie) generated using polkadot $POLKADOT_VERSION
ARG CHAIN=3-auth-node-${POLKADOT_VERSION}
ARG DD_API_KEY=somekey

ENV DD_API_KEY=${DD_API_KEY}
ENV CHAIN=${CHAIN}

USER root
RUN gpg --recv-keys --keyserver hkps://keys.mailvelope.com 9D4B2B6EB8F97156D19669A9FF0812D491B96798
RUN gpg --export 9D4B2B6EB8F97156D19669A9FF0812D491B96798 > /usr/share/keyrings/parity.gpg
RUN apt update && apt install -y curl && rm -r /var/cache/* /var/lib/apt/lists/*

WORKDIR /cross-client

RUN curl -L https://s3.amazonaws.com/dd-agent/scripts/install_script.sh --output install_script.sh && \
chmod +x ./install_script.sh

RUN DD_AGENT_MAJOR_VERSION=7 DD_INSTALL_ONLY=true DD_SITE="datadoghq.com" ./install_script.sh
COPY --from=openmetrics /devnet/conf.yaml /etc/datadog-agent/conf.d/openmetrics.d/

USER polkadot

COPY ./devnet/chain ./chain/

# The substrate node-key argument should be a 32 bytes long sr25519 secret key
# while gossamer nodes uses a 64 bytes long sr25519 key (32 bytes long to secret key + 32 bytes long to public key).
# Then to keep both substrate and gossamer alice nodes with the same libp2p node keys we just need to use
# the first 32 bytes from `alice.node.key` which means the 32 bytes long sr25519 secret key used here.
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" \
--tmp \
--prometheus-external \
--prometheus-port 9876 \
--unsafe-rpc-external \
--unsafe-ws-external

EXPOSE 7001/tcp 8545/tcp 8546/tcp 9876/tcp
59 changes: 59 additions & 0 deletions devnet/substrate_bob.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# Copyright 2022 ChainSafe Systems (ON)
# SPDX-License-Identifier: LGPL-3.0-only
ARG POLKADOT_VERSION=v0.9.10
FROM golang:1.17 as openmetrics

ARG METRICS_NAMESPACE=substrate.local.devnet

WORKDIR /devnet

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

COPY ./devnet .
RUN go run cmd/update-dd-agent-confd/main.go -n=${METRICS_NAMESPACE} -t=key:alice > conf.yaml

FROM parity/polkadot:${POLKADOT_VERSION}

ARG POLKADOT_VERSION
# Using a genesis file with 3 authority nodes (alice, bob, charlie) generated using polkadot $POLKADOT_VERSION
ARG CHAIN=3-auth-node-${POLKADOT_VERSION}
ARG DD_API_KEY=somekey
ARG key

ENV DD_API_KEY=${DD_API_KEY}
ENV CHAIN=${CHAIN}
ENV key=${key}

USER root
RUN gpg --recv-keys --keyserver hkps://keys.mailvelope.com 9D4B2B6EB8F97156D19669A9FF0812D491B96798
RUN gpg --export 9D4B2B6EB8F97156D19669A9FF0812D491B96798 > /usr/share/keyrings/parity.gpg

RUN apt update && apt install -y curl && rm -r /var/cache/* /var/lib/apt/lists/*

WORKDIR /cross-client

RUN curl -L https://s3.amazonaws.com/dd-agent/scripts/install_script.sh --output install_script.sh && \
chmod +x ./install_script.sh

RUN DD_AGENT_MAJOR_VERSION=7 DD_INSTALL_ONLY=true DD_SITE="datadoghq.com" ./install_script.sh
COPY --from=openmetrics /devnet/conf.yaml /etc/datadog-agent/conf.d/openmetrics.d/

USER polkadot

COPY ./devnet/chain ./chain/

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']

0 comments on commit b7b2a66

Please sign in to comment.