Skip to content

Commit ad4e08d

Browse files
committed
Support Web3signer distroless
1 parent 0f254a9 commit ad4e08d

9 files changed

Lines changed: 241 additions & 59 deletions

File tree

.github/workflows/build-clients.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@ jobs:
2222
test_cl: false
2323
test_el: false
2424
test_vc: false
25+
- env: |-
26+
CORE_FILES=web3signer.yml
27+
W3S_DOCKERFILE=Dockerfile.source
28+
test_cl: false
29+
test_el: false
30+
test_vc: false
2531
- env: |-
2632
COMPOSE_FILE=nimbus-vp.yml
2733
NIMVP_DOCKERFILE=Dockerfile.source
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
name: Test Web3signer
2+
3+
defaults:
4+
run:
5+
shell: bash
6+
7+
on:
8+
push:
9+
branches: [main]
10+
pull_request:
11+
types: [opened, synchronize, labeled, unlabeled]
12+
branches: [main]
13+
14+
concurrency:
15+
group: ci-${{ github.workflow }}-${{ github.ref }}
16+
cancel-in-progress: true
17+
18+
jobs:
19+
test-web3signer:
20+
if: |
21+
contains(github.event.pull_request.labels.*.name, 'test-web3signer') ||
22+
contains(github.event.pull_request.labels.*.name, 'test-all') ||
23+
github.event_name == 'push'
24+
runs-on: ubuntu-latest
25+
steps:
26+
- name: Checkout
27+
uses: actions/checkout@v6
28+
- name: Set up Docker buildx
29+
uses: docker/setup-buildx-action@v4
30+
- name: Create .env file
31+
run: cp default.env .env
32+
- name: Set Lighthouse/Geth/Web3signer
33+
run: |
34+
source ./.github/helper.sh
35+
CORE_FILES=lighthouse.yml:geth.yml:web3signer.yml
36+
var=CORE_FILES
37+
set_value_in_env
38+
FEE_RECIPIENT=0xDccf8451070a86183eE70D330C4c43b686E9CF86
39+
var=FEE_RECIPIENT
40+
set_value_in_env
41+
WEB3SIGNER=true
42+
var=WEB3SIGNER
43+
set_value_in_env
44+
W3S_DOCKER_TAG=latest
45+
var=W3S_DOCKER_TAG
46+
set_value_in_env
47+
W3S_READ_ONLY=false
48+
var=W3S_READ_ONLY
49+
set_value_in_env
50+
- name: Start Lighthouse/Geth/Web3signer
51+
run: ./ethd up
52+
- name: Pause for 30 seconds
53+
run: sleep 30
54+
- name: Test Web3signer
55+
run: ./.github/check-service.sh web3signer
56+
- name: Test PostgreSQL
57+
run: ./.github/check-service.sh postgres
58+
- name: Test version
59+
run: ./ethd version
60+
- name: Set distroless
61+
run: |
62+
source ./.github/helper.sh
63+
W3S_DOCKER_TAG=latest-distroless
64+
var=W3S_DOCKER_TAG
65+
set_value_in_env
66+
W3S_READ_ONLY=true
67+
var=W3S_READ_ONLY
68+
set_value_in_env
69+
- name: Rebuild Web3signer image
70+
run: ./ethd cmd build --pull
71+
- name: Start Lighthouse/Geth/Web3signer
72+
run: ./ethd up
73+
- name: Pause for 30 seconds
74+
run: sleep 30
75+
- name: Test Web3signer
76+
run: ./.github/check-service.sh web3signer
77+
- name: Test PostgreSQL
78+
run: ./.github/check-service.sh postgres
79+
- name: Test version
80+
run: ./ethd version

default.env

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -404,8 +404,15 @@ VERO_DOCKER_REPO=ghcr.io/serenita-org/vero
404404
VERO_DOCKERFILE=Dockerfile.binary
405405

