Skip to content

Commit

Permalink
build: docker-compose
Browse files Browse the repository at this point in the history
  • Loading branch information
pepyakin committed Jan 11, 2024
1 parent c4dd651 commit c09b8b6
Show file tree
Hide file tree
Showing 5 changed files with 108 additions and 16 deletions.
7 changes: 6 additions & 1 deletion demo/rollkit/docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
9 changes: 5 additions & 4 deletions demo/sovereign/docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand All @@ -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
Expand Down
60 changes: 60 additions & 0 deletions docker/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -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"
39 changes: 32 additions & 7 deletions sugondat/chain/Dockerfile
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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 \
Expand All @@ -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"]
9 changes: 5 additions & 4 deletions sugondat/shim/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down

0 comments on commit c09b8b6

Please sign in to comment.