Skip to content

Commit bb1bb69

Browse files
pepyakinrphmeier
authored andcommitted
build: docker-compose
This commit introduces docker/docker-compose.yml. Thanks to it you can now spin up a network with just one command: docker compose -f docker/docker-compose.yml --build up That will launch the polkadot localnet, the parachain node, the shim and the demoes: gm (based on rollkit) and the sovereign demo. Besides that this commit adds explicit cache IDs: that seems to improve the caching behavior when running builds from docker-compose. Atm, parity/polkadot image isn't multi-arch and doesn't support arm64. To properly support macOS builds I opted to build the whole thing inside amd64. It seems it has ok performance. Also, I wrapped the docker entrypoints in tini. This solves the problem of propagating the SIGTERM/SIGINT when stopping the services.
1 parent 1efcf58 commit bb1bb69

File tree

5 files changed

+108
-16
lines changed

5 files changed

+108
-16
lines changed

demo/rollkit/docker/Dockerfile

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,12 @@ RUN --mount=type=cache,target=/go/pkg \
2727

2828
FROM golang:1.21 AS prod
2929

30+
ENV TINI_VERSION v0.19.0
31+
ARG TARGETARCH
32+
ADD https://github.com/krallin/tini/releases/download/${TINI_VERSION}/tini-${TARGETARCH} /tini
33+
RUN chmod +x /tini
34+
3035
COPY --from=builder /go/bin/gmd /usr/local/bin/gmd
3136
COPY ./demo/rollkit/init-local.sh /root/init-local.sh
3237
WORKDIR /root
33-
ENTRYPOINT /usr/local/bin/gmd
38+
ENTRYPOINT ["/tini", "/root/init-local.sh"]

demo/sovereign/docker/Dockerfile

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,9 @@ COPY . /sugondat
4242

4343
ENV CONSTANTS_MANIFEST=/sugondat/demo/sovereign/constants.json
4444
RUN \
45-
--mount=type=cache,target=/cargo/git \
46-
--mount=type=cache,target=/cargo/registry \
47-
--mount=type=cache,target=/cargo_target \
45+
--mount=type=cache,id=demo-sovereign,target=/cargo/git \
46+
--mount=type=cache,id=demo-sovereign,target=/cargo/registry \
47+
--mount=type=cache,id=demo-sovereign,target=/cargo_target \
4848
cd demo/sovereign \
4949
&& $CARGO_HOME/bin/cargo build --release --locked \
5050
&& cp $CARGO_TARGET_DIR/release/sov-demo-rollup /usr/bin/sov-demo-rollup \
@@ -59,7 +59,8 @@ RUN \
5959
pkg-config
6060

6161
ENV TINI_VERSION v0.19.0
62-
ADD https://github.com/krallin/tini/releases/download/${TINI_VERSION}/tini /tini
62+
ARG TARGETARCH
63+
ADD https://github.com/krallin/tini/releases/download/${TINI_VERSION}/tini-${TARGETARCH} /tini
6364
RUN chmod +x /tini
6465

6566
COPY --from=builder /usr/bin/sov-demo-rollup /usr/bin/sov-demo-rollup

docker/docker-compose.yml

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# A couple of notes on this file.
2+
#
3+
# docker-compose takes over the control of the context meaning you don't pass it as an argument to
4+
# build. Instead, the context is specified relative to the location of this file. In turn, the
5+
# location of the dockerfile is relative to the context.
6+
7+
name: sugondat
8+
9+
services:
10+
zombienet:
11+
build:
12+
context: ..
13+
dockerfile: ./sugondat/chain/Dockerfile
14+
target: zombienet
15+
ports:
16+
- "9988:9988"
17+
# Mount /zombienet as tmpfs so as to avoid zombienet prompting if it should ignore existing
18+
# directory.
19+
tmpfs: /zombienet
20+
shim:
21+
build:
22+
context: ..
23+
dockerfile: ./sugondat/shim/Dockerfile
24+
ports:
25+
- "10995:10995"
26+
# depends_on:
27+
# zombienet:
28+
# condition: service_healthy
29+
environment:
30+
- RUST_LOG=sugondat=trace
31+
command: ["serve", "-p", "10995", "--node-url=ws://zombienet:9988", "--submit-dev-alice"]
32+
# Health check.
33+
#
34+
# Note that if JSON-RPC returns an error, the health check will succeed. It's fine for now.
35+
healthcheck:
36+
test: [
37+
"CMD-SHELL",
38+
"curl -s -XPOST -H 'Content-Type: application/json' -d '{\"jsonrpc\":\"2.0\",\"id\":0,\"method\":\"sovereign_getBlock\", \"params\":[1, \"0x00000000000000000000000000000000\"]}' http://localhost:10995/"]
39+
gm:
40+
build:
41+
context: ..
42+
dockerfile: ./demo/rollkit/docker/Dockerfile
43+
depends_on:
44+
shim:
45+
condition: service_healthy
46+
# This unites the Linux network namespace with the one of the `shim` service. That means that
47+
# shim will be available via localhost.
48+
network_mode: "service:shim"
49+
sov:
50+
build:
51+
context: ..
52+
dockerfile: ./demo/sovereign/docker/Dockerfile
53+
depends_on:
54+
shim:
55+
condition: service_healthy
56+
# Don't persist the rollup data directory.
57+
tmpfs: /demo_data
58+
# This unites the Linux network namespace with the one of the `shim` service. That means that
59+
# shim will be available via localhost.
60+
network_mode: "service:shim"

