Skip to content

Commit 2255128

Browse files
committed
feat(sdk): prepare Dockerfile for additional container releases
1 parent 0ac90f8 commit 2255128

3 files changed

Lines changed: 154 additions & 73 deletions

File tree

.changeset/angry-rats-mate.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@cartesi/sdk": patch
3+
---
4+
5+
refactor Dockerfile for additional runtime and database targets

packages/sdk/Dockerfile

Lines changed: 143 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,15 @@
11
# syntax=docker.io/docker/dockerfile:1
2-
ARG BASE_IMAGE
3-
ARG CARTESI_ESPRESSO_READER_VERSION
4-
ARG CARTESI_IMAGE_KERNEL_VERSION
5-
ARG CARTESI_MACHINE_EMULATOR_VERSION
6-
ARG CARTESI_ROLLUPS_GRAPHQL_VERSION
7-
ARG CRANE_VERSION
8-
ARG ESPRESSO_DEV_NODE_TAG
9-
ARG FOUNDRY_VERSION
10-
ARG LINUX_KERNEL_VERSION
11-
ARG NODEJS_VERSION
12-
ARG POSTGRES_VERSION
13-
ARG SU_EXEC_VERSION
14-
ARG XGENEXT2_VERSION
2+
ARG CARTESI_BASE_IMAGE
3+
ARG ESPRESSO_DEV_NODE_BASE_IMAGE
4+
ARG POSTGRES_BASE_IMAGE
155

166
################################################################################
177
# https://github.com/EspressoSystems/espresso-sequencer/pkgs/container/espresso-sequencer%2Fespresso-dev-node
18-
FROM ghcr.io/espressosystems/espresso-sequencer/espresso-dev-node:${ESPRESSO_DEV_NODE_TAG} AS espresso-dev-node
8+
FROM ${ESPRESSO_DEV_NODE_BASE_IMAGE} AS espresso-dev-node
199

2010
################################################################################
2111
# base image
22-
FROM ${BASE_IMAGE} AS base
12+
FROM ${CARTESI_BASE_IMAGE} AS base
2313
SHELL ["/bin/bash", "-euo", "pipefail", "-c"]
2414
ARG DEBIAN_FRONTEND=noninteractive
2515
RUN <<EOF
@@ -130,28 +120,136 @@ curl -fsSL "https://github.com/cartesi/rollups-espresso-reader/archive/refs/tags
130120
| tar --wildcards -xz -C ${ESPRESSO_DEST_FOLDER} --strip-components=6 '*/migrations/*.sql'
131121
EOF
132122