406406
# Web3Signer
407+
# SRC build target can be a tag, a branch, or a pr as "pr-ID"
408+
W3S_SRC_BUILD_TARGET=master
409+
W3S_SRC_REPO=https://github.com/Consensys/web3signer
410+
# Use latest-distroless or <vx.y>-distroless for a distroless setup
407411
W3S_DOCKER_TAG=latest
412+
# Set to "true" for distroless and read-only Docker
413+
W3S_READ_ONLY=false
408414
W3S_DOCKER_REPO=consensys/web3signer
415+
W3S_DOCKERFILE=Dockerfile.binary
409416
PG_DOCKER_TAG=18-trixie
410417

411418
# Besu
@@ -494,4 +501,4 @@ DOCKER_ROOT=/var/lib/docker
494501
DOCKER_SOCK=/var/run/docker.sock
495502

496503
# Used by ethd update - please do not adjust
497-
ENV_VERSION=55
504+
ENV_VERSION=56

ethd

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ set -Eeuo pipefail
55
__project_name="Eth Docker"
66
__app_name="Ethereum node"
77
__sample_service="consensus"
8-
__min_env_version=55
8+
__min_env_version=56
99
__docker_exe="docker"
1010
__old_docker=0
1111
__docker_sudo=""
@@ -1124,6 +1124,16 @@ __source_build() {
11241124
fi
11251125
;;
11261126
esac
1127+
case "${COMPOSE_FILE}" in
1128+
*web3signer.yml*)
1129+
var="W3S_DOCKERFILE"
1130+
__get_value_from_env "${var}" "${__env_file}" "__value"
1131+
# shellcheck disable=SC2154
1132+
if [[ "${__value}" = "Dockerfile.source" ]]; then
1133+
__docompose build --pull --no-cache web3signer
1134+
fi
1135+
;;
1136+
esac
11271137
case "${COMPOSE_FILE}" in
11281138
*mev-boost.yml*)
11291139
var="MEV_DOCKERFILE"
@@ -5816,6 +5826,7 @@ config() {
58165826

58175827
version() {
58185828
local var
5829+
local w3s_exec=""
58195830

58205831
grep "^This is" README.md
58215832
echo
@@ -5939,7 +5950,15 @@ version() {
59395950
# Web3signer version
59405951
case "${__value}" in
59415952
*web3signer.yml*)
5942-
__docompose exec web3signer /opt/web3signer/bin/web3signer --version
5953+
var=W3S_DOCKER_TAG
5954+
__get_value_from_env "${var}" "${__env_file}" "__value"
5955+
if [[ "$__value" =~ distroless ]]; then
5956+
w3s_exec="java -cp /opt/web3signer/lib/* tech.pegasys.web3signer.Web3SignerApp"
5957+
else
5958+
w3s_exec="/opt/web3signer/bin/web3signer"
5959+
fi
5960+
# shellcheck disable=SC2086
5961+
__docompose exec web3signer ${w3s_exec} --version
59435962
echo
59445963
__docompose exec postgres pg_config --version
59455964
echo

web3signer.yml

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ services:
1919
pull_policy: never
2020
volumes:
2121
- web3signer-slashing-data:/var/lib/postgres-data:ro
22+
- web3signer-keys:/var/lib/web3signer
2223
environment:
2324
- PG_DOCKER_TAG=${PG_DOCKER_TAG}
2425
- PG_ALIAS=${PG_ALIAS}
@@ -40,15 +41,18 @@ services:
4041
build:
4142
context: ./web3signer
4243
args:
44+
- BUILD_TARGET=${W3S_SRC_BUILD_TARGET:-$$(git describe --tags $$(git rev-list --tags --max-count=1))}
45+
- SRC_REPO=${W3S_SRC_REPO:-https://github.com/Consensys/web3signer}
4346
- DOCKER_TAG=${W3S_DOCKER_TAG:-latest}
4447
- DOCKER_REPO=${W3S_DOCKER_REPO:-consensys/web3signer}
45-
dockerfile: Dockerfile.binary
48+
dockerfile: ${W3S_DOCKERFILE}
4649
image: web3signer:local
4750
pull_policy: never
48-
user: web3signer
51+
user: 10000:10000
4952
volumes:
5053
- web3signer-keys:/var/lib/web3signer
5154
- /etc/localtime:/etc/localtime:ro
55+
read_only: ${W3S_READ_ONLY:-false}
5256
environment:
5357
- JAVA_OPTS=${W3S_HEAP:--Xmx6g}
5458
- NETWORK=${NETWORK}
@@ -62,15 +66,14 @@ services:
6266
w3s-init:
6367
condition: service_completed_successfully
6468
<<: *logging
65-
entrypoint:
66-
- docker-entrypoint.sh
67-
- /opt/web3signer/bin/web3signer
69+
command:
6870
- --key-store-path=/var/lib/web3signer/keys
6971
- --metrics-enabled
7072
- --metrics-host-allowlist=*
7173
- --http-host-allowlist=*
7274
- --logging=${LOG_LEVEL:-info}
7375
- eth2
76+
- --network=${NETWORK}
7477
- --enable-key-manager-api=true
7578
- --slashing-protection-db-url=jdbc:postgresql://${PG_ALIAS:-${NETWORK}-postgres}/web3signer
7679
- --slashing-protection-db-username=postgres

web3signer/Dockerfile.binary

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,6 @@
1-
# hadolint global ignore=DL3007,DL3008,DL3059
21
ARG DOCKER_TAG=latest
32
ARG DOCKER_REPO=consensys/web3signer
43

54
FROM ${DOCKER_REPO}:${DOCKER_TAG}
65

7-
ARG USER=web3signer
8-
ARG UID=10000
9-
10-
USER root
11-
12-
RUN groupmod -g "${UID}" ${USER} && usermod -u "${UID}" -g "${UID}" ${USER}
13-
14-
RUN set -eux; \
15-
apt-get update; \
16-
DEBIAN_FRONTEND=noninteractive TZ=Etc/UTC apt-get install -y --no-install-recommends gosu ca-certificates tzdata git git-lfs; \
17-
rm -rf /var/lib/apt/lists/*; \
18-
# verify that the binary works
19-
gosu nobody true
20-
21-
# Create data mount point with permissions
22-
RUN mkdir -p /var/lib/web3signer/keys && chown -R ${USER}:${USER} /var/lib/web3signer && chmod -R 700 /var/lib/web3signer
23-
# Cannot assume buildkit, hence no chmod
24-
COPY --chown=${USER}:${USER} ./docker-entrypoint.sh /usr/local/bin/
25-
# Belt and suspenders
26-
RUN chmod -R 755 /usr/local/bin/*
27-
28-
USER ${USER}
29-
30-
ENTRYPOINT ["/opt/web3signer/bin/web3signer"]
6+
USER 10000:10000

web3signer/Dockerfile.source

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
# hadolint global ignore=DL3007,DL3008,DL3059
2+
# Build Web3signer in a stock Ubuntu container
3+
FROM eclipse-temurin:25-jdk-noble AS builder
4+
5+
# This is here to avoid build-time complaints
6+
ARG DOCKER_TAG
7+
ARG DOCKER_REPO
8+
9+
RUN apt-get update && apt-get install -y --no-install-recommends ca-certificates git
10+
11+
ARG BUILD_TARGET
12+
ARG SRC_REPO
13+
14+
WORKDIR /usr/src
15+
16+
ARG SRC_DIR=web3signer
17+
RUN bash -eo pipefail <<'EOF'
18+
git clone "$SRC_REPO" "$SRC_DIR"
19+
cd "$SRC_DIR"
20+
git config advice.detachedHead false
21+
git fetch --all --tags
22+
CLEANED=$(echo "$BUILD_TARGET" | sed 's/\$\$(/$(/g')
23+
TARGET=$(eval echo "$CLEANED")
24+
echo "Build $TARGET from $SRC_REPO"
25+
if [[ "$TARGET" =~ ^pr-[1-9][0-9]*$ ]]; then
26+
git fetch origin pull/$(echo "$TARGET" | cut -d '-' -f 2)/head:build-pr
27+
git checkout build-pr
28+
else
29+
git checkout "$TARGET"
30+
fi
31+
git submodule update --init --recursive --jobs $(nproc)
32+
./gradlew installDist
33+
EOF
34+
35+
36+
# Pull all binaries into a second stage deploy Ubuntu container
37+
FROM eclipse-temurin:25-jre-noble
38+
39+
RUN apt-get update && DEBIAN_FRONTEND=noninteractive TZ=Etc/UTC apt-get install -y --no-install-recommends \
40+
ca-certificates \
41+
tzdata \
42+
gosu \
43+
libjemalloc-dev \
44+
git \
45+
git-lfs \
46+
wget \
47+
curl \
48+
adduser \
49+
&& gosu nobody true \
50+
&& apt-get clean \
51+
&& rm -rf /var/lib/apt/lists/*
52+
53+
ARG USER=web3signer
54+
ARG UID=10000
55+
56+
# See https://stackoverflow.com/a/55757473/12429735RUN
57+
RUN adduser \
58+
--disabled-password \
59+
--gecos "" \
60+
--home "/nonexistent" \
61+
--shell "/usr/sbin/nologin" \
62+
--no-create-home \
63+
--uid "${UID}" \
64+
"${USER}"
65+
66+
# Create data mount point with permissions
67+
RUN mkdir -p /var/lib/web3signer/keys && chown -R ${USER}:${USER} /var/lib/web3signer && chmod -R 700 /var/lib/web3signer
68+
69+
# Cannot assume buildkit, hence no chmod
70+
COPY --from=builder --chown=${USER}:${USER} /usr/src/web3signer/build/install/web3signer/. /opt/web3signer/
71+
COPY --chown=${USER}:${USER} ./docker-entrypoint.sh /usr/local/bin/
72+
# Belt and suspenders
73+
RUN chmod -R 755 /usr/local/bin/*
74+
75+
USER ${USER}
76+
77+
ENTRYPOINT ["docker-entrypoint.sh", "/opt/web3signer/bin/web3signer"]

web3signer/docker-entrypoint-flyway.sh

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
#!/bin/bash
22
set -Eeu
33

4+
# Permissions
5+
mkdir -p /var/lib/web3signer/keys && chown -R 10000:10000 /var/lib/web3signer
6+
47
# Configuration
58
db_url="postgresql://postgres:postgres@${PG_ALIAS}:5432/web3signer"
69
check_query="SELECT 1 FROM pg_database WHERE datname = current_database() AND datcollversion <> (SELECT collversion FROM pg_collation WHERE collname = 'en_US.utf8' LIMIT 1);"
@@ -49,4 +52,26 @@ if [[ -f "${data_dir}/PG_VERSION" ]]; then
4952
fi
5053
fi
5154

55+
if [[ -f /var/lib/web3signer/.migration_fatal_error ]]; then
56+
echo "An error occurred during \"ethd update\" and slashing protection database migration, that makes it unsafe to start Web3signer."
57+
echo "Until this is manually remedied, Web3signer will refuse to start up."
58+
echo "Aborting."
59+
echo
60+
echo "If this issue has since been resolved, you can remove the \".migration_fatal_error\" marker file in Web3signer's"
61+
echo "Docker volume."
62+
echo
63+
echo "ONLY remove the marker file if the issue has been resolved. You risk slashing otherwise."
64+
sleep 30
65+
exit 1
66+
fi
67+
68+
if [[ -f /var/lib/web3signer/.migration_error ]]; then
69+
echo "An error occurred during \"ethd update\", while switching to a new version of PostgreSQL."
70+
echo "Web3signer will start, but won't work until PostgreSQL's version matches the slashing protection database"
71+
echo "version."
72+
echo
73+
echo "If this issue has since been resolved, you can remove the \".migration_error\" marker file in Web3signer's"
74+
echo "Docker volume."
75+
fi
76+
5277
exec "$@"

0 commit comments

Comments
 (0)