sugondat/chain/Dockerfile

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
FROM ubuntu:20.04 as builder
1+
# HACK: Take note that this Dockerfile is meant to be used on x86-64 and apple silicon. However,
2+
# we have to use `--platform=amd64` even on macs relying on rosetta 2 to run the code. The reason
3+
# for that is zombienet requires a polkadot binary. Sadly, Polkadot is not packaged as a multi-
4+
# arch binary.
5+
6+
FROM --platform=amd64 ubuntu:20.04 as builder
27

38
LABEL org.opencontainers.image.source=https://github.com/thrumdev/blobs
49

@@ -36,18 +41,19 @@ RUN $CARGO_HOME/bin/rustup target add wasm32-unknown-unknown
3641
WORKDIR /sugondat
3742
COPY . /sugondat
3843

39-
FROM builder AS builder-release
44+
FROM --platform=amd64 builder AS builder-release
4045

41-
RUN --mount=type=cache,target=/cargo/git \
42-
--mount=type=cache,target=/cargo/registry \
43-
--mount=type=cache,target=/cargo_target \
46+
RUN --mount=type=cache,id=sugondat-chain,target=/cargo/git \
47+
--mount=type=cache,id=sugondat-chain,target=/cargo/registry \
48+
--mount=type=cache,id=sugondat-chain,target=/cargo_target \
4449
$CARGO_HOME/bin/cargo build --locked --release -p sugondat-node && \
4550
cp /cargo_target/release/sugondat-node /usr/bin/sugondat-node
4651

47-
FROM ubuntu:20.04
52+
FROM --platform=amd64 ubuntu:20.04 as prod
4853

4954
ENV TINI_VERSION v0.19.0
50-
ADD https://github.com/krallin/tini/releases/download/${TINI_VERSION}/tini /tini
55+
# Hardcoded to amd64. See the comment at the top of this file.
56+
ADD https://github.com/krallin/tini/releases/download/${TINI_VERSION}/tini-amd64 /tini
5157
RUN chmod +x /tini
5258

5359
RUN \
@@ -59,3 +65,22 @@ RUN \
5965
COPY --from=builder-release /usr/bin/sugondat-node /usr/bin/sugondat-node
6066

6167
ENTRYPOINT ["/tini", "--", "/usr/bin/sugondat-node"]
68+
69+
# This target supplements sugondat-node with all the sufficient components to spawn a full local
70+
# testnet (zombienet).
71+
FROM --platform=amd64 prod as zombienet
72+
73+
RUN curl -sL https://deb.nodesource.com/setup_20.x | bash -
74+
RUN apt-get install -y nodejs multitail
75+
RUN npm install -g @zombienet/cli
76+
77+
COPY --from=parity/polkadot:v1.4.0 /usr/bin/polkadot /usr/bin/
78+
COPY --from=parity/polkadot:v1.4.0 /usr/lib/polkadot/polkadot-prepare-worker /usr/bin/
79+
COPY --from=parity/polkadot:v1.4.0 /usr/lib/polkadot/polkadot-execute-worker /usr/bin/
80+
81+
COPY ./testnet.toml /testnet.toml
82+
83+
EXPOSE 9988
84+
85+
VOLUME /zombienet
86+
ENTRYPOINT ["/tini", "--", "zombienet", "spawn", "--provider=native", "-d/zombienet/data", "/testnet.toml"]

sugondat/shim/Dockerfile

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,17 @@ COPY . /sugondat
3737

3838
FROM builder AS builder-release
3939

40-
RUN --mount=type=cache,target=/cargo/git \
41-
--mount=type=cache,target=/cargo/registry \
42-
--mount=type=cache,target=/cargo_target \
40+
RUN --mount=type=cache,id=sugondat-shim,target=/cargo/git \
41+
--mount=type=cache,id=sugondat-shim,target=/cargo/registry \
42+
--mount=type=cache,id=sugondat-shim,target=/cargo_target \
4343
$CARGO_HOME/bin/cargo build --locked --release -p sugondat-shim && \
4444
cp /cargo_target/release/sugondat-shim /usr/bin/sugondat-shim
4545

4646
FROM ubuntu:20.04
4747

4848
ENV TINI_VERSION v0.19.0
49-
ADD https://github.com/krallin/tini/releases/download/${TINI_VERSION}/tini /tini
49+
ARG TARGETARCH
50+
ADD https://github.com/krallin/tini/releases/download/${TINI_VERSION}/tini-${TARGETARCH} /tini
5051
RUN chmod +x /tini
5152

5253
RUN \

0 commit comments

Comments
 (0)