Skip to content

Commit 37b367c

Browse files
authored
Add diag image for docker (#633)
* feat: add diag image for docker * fix: update dockerignore * fix: update trivy to not run in diag
1 parent 8a2a5b1 commit 37b367c

4 files changed

Lines changed: 167 additions & 7 deletions

File tree

.dockerignore

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,4 +145,10 @@ arbitrum-nitro-testnode/
145145
**/test-data/
146146
**/test-vectors/
147147
**/large-files/
148-
**/sample-data/
148+
**/sample-data/
149+
150+
# Re-include scripts needed for Docker builds (must be at end to override earlier exclusions)
151+
!scripts/
152+
!scripts/build/
153+
!scripts/build/*
154+
!scripts/diag-entrypoint.sh

.github/workflows/publish-docker.yml

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ on:
1414
description: Dockerfile
1515
required: true
1616
default: Dockerfile
17+
type: choice
18+
options: [Dockerfile, Dockerfile.diag]
1719
build-config:
1820
description: Build configuration
1921
required: true
@@ -46,9 +48,11 @@ jobs:
4648
with:
4749
runner: ${{ matrix.runner }}
4850
group_name: core
49-
image_name: ${{ github.event.inputs.image-name }}
50-
dockerfile_path: ${{ github.event.inputs.dockerfile }}
51+
image_name: ${{ inputs.image-name }}
52+
dockerfile_path: ${{ inputs.dockerfile }}
5153
platforms: ${{ matrix.platform }}
54+
# Skip Trivy for diagnostic image - JetBrains tools have transitive dependency CVEs we cannot fix
55+
run_trivy: ${{ inputs.dockerfile == 'Dockerfile' }}
5256
pre_build_script: |
5357
sudo rm -rf /usr/share/dotnet
5458
sudo rm -rf /opt/ghc
@@ -63,11 +67,11 @@ jobs:
6367
docker system prune -af --volumes
6468
df -h
6569
docker_build_args: |
66-
BUILD_CONFIG=${{ github.event.inputs.build-config }}
70+
BUILD_CONFIG=${{ inputs.build-config }}
6771
BUILD_TIMESTAMP=${{ github.run_number }}
6872
CI=true
6973
COMMIT_HASH=${{ github.sha }}
70-
additional_tags: ${{ github.event.inputs.tag }}${{ matrix.arch_suffix }}
74+
additional_tags: ${{ inputs.tag }}${{ matrix.arch_suffix }}
7175

7276
Create-Manifest:
7377
name: Create multi-arch manifest
@@ -90,9 +94,11 @@ jobs:
9094
password: ${{ steps.jfrog.outputs.oidc-token }}
9195

9296
- name: Create and push multi-arch manifest
97+
env:
98+
IMAGE_NAME: ${{ inputs.image-name }}
99+
TAG: ${{ inputs.tag }}
93100
run: |
94-
IMAGE_BASE="nethermind.jfrog.io/core-oci-local-dev/${{ github.event.inputs.image-name }}"
95-
TAG="${{ github.event.inputs.tag }}"
101+
IMAGE_BASE="nethermind.jfrog.io/core-oci-local-dev/${IMAGE_NAME}"
96102
97103
echo "🔍 Preparing multi-arch manifest creation..."
98104

Dockerfile.diag

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
# SPDX-FileCopyrightText: 2025 Demerzel Solutions Limited
2+
# SPDX-License-Identifier: LGPL-3.0-only
3+
4+
FROM --platform=$BUILDPLATFORM mcr.microsoft.com/dotnet/sdk:10.0.100-noble AS build
5+
6+
ARG BUILD_CONFIG=Release
7+
ARG BUILD_TIMESTAMP
8+
ARG CI
9+
ARG COMMIT_HASH
10+
ARG TARGETARCH
11+
12+
WORKDIR /src
13+
14+
# Copy source files
15+
COPY src/Nethermind src/Nethermind
16+
COPY src/Nethermind.Arbitrum src/Nethermind.Arbitrum
17+
COPY src/Directory.Build.props .
18+
COPY src/nuget.config .
19+
20+
# Resolve .NET RID architecture from Docker TARGETARCH
21+
RUN arch=$([ "$TARGETARCH" = "amd64" ] && echo "x64" || echo "$TARGETARCH") && \
22+
echo "$arch" > /tmp/dotnet-arch
23+
24+
# Install JetBrains dotMemory (architecture-specific)
25+
RUN arch=$(cat /tmp/dotnet-arch) && \
26+
dotnet add src/Nethermind/src/Nethermind/Nethermind.Runner/Nethermind.Runner.csproj \
27+
package JetBrains.dotMemory.Console.linux-$arch --package-directory /tmp/packages
28+
29+
# Build Arbitrum plugin
30+
RUN arch=$(cat /tmp/dotnet-arch) && \
31+
dotnet publish src/Nethermind.Arbitrum/Nethermind.Arbitrum.csproj -c $BUILD_CONFIG -a $arch -o /arbitrum-plugin --sc false \
32+
-p:BuildTimestamp=$BUILD_TIMESTAMP -p:Commit=$COMMIT_HASH -p:DeterministicSourcePaths=false
33+
34+
# Build main Nethermind Runner
35+
RUN arch=$(cat /tmp/dotnet-arch) && \
36+
dotnet publish src/Nethermind/src/Nethermind/Nethermind.Runner/Nethermind.Runner.csproj -c $BUILD_CONFIG -a $arch -o /publish --sc false \
37+
-p:BuildTimestamp=$BUILD_TIMESTAMP -p:Commit=$COMMIT_HASH -p:DeterministicSourcePaths=false
38+
39+
# Copy Arbitrum plugin to plugins directory
40+
RUN mkdir -p /publish/plugins && \
41+
cp /arbitrum-plugin/Nethermind.Arbitrum.* /publish/plugins/
42+
43+
# Copy Stylus native libraries to maintain relative structure from plugin assembly
44+
RUN mkdir -p /publish/plugins/Arbos/Stylus && \
45+
cp -r /arbitrum-plugin/Arbos/Stylus/runtimes /publish/plugins/Arbos/Stylus/ && \
46+
echo "Stylus libraries copied:" && \
47+
find /publish/plugins/Arbos/Stylus -name "*.so" -o -name "*.dylib" -o -name "*.dll" | sort
48+
49+
# Copy configuration files
50+
COPY src/Nethermind.Arbitrum/Properties/configs /publish/configs
51+
COPY src/Nethermind.Arbitrum/Properties/chainspec /publish/chainspec
52+
53+
# Create data directory
54+
RUN mkdir -p /publish/data
55+
56+
# Install diagnostic tools
57+
RUN dotnet tool install -g dotnet-dump && \
58+
dotnet tool install -g dotnet-gcdump && \
59+
dotnet tool install -g dotnet-trace && \
60+
dotnet tool install -g JetBrains.dotTrace.GlobalTools
61+
62+
FROM mcr.microsoft.com/dotnet/aspnet:10.0.0-noble
63+
64+
# Fix CVE-2025-68973 - Update gpgv package
65+
RUN apt-get update && \
66+
apt-get install -y --no-install-recommends gpgv=2.4.4-2ubuntu17.4 && \
67+
apt-get clean && \
68+
rm -rf /var/lib/apt/lists/*
69+
70+
WORKDIR /nethermind
71+
72+
VOLUME /nethermind/diag
73+
VOLUME /nethermind/keystore
74+
VOLUME /nethermind/logs
75+
VOLUME /nethermind/nethermind_db
76+
77+
# Expose ports for JSON-RPC, Engine API, and metrics
78+
EXPOSE 8545 8551 6060
79+
80+
# Copy application from build stage
81+
COPY --from=build /publish .
82+
83+
# Copy diagnostic tools
84+
COPY --from=build /root/.dotnet/tools /opt/diag-tools
85+
COPY --from=build /tmp/packages/jetbrains.dotmemory.console.*/**/tools /opt/diag-tools/dotmemory
86+
87+
# Copy diagnostic entrypoint script
88+
COPY --chmod=0755 scripts/diag-entrypoint.sh entrypoint.sh
89+
90+
ENV PATH="$PATH:/opt/diag-tools:/opt/diag-tools/dotmemory"
91+
92+
STOPSIGNAL SIGINT
93+
94+
ENTRYPOINT ["./entrypoint.sh"]

scripts/diag-entrypoint.sh

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
#!/bin/bash
2+
# SPDX-FileCopyrightText: 2025 Demerzel Solutions Limited
3+
# SPDX-License-Identifier: LGPL-3.0-only
4+
5+
set -eo pipefail
6+
7+
start_dotmemory() {
8+
echo "Starting dotMemory..."
9+
10+
exec dotmemory start \
11+
--save-to-dir=/nethermind/diag/dotmemory \
12+
--service-output \
13+
./nethermind -- "$@"
14+
}
15+
16+
start_dotnet_trace() {
17+
echo "Starting dotnet-trace..."
18+
19+
exec dotnet-trace collect \
20+
-o /nethermind/diag/dotnet.nettrace \
21+
--show-child-io \
22+
-- ./nethermind "$@"
23+
}
24+
25+
start_dottrace() {
26+
echo "Starting dotTrace..."
27+
28+
exec dottrace start \
29+
--framework=netcore \
30+
--profiling-type=timeline \
31+
--propagate-exit-code \
32+
--save-to=/nethermind/diag/dottrace \
33+
--service-output=on \
34+
-- ./nethermind "$@"
35+
}
36+
37+
case "$DIAG_WITH" in
38+
"")
39+
exec ./nethermind "$@"
40+
;;
41+
dotmemory)
42+
start_dotmemory "$@"
43+
;;
44+
dotnet-trace)
45+
start_dotnet_trace "$@"
46+
;;
47+
dottrace)
48+
start_dottrace "$@"
49+
;;
50+
*)
51+
printf '\e[31mUnknown DIAG_WITH value: %q\e[0m\n' "$DIAG_WITH" >&2
52+
exit 2
53+
;;
54+
esac

0 commit comments

Comments
 (0)