123+
################################################################################
124+
# cartesi runtime target
125+
FROM base AS runtime
126+
ARG CARTESI_MACHINE_EMULATOR_VERSION
127+
ARG CARTESI_ROLLUPS_NODE_VERSION
128+
ARG TARGETARCH
129+
130+
USER root
131+
ARG DEBIAN_FRONTEND=noninteractive
132+
RUN <<EOF
133+
apt-get install -y --no-install-recommends \
134+
libslirp0 \
135+
lua5.4 \
136+
xz-utils
137+
rm -rf /var/lib/apt/lists/*
138+
EOF
139+
140+
RUN <<EOF
141+
set -e
142+
addgroup --system --gid 102 cartesi
143+
adduser --system --uid 102 \
144+
--disabled-login \
145+
--gecos "cartesi user" \
146+
--home /nonexistent \
147+
--ingroup cartesi \
148+
--no-create-home \
149+
--shell /bin/false \
150+
cartesi
151+
EOF
152+
153+
# Install cartesi-machine emulator
154+
RUN <<EOF
155+
curl -fsSL https://github.com/cartesi/machine-emulator/releases/download/v${CARTESI_MACHINE_EMULATOR_VERSION}/cartesi-machine-v${CARTESI_MACHINE_EMULATOR_VERSION}_${TARGETARCH}.deb \
156+
-o /tmp/cartesi-machine.deb
157+
dpkg -i /tmp/cartesi-machine.deb
158+
rm /tmp/cartesi-machine.deb
159+
cartesi-machine --version-json
160+
EOF
161+
162+
# Install cartesi-rollups-node
163+
RUN <<EOF
164+
curl -fsSL https://github.com/cartesi/rollups-node/releases/download/v${CARTESI_ROLLUPS_NODE_VERSION}/cartesi-rollups-node-v${CARTESI_ROLLUPS_NODE_VERSION%%-*}_${TARGETARCH}.deb \
165+
-o /tmp/cartesi-rollups-node.deb
166+
dpkg -i /tmp/cartesi-rollups-node.deb
167+
rm /tmp/cartesi-rollups-node.deb
168+
mkdir -p /var/lib/cartesi-rollups-node/snapshots
169+
chmod 755 /var/lib/cartesi-rollups-node/snapshots
170+
chown cartesi:cartesi /var/lib/cartesi-rollups-node/snapshots
171+
cartesi-rollups-node --version
172+
EOF
173+
174+
COPY --from=graphql /usr/local/bin/cartesi-rollups-graphql /usr/local/bin/
175+
COPY --from=espresso-reader /usr/local/bin/cartesi-rollups-espresso-reader /usr/local/bin/
176+
177+
USER cartesi
178+
133179
################################################################################
134180
# postgresql initdb
135-
FROM postgres:${POSTGRES_VERSION} AS postgresql-initdb
136-
ENV POSTGRES_PASSWORD=password
181+
FROM ${POSTGRES_BASE_IMAGE} AS postgresql-initdb
182+
183+
ARG DEBIAN_FRONTEND=noninteractive
184+
RUN <<EOF
185+
set -eo
186+
apt-get update
187+
apt-get install -y --no-install-recommends \
188+
libslirp0
189+
EOF
190+
191+
COPY --from=runtime /usr/bin/cartesi-rollups-cli /usr/bin/
192+
COPY --from=runtime /usr/lib/libcartesi* /usr/lib/
193+
COPY --from=go-migrate /usr/local/bin/migrate /usr/local/bin/
194+
COPY --from=graphql-migration /usr/share/cartesi/rollups-graphql/migrations /usr/share/cartesi/rollups-graphql/migrations
195+
COPY --from=espresso-reader-migration /usr/share/cartesi/rollups-espresso-reader/migrations /usr/share/cartesi/rollups-espresso-reader/migrations
196+
197+
ARG POSTGRES_PASSWORD=password
198+
199+
# create rollupsdb, graphql and espresso databases
200+
COPY <<EOF /docker-entrypoint-initdb.d/00-createdb.sql
201+
CREATE DATABASE rollupsdb;
202+
CREATE DATABASE graphql;
203+
CREATE DATABASE espresso;
204+
EOF
205+
206+
# rollups-node migrations
207+
COPY <<EOF /docker-entrypoint-initdb.d/01-rollups-node-migrations.sh
208+
#!/usr/bin/env bash
209+
set -e
210+
export CARTESI_DATABASE_CONNECTION="postgres://postgres@/rollupsdb?host=/var/run/postgresql"
211+
cartesi-rollups-cli db upgrade --verbose
212+
EOF
213+
214+
# rollups-graphql migrations
215+
COPY <<EOF /docker-entrypoint-initdb.d/02-graphql-migrations.sh
216+
#!/usr/bin/env bash
217+
set -e
218+
migrate -verbose -path /usr/share/cartesi/rollups-graphql/migrations -database 'postgres://postgres@/graphql?host=/var/run/postgresql' up
219+
EOF
220+
221+
# espresso-reader migrations
222+
COPY <<EOF /docker-entrypoint-initdb.d/03-espresso-reader-migrations.sh
223+
#!/usr/bin/env bash
224+
set -e
225+
migrate -verbose -path /usr/share/cartesi/rollups-espresso-reader/migrations -database 'postgres://postgres@/rollupsdb?host=/var/run/postgresql' up
226+
EOF
227+
137228
RUN /usr/local/bin/docker-ensure-initdb.sh postgres
138229

230+
################################################################################
231+
# rollups-database image
232+
FROM ${POSTGRES_BASE_IMAGE} AS database
233+
COPY --from=postgresql-initdb /var/lib/postgresql/data /var/lib/postgresql/data
234+
139235
################################################################################
140236
# sdk final image
141-
FROM base
237+
FROM runtime
142238
ARG ALTO_VERSION
239+
ARG CARTESI_DEVNET_VERSION
143240
ARG CARTESI_IMAGE_KERNEL_VERSION
241+
ARG CARTESI_LINUX_KERNEL_VERSION
144242
ARG CARTESI_MACHINE_EMULATOR_VERSION
243+
ARG CARTESI_PAYMASTER_VERSION
145244
ARG CARTESI_ROLLUPS_NODE_VERSION
146-
ARG DEVNET_VERSION
147-
ARG LINUX_KERNEL_VERSION
148-
ARG PAYMASTER_VERSION
245+
ARG TARGETARCH
149246
ARG TARGETARCH
150247
ARG XGENEXT2_VERSION
151248

152249
USER root
153250
ARG DEBIAN_FRONTEND=noninteractive
154251
RUN <<EOF
252+
apt-get update
155253
apt-get install -y --no-install-recommends \
156254
jq \
157255
libarchive-tools \
@@ -163,8 +261,11 @@ apt-get install -y --no-install-recommends \
163261
squashfs-tools \
164262
xxd \
165263
xz-utils
264+
rm -rf /var/lib/apt/lists/*
265+
EOF
166266

167267
# Install e2fsprogs from backports
268+
RUN <<EOF
168269
echo 'deb http://deb.debian.org/debian bookworm-backports main' > /etc/apt/sources.list.d/backports.list
169270
apt-get update
170271
apt-get install -y --no-install-recommends -t bookworm-backports \
@@ -188,15 +289,33 @@ EOF
188289
# Install nodejs packages
189290
RUN <<EOF
190291
npm install -g \
191-
@cartesi/devnet@${DEVNET_VERSION} \
192-
@cartesi/mock-verifying-paymaster@${PAYMASTER_VERSION} \
292+
@cartesi/devnet@${CARTESI_DEVNET_VERSION} \
293+
@cartesi/mock-verifying-paymaster@${CARTESI_PAYMASTER_VERSION} \
193294
@pimlico/alto@${ALTO_VERSION}
194295

195296
mkdir -p /usr/share/cartesi
196297
cp /usr/local/lib/node_modules/@cartesi/devnet/export/abi/localhost.json /usr/share/cartesi/
197298
cp /usr/local/lib/node_modules/@cartesi/devnet/build/anvil_state.json /usr/share/cartesi/
198299
EOF
199300

301+
# Install linux kernel image
302+
RUN <<EOF
303+
curl -fsSL "https://github.com/cartesi/image-kernel/releases/download/v${CARTESI_IMAGE_KERNEL_VERSION}/linux-${CARTESI_LINUX_KERNEL_VERSION}.bin" \
304+
-o /usr/share/cartesi-machine/images/linux.bin
305+
echo "e4663365ea565792110129a6b479eca896cb31c23f561cb42214609588689f9d3d173a82b4ea27ff74ae05334747cc76ed6bc4c200a7499ac5134abfd2b3045e /usr/share/cartesi-machine/images/linux.bin" \
306+
| sha512sum -c
307+
EOF
308+
309+
# Install linux headers
310+
RUN <<EOF
311+
curl -fsSL "https://github.com/cartesi/image-kernel/releases/download/v${CARTESI_IMAGE_KERNEL_VERSION}/linux-headers-${CARTESI_LINUX_KERNEL_VERSION}.tar.xz" \
312+
-o "/tmp/linux-headers-${CARTESI_LINUX_KERNEL_VERSION}.tar.xz"
313+
echo "2ecdb9c9f02a96faed2605ec811ef7188f963feb21b32d057b1ab3278f27ac42887f235a3f52eadd5f5caa56a61e141ad2bb666793d5bdd755c273adba167d45 /tmp/linux-headers-${CARTESI_LINUX_KERNEL_VERSION}.tar.xz" \
314+
| sha512sum -c
315+
tar -xJf "/tmp/linux-headers-${CARTESI_LINUX_KERNEL_VERSION}.tar.xz" -C /
316+
rm "/tmp/linux-headers-${CARTESI_LINUX_KERNEL_VERSION}.tar.xz"
317+
EOF
318+
200319
ENV LC_ALL=en_US.UTF-8
201320
ENV LANG=en_US.UTF-8
202321
ENV LANGUAGE=en_US:en
@@ -214,52 +333,10 @@ COPY --from=su-exec /usr/local/src/su-exec /usr/local/bin/
214333
COPY --from=crane /usr/local/bin/crane /usr/local/bin/
215334
COPY --from=foundry /usr/local/bin/anvil /usr/local/bin/
216335
COPY --from=foundry /usr/local/bin/cast /usr/local/bin/
336+
COPY --from=espresso-dev-node /usr/bin/espresso-dev-node /usr/local/bin/
217337
COPY --from=go-migrate /usr/local/bin/migrate /usr/local/bin/
218-
COPY --from=graphql /usr/local/bin/cartesi-rollups-graphql /usr/local/bin/
219338
COPY --from=graphql-migration /usr/share/cartesi/rollups-graphql/migrations /usr/share/cartesi/rollups-graphql/migrations
220-
COPY --from=espresso-reader /usr/local/bin/cartesi-rollups-espresso-reader /usr/local/bin/
221339
COPY --from=espresso-reader-migration /usr/share/cartesi/rollups-espresso-reader/migrations /usr/share/cartesi/rollups-espresso-reader/migrations
222-
COPY --from=espresso-dev-node /usr/bin/espresso-dev-node /usr/local/bin/
223-
COPY --from=postgresql-initdb /var/lib/postgresql/data /var/lib/postgresql/data
224-
225-
RUN mkdir -p /tmp/.cartesi && chmod 1777 /tmp/.cartesi
226-
227-
# Install cartesi-machine emulator
228-
RUN <<EOF
229-
curl -fsSL https://github.com/cartesi/machine-emulator/releases/download/v${CARTESI_MACHINE_EMULATOR_VERSION}/cartesi-machine-v${CARTESI_MACHINE_EMULATOR_VERSION}_${TARGETARCH}.deb \
230-
-o /tmp/cartesi-machine.deb
231-
dpkg -i /tmp/cartesi-machine.deb
232-
rm /tmp/cartesi-machine.deb
233-
cartesi-machine --version-json
234-
EOF
235-
236-
# Install linux kernel image
237-
RUN <<EOF
238-
curl -fsSL "https://github.com/cartesi/image-kernel/releases/download/v${CARTESI_IMAGE_KERNEL_VERSION}/linux-${LINUX_KERNEL_VERSION}.bin" \
239-
-o /usr/share/cartesi-machine/images/linux.bin
240-
echo "e4663365ea565792110129a6b479eca896cb31c23f561cb42214609588689f9d3d173a82b4ea27ff74ae05334747cc76ed6bc4c200a7499ac5134abfd2b3045e /usr/share/cartesi-machine/images/linux.bin" \
241-
| sha512sum -c
242-
EOF
243-
244-
# Install linux headers
245-
RUN <<EOF
246-
curl -fsSL "https://github.com/cartesi/image-kernel/releases/download/v${CARTESI_IMAGE_KERNEL_VERSION}/linux-headers-${LINUX_KERNEL_VERSION}.tar.xz" \
247-
-o "/tmp/linux-headers-$LINUX_KERNEL_VERSION.tar.xz"
248-
echo "2ecdb9c9f02a96faed2605ec811ef7188f963feb21b32d057b1ab3278f27ac42887f235a3f52eadd5f5caa56a61e141ad2bb666793d5bdd755c273adba167d45 /tmp/linux-headers-${LINUX_KERNEL_VERSION}.tar.xz" \
249-
| sha512sum -c
250-
tar -xJf "/tmp/linux-headers-${LINUX_KERNEL_VERSION}.tar.xz" -C /
251-
rm "/tmp/linux-headers-${LINUX_KERNEL_VERSION}.tar.xz"
252-
EOF
253-
254-
# Install cartesi-rollups-node
255-
RUN <<EOF
256-
curl -fsSL https://github.com/cartesi/rollups-node/releases/download/v${CARTESI_ROLLUPS_NODE_VERSION}/cartesi-rollups-node-v${CARTESI_ROLLUPS_NODE_VERSION%%-*}_${TARGETARCH}.deb \
257-
-o /tmp/cartesi-rollups-node.deb
258-
dpkg -i /tmp/cartesi-rollups-node.deb
259-
rm /tmp/cartesi-rollups-node.deb
260-
mkdir -p /var/lib/cartesi-rollups-node/snapshots
261-
cartesi-rollups-node --version
262-
EOF
263340

264341
WORKDIR /mnt
265342
ENTRYPOINT ["/usr/local/bin/entrypoint.sh"]

packages/sdk/docker-bake.hcl

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,20 @@ target "default" {
55
inherits = ["docker-metadata-action", "docker-platforms"]
66
args = {
77
ALTO_VERSION = "0.0.4"
8-
BASE_IMAGE = "debian:bookworm-20250224"
8+
CARTESI_BASE_IMAGE = "docker.io/library/debian:bookworm-20250317-slim@sha256:1209d8fd77def86ceb6663deef7956481cc6c14a25e1e64daec12c0ceffcc19d"
9+
CARTESI_DEVNET_VERSION = "2.0.0-alpha.3"
910
CARTESI_ESPRESSO_READER_VERSION = "0.2.3-node-20250128"
1011
CARTESI_IMAGE_KERNEL_VERSION = "0.20.0"
12+
CARTESI_LINUX_KERNEL_VERSION = "6.5.13-ctsi-1-v0.20.0"
1113
CARTESI_MACHINE_EMULATOR_VERSION = "0.18.1"
14+
CARTESI_PAYMASTER_VERSION = "0.2.0"
1215
CARTESI_ROLLUPS_GRAPHQL_VERSION = "2.3.8"
1316
CARTESI_ROLLUPS_NODE_VERSION = "2.0.0-alpha.1"
1417
CRANE_VERSION = "0.19.1"
15-
DEVNET_VERSION = "2.0.0-alpha.3"
16-
ESPRESSO_DEV_NODE_TAG = "20241120-patch6"
18+
ESPRESSO_DEV_NODE_BASE_IMAGE = "ghcr.io/espressosystems/espresso-sequencer/espresso-dev-node:20241120-patch6@sha256:453264eab19e3313c85a8720c784f16f15e36bacb28ae917034e24342cecf3c3"
1719
FOUNDRY_VERSION = "0.3.0"
1820
GO_MIGRATE_VERSION = "4.18.2"
19-
LINUX_KERNEL_VERSION = "6.5.13-ctsi-1-v0.20.0"
20-
NODEJS_VERSION = "18.19.0"
21-
PAYMASTER_VERSION = "0.2.0"
22-
POSTGRES_VERSION = "16"
21+
POSTGRES_BASE_IMAGE = "docker.io/library/postgres:16@sha256:e95b0cb95f719e0ce156c2bc5545c89fbd98a1a692845a5331ddc79ea61f1b1e"
2322
SU_EXEC_VERSION = "0.2"
2423
XGENEXT2_VERSION = "1.5.6"
2524
}

0 commit comments

Comments
 (0)