From c09b8b6776d1b15083d57e54c522ef932975a075 Mon Sep 17 00:00:00 2001 From: Sergei Shulepov Date: Thu, 4 Jan 2024 16:32:46 +0100 Subject: [PATCH] build: docker-compose --- demo/rollkit/docker/Dockerfile | 7 +++- demo/sovereign/docker/Dockerfile | 9 ++--- docker/docker-compose.yml | 60 ++++++++++++++++++++++++++++++++ sugondat/chain/Dockerfile | 39 +++++++++++++++++---- sugondat/shim/Dockerfile | 9 ++--- 5 files changed, 108 insertions(+), 16 deletions(-) create mode 100644 docker/docker-compose.yml diff --git a/demo/rollkit/docker/Dockerfile b/demo/rollkit/docker/Dockerfile index b45f884d..f00d7795 100644 --- a/demo/rollkit/docker/Dockerfile +++ b/demo/rollkit/docker/Dockerfile @@ -27,7 +27,12 @@ RUN --mount=type=cache,target=/go/pkg \ FROM golang:1.21 AS prod +ENV TINI_VERSION v0.19.0 +ARG TARGETARCH +ADD https://github.com/krallin/tini/releases/download/${TINI_VERSION}/tini-${TARGETARCH} /tini +RUN chmod +x /tini + COPY --from=builder /go/bin/gmd /usr/local/bin/gmd COPY ./demo/rollkit/init-local.sh /root/init-local.sh WORKDIR /root -ENTRYPOINT /usr/local/bin/gmd +ENTRYPOINT ["/tini", "/root/init-local.sh"] diff --git a/demo/sovereign/docker/Dockerfile b/demo/sovereign/docker/Dockerfile index 99cd36ac..f8f9eb5a 100644 --- a/demo/sovereign/docker/Dockerfile +++ b/demo/sovereign/docker/Dockerfile @@ -42,9 +42,9 @@ COPY . /sugondat ENV CONSTANTS_MANIFEST=/sugondat/demo/sovereign/constants.json RUN \ - --mount=type=cache,target=/cargo/git \ - --mount=type=cache,target=/cargo/registry \ - --mount=type=cache,target=/cargo_target \ + --mount=type=cache,id=demo-sovereign,target=/cargo/git \ + --mount=type=cache,id=demo-sovereign,target=/cargo/registry \ + --mount=type=cache,id=demo-sovereign,target=/cargo_target \ cd demo/sovereign \ && $CARGO_HOME/bin/cargo build --release --locked \ && cp $CARGO_TARGET_DIR/release/sov-demo-rollup /usr/bin/sov-demo-rollup \ @@ -59,7 +59,8 @@ RUN \ pkg-config ENV TINI_VERSION v0.19.0 -ADD https://github.com/krallin/tini/releases/download/${TINI_VERSION}/tini /tini +ARG TARGETARCH +ADD https://github.com/krallin/tini/releases/download/${TINI_VERSION}/tini-${TARGETARCH} /tini RUN chmod +x /tini COPY --from=builder /usr/bin/sov-demo-rollup /usr/bin/sov-demo-rollup diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml new file mode 100644 index 00000000..77a6e46e --- /dev/null +++ b/docker/docker-compose.yml @@ -0,0 +1,60 @@ +# A couple of notes on this file. +# +# docker-compose takes over the control of the context meaning you don't pass it as an argument to +# build. Instead, the context is specified relative to the location of this file. In turn, the +# location of the dockerfile is relative to the context. + +name: sugondat + +services: + zombienet: + build: + context: .. + dockerfile: ./sugondat/chain/Dockerfile + target: zombienet + ports: + - "9988:9988" + # Mount /zombienet as tmpfs so as to avoid zombienet prompting if it should ignore existing + # directory. + tmpfs: /zombienet + shim: + build: + context: .. + dockerfile: ./sugondat/shim/Dockerfile + ports: + - "10995:10995" + # depends_on: + # zombienet: + # condition: service_healthy + environment: + - RUST_LOG=sugondat=trace + command: ["serve", "-p", "10995", "--node-url=ws://zombienet:9988", "--submit-dev-alice"] + # Health check. + # + # Note that if JSON-RPC returns an error, the health check will succeed. It's fine for now. + healthcheck: + test: [ + "CMD-SHELL", + "curl -s -XPOST -H 'Content-Type: application/json' -d '{\"jsonrpc\":\"2.0\",\"id\":0,\"method\":\"sovereign_getBlock\", \"params\":[1, \"0x00000000000000000000000000000000\"]}' http://localhost:10995/"] + gm: + build: + context: .. + dockerfile: ./demo/rollkit/docker/Dockerfile + depends_on: + shim: + condition: service_healthy + # This unites the Linux network namespace with the one of the `shim` service. That means that + # shim will be available via localhost. + network_mode: "service:shim" + sov: + build: + context: .. + dockerfile: ./demo/sovereign/docker/Dockerfile + depends_on: + shim: + condition: service_healthy + # Don't persist the rollup data directory. + tmpfs: /demo_data + # This unites the Linux network namespace with the one of the `shim` service. That means that + # shim will be available via localhost. + network_mode: "service:shim" diff --git a/sugondat/chain/Dockerfile b/sugondat/chain/Dockerfile index cd3fb289..af0c07e3 100644 --- a/sugondat/chain/Dockerfile +++ b/sugondat/chain/Dockerfile @@ -1,4 +1,9 @@ -FROM ubuntu:20.04 as builder +# HACK: Take note that this Dockerfile is meant to be used on x86-64 and apple silicon. However, +# we have to use `--platform=amd64` even on macs relying on rosetta 2 to run the code. The reason +# for that is zombienet requires a polkadot binary. Sadly, Polkadot is not packaged as a multi- +# arch binary. + +FROM --platform=amd64 ubuntu:20.04 as builder LABEL org.opencontainers.image.source=https://github.com/thrumdev/blobs @@ -36,18 +41,19 @@ RUN $CARGO_HOME/bin/rustup target add wasm32-unknown-unknown WORKDIR /sugondat COPY . /sugondat -FROM builder AS builder-release +FROM --platform=amd64 builder AS builder-release -RUN --mount=type=cache,target=/cargo/git \ - --mount=type=cache,target=/cargo/registry \ - --mount=type=cache,target=/cargo_target \ +RUN --mount=type=cache,id=sugondat-chain,target=/cargo/git \ + --mount=type=cache,id=sugondat-chain,target=/cargo/registry \ + --mount=type=cache,id=sugondat-chain,target=/cargo_target \ $CARGO_HOME/bin/cargo build --locked --release -p sugondat-node && \ cp /cargo_target/release/sugondat-node /usr/bin/sugondat-node -FROM ubuntu:20.04 +FROM --platform=amd64 ubuntu:20.04 as prod ENV TINI_VERSION v0.19.0 -ADD https://github.com/krallin/tini/releases/download/${TINI_VERSION}/tini /tini +# Hardcoded to amd64. See the comment at the top of this file. +ADD https://github.com/krallin/tini/releases/download/${TINI_VERSION}/tini-amd64 /tini RUN chmod +x /tini RUN \ @@ -59,3 +65,22 @@ RUN \ COPY --from=builder-release /usr/bin/sugondat-node /usr/bin/sugondat-node ENTRYPOINT ["/tini", "--", "/usr/bin/sugondat-node"] + +# This target supplements sugondat-node with all the sufficient components to spawn a full local +# testnet (zombienet). +FROM --platform=amd64 prod as zombienet + +RUN curl -sL https://deb.nodesource.com/setup_20.x | bash - +RUN apt-get install -y nodejs multitail +RUN npm install -g @zombienet/cli + +COPY --from=parity/polkadot:v1.4.0 /usr/bin/polkadot /usr/bin/ +COPY --from=parity/polkadot:v1.4.0 /usr/lib/polkadot/polkadot-prepare-worker /usr/bin/ +COPY --from=parity/polkadot:v1.4.0 /usr/lib/polkadot/polkadot-execute-worker /usr/bin/ + +COPY ./testnet.toml /testnet.toml + +EXPOSE 9988 + +VOLUME /zombienet +ENTRYPOINT ["/tini", "--", "zombienet", "spawn", "--provider=native", "-d/zombienet/data", "/testnet.toml"] diff --git a/sugondat/shim/Dockerfile b/sugondat/shim/Dockerfile index cb22d116..a1ba06ec 100644 --- a/sugondat/shim/Dockerfile +++ b/sugondat/shim/Dockerfile @@ -37,16 +37,17 @@ COPY . /sugondat FROM builder AS builder-release -RUN --mount=type=cache,target=/cargo/git \ - --mount=type=cache,target=/cargo/registry \ - --mount=type=cache,target=/cargo_target \ +RUN --mount=type=cache,id=sugondat-shim,target=/cargo/git \ + --mount=type=cache,id=sugondat-shim,target=/cargo/registry \ + --mount=type=cache,id=sugondat-shim,target=/cargo_target \ $CARGO_HOME/bin/cargo build --locked --release -p sugondat-shim && \ cp /cargo_target/release/sugondat-shim /usr/bin/sugondat-shim FROM ubuntu:20.04 ENV TINI_VERSION v0.19.0 -ADD https://github.com/krallin/tini/releases/download/${TINI_VERSION}/tini /tini +ARG TARGETARCH +ADD https://github.com/krallin/tini/releases/download/${TINI_VERSION}/tini-${TARGETARCH} /tini RUN chmod +x /tini RUN \