Skip to content

Commit 52bb597

Browse files
committed
Support Web3signer distroless
1 parent fb928a4 commit 52bb597

8 files changed

Lines changed: 137 additions & 63 deletions
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
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+
COMPOSE_FILE=lighthouse.yml:geth.yml:web3signer.yml
36+
var=COMPOSE_FILE
37+
set_value_in_env
38+
WEB3SIGNER=true
39+
var=WEB3SIGNER
40+
set_value_in_env
41+
- name: Start Lighthouse/Geth/Web3signer
42+
run: ./ethd up
43+
- name: Pause for 30 seconds
44+
run: sleep 30
45+
- name: Test Web3signer
46+
run: ./.github/check-service.sh web3signer
47+
- name: Test PostgreSQL
48+
run: ./.github/check-service.sh postgres

default.env

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

406406
# Web3Signer
407+
# Use latest-distroless or <vx.y>-distroless for a distroless setup
407408
W3S_DOCKER_TAG=latest
409+
# Set to "true" for distroless and read-only Docker
410+
W3S_READ_ONLY=false
408411
W3S_DOCKER_REPO=consensys/web3signer
412+
# Use Dockerfile.custom-network for a custom devnet NETWORK. Doesn't support distroless.
413+
W3S_DOCKERFILE=Dockerfile.slim
409414
PG_DOCKER_TAG=18-trixie
410415

411416
# Besu
@@ -494,4 +499,4 @@ DOCKER_ROOT=/var/lib/docker
494499
DOCKER_SOCK=/var/run/docker.sock
495500

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

web3signer.yml

Lines changed: 6 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}
@@ -42,10 +43,10 @@ services:
4243
args:
4344
- DOCKER_TAG=${W3S_DOCKER_TAG:-latest}
4445
- DOCKER_REPO=${W3S_DOCKER_REPO:-consensys/web3signer}
45-
dockerfile: Dockerfile.binary
46+
dockerfile: ${W3S_DOCKERFILE}
4647
image: web3signer:local
4748
pull_policy: never
48-
user: web3signer
49+
user: 10000:10000
4950
volumes:
5051
- web3signer-keys:/var/lib/web3signer
5152
- /etc/localtime:/etc/localtime:ro
@@ -61,16 +62,16 @@ services:
6162
depends_on:
6263
w3s-init:
6364
condition: service_completed_successfully
65+
read_only: ${W3S_READ_ONLY:-false}
6466
<<: *logging
65-
entrypoint:
66-
- docker-entrypoint.sh
67-
- /opt/web3signer/bin/web3signer
67+
command:
6868
- --key-store-path=/var/lib/web3signer/keys
6969
- --metrics-enabled
7070
- --metrics-host-allowlist=*
7171
- --http-host-allowlist=*
7272
- --logging=${LOG_LEVEL:-info}
7373
- eth2
74+
- --network=${NETWORK}
7475
- --enable-key-manager-api=true
7576
- --slashing-protection-db-url=jdbc:postgresql://${PG_ALIAS:-${NETWORK}-postgres}/web3signer
7677
- --slashing-protection-db-username=postgres
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ RUN set -eux; \
2121
# Create data mount point with permissions
2222
RUN mkdir -p /var/lib/web3signer/keys && chown -R ${USER}:${USER} /var/lib/web3signer && chmod -R 700 /var/lib/web3signer
2323
# Cannot assume buildkit, hence no chmod
24-
COPY --chown=${USER}:${USER} ./docker-entrypoint.sh /usr/local/bin/
24+
COPY --chown=${USER}:${USER} ./docker-entrypoint-custom-network.sh /usr/local/bin/docker-entrypoint.sh
2525
# Belt and suspenders
2626
RUN chmod -R 755 /usr/local/bin/*
2727

2828
USER ${USER}
2929

30-
ENTRYPOINT ["/opt/web3signer/bin/web3signer"]
30+
ENTRYPOINT ["docker-entrypoint.sh", "/opt/web3signer/bin/web3signer"]

web3signer/Dockerfile.slim

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
ARG DOCKER_TAG=latest
2+
ARG DOCKER_REPO=consensys/web3signer
3+
4+
FROM ${DOCKER_REPO}:${DOCKER_TAG}
5+
6+
USER 10000:10000
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#!/usr/bin/env bash
2+
set -Eeuo pipefail
3+
4+
# Because we're oh-so-clever with custom NETWORK, we may need to remove what's already passed in.
5+
__strip_network_args() {
6+
local arg
7+
__args=()
8+
for arg in "$@"; do
9+
if [[ ! "${arg}" = "--network=${NETWORK}" ]]; then
10+
__args+=("${arg}")
11+
fi
12+
done
13+
}
14+
15+
16+
if [[ "${NETWORK}" =~ ^https?:// ]]; then
17+
echo "Custom testnet at ${NETWORK}"
18+
repo=$(awk -F'/tree/' '{print $1}' <<< "${NETWORK}")
19+
branch=$(awk -F'/tree/' '{print $2}' <<< "${NETWORK}" | cut -d'/' -f1)
20+
config_dir=$(awk -F'/tree/' '{print $2}' <<< "${NETWORK}" | cut -d'/' -f2-)
21+
echo "This appears to be the ${repo} repo, branch ${branch} and config directory ${config_dir}."
22+
# For want of something more amazing, let's just fail if git fails to pull this
23+
set -e
24+
if [[ ! -d "/var/lib/web3signer/testnet/${config_dir}" ]]; then
25+
mkdir -p /var/lib/web3signer/testnet
26+
cd /var/lib/web3signer/testnet
27+
git init --initial-branch="${branch}"
28+
git remote add origin "${repo}"
29+
git config core.sparseCheckout true
30+
echo "${config_dir}" > .git/info/sparse-checkout
31+
git pull origin "${branch}"
32+
fi
33+
set +e
34+
__network="--network=/var/lib/web3signer/testnet/${config_dir}/config.yaml"
35+
36+
__strip_network_args "$@"
37+
set -- "${__args[@]}"
38+
else
39+
__network=""
40+
fi
41+
42+
# Word splitting is desired for the command line parameters
43+
# shellcheck disable=SC2086
44+
exec "$@" ${__network}

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+
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 "$@"

web3signer/docker-entrypoint.sh

Lines changed: 0 additions & 55 deletions
This file was deleted.

0 commit comments

Comments
 (0)