feat(build): docker image with delve debugger support

This commit is contained in:
Fabio Bozzo 2024-08-30 17:50:50 +02:00
parent ab3ee99ca9
commit dea013ade0
2 changed files with 19 additions and 3 deletions

View file

@ -8,6 +8,9 @@ FROM golang:1.23-alpine as builder
RUN apk add --no-cache gcc musl-dev linux-headers git
# Install Delve debugger
RUN go install github.com/go-delve/delve/cmd/dlv@latest
# Get dependencies - will also be cached if we won't change go.mod/go.sum
COPY go.mod /go-ethereum/
COPY go.sum /go-ethereum/
@ -22,7 +25,10 @@ FROM alpine:latest
RUN apk add --no-cache ca-certificates
COPY --from=builder /go-ethereum/build/bin/* /usr/local/bin/
EXPOSE 8545 8546 30303 30303/udp
# Copy Delve debugger executable to current stage
COPY --from=builder /go/bin/dlv /
EXPOSE 4000 8545 8546 30303 30303/udp
# Add some metadata labels to help programmatic image consumption
ARG COMMIT=""

View file

@ -55,6 +55,7 @@ import (
"time"
"github.com/cespare/cp"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/crypto/signify"
"github.com/ethereum/go-ethereum/internal/build"
@ -728,6 +729,7 @@ func doDocker(cmdline []string) {
image = flag.Bool("image", false, `Whether to build and push an arch specific docker image`)
manifest = flag.String("manifest", "", `Push a multi-arch docker image for the specified architectures (usually "amd64,arm64")`)
upload = flag.String("upload", "", `Where to upload the docker image (usually "ethereum/client-go")`)
debug = flag.Bool("debug", false, `Build a complementary image with Delve debugger support`)
)
flag.CommandLine.Parse(cmdline)
@ -763,8 +765,16 @@ func doDocker(cmdline []string) {
}
// If architecture specific image builds are requested, build and push them
if *image {
build.MustRunCommand("docker", "build", "--build-arg", "COMMIT="+env.Commit, "--build-arg", "VERSION="+params.VersionWithMeta, "--build-arg", "BUILDNUM="+env.Buildnum, "--tag", fmt.Sprintf("%s:TAG", *upload), ".")
build.MustRunCommand("docker", "build", "--build-arg", "COMMIT="+env.Commit, "--build-arg", "VERSION="+params.VersionWithMeta, "--build-arg", "BUILDNUM="+env.Buildnum, "--tag", fmt.Sprintf("%s:alltools-TAG", *upload), "-f", "Dockerfile.alltools", ".")
buildArgsSet := [][]string{
{"build", "--build-arg", "COMMIT=" + env.Commit, "--build-arg", "VERSION=" + params.VersionWithMeta, "--build-arg", "BUILDNUM=" + env.Buildnum, "--tag", fmt.Sprintf("%s:TAG", *upload), "."},
{"build", "--build-arg", "COMMIT=" + env.Commit, "--build-arg", "VERSION=" + params.VersionWithMeta, "--build-arg", "BUILDNUM=" + env.Buildnum, "--tag", fmt.Sprintf("%s:alltools-TAG", *upload), "-f", "Dockerfile.alltools", "."},
}
if *debug {
buildArgsSet = append(buildArgsSet, []string{"buildx", "build", "--build-arg", "COMMIT=" + env.Commit, "--build-arg", "VERSION=" + params.VersionWithMeta, "--build-arg", "BUILDNUM=" + env.Buildnum, "--build-arg", "GOFLAGS=-gcflags=all=-N -gcflags=all=-l", "--tag", fmt.Sprintf("%s:debug-TAG", *upload), "-f", "Dockerfile.alltools", "."})
}
for _, buildArgs := range buildArgsSet {
build.MustRunCommand("docker", buildArgs...)
}
// Tag and upload the images to Docker Hub
for _, tag := range tags {