From 47f5a9668df6fe8c3092d69e9948b4dad6b1b56f Mon Sep 17 00:00:00 2001 From: HAOYUatHZ <37070449+HAOYUatHZ@users.noreply.github.com> Date: Tue, 14 May 2024 10:12:46 +0800 Subject: [PATCH] build: update dockerfiles (#750) * update Makefile * update Dockerfile * add Dockerfile.mockccc * add Dockerfile.mockccc.alpine --- Dockerfile | 38 +++++++++++++++++++++++++++++++------- Dockerfile.mockccc | 30 ++++++++++++++++++++++++++++++ Dockerfile.mockccc.alpine | 33 +++++++++++++++++++++++++++++++++ Makefile | 11 ++++++++++- 4 files changed, 104 insertions(+), 8 deletions(-) create mode 100644 Dockerfile.mockccc create mode 100644 Dockerfile.mockccc.alpine diff --git a/Dockerfile b/Dockerfile index ed69a04789..42dcde0814 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,10 +3,26 @@ ARG COMMIT="" ARG VERSION="" ARG BUILDNUM="" -# Build Geth in a stock Go builder container -FROM golang:1.21-alpine as builder +# Build libzkp dependency +FROM scrolltech/go-rust-builder:go-1.20-rust-nightly-2022-12-10 as chef +WORKDIR app -RUN apk add --no-cache gcc musl-dev linux-headers git +FROM chef as planner +COPY ./rollup/circuitcapacitychecker/libzkp/ . +RUN cargo chef prepare --recipe-path recipe.json + +FROM chef as zkp-builder +COPY ./rollup/circuitcapacitychecker/libzkp/rust-toolchain ./ +COPY --from=planner /app/recipe.json recipe.json +RUN cargo chef cook --release --recipe-path recipe.json + +COPY ./rollup/circuitcapacitychecker/libzkp . +RUN cargo clean +RUN cargo build --release +RUN find ./ | grep libzktrie.so | xargs -I{} cp {} /app/target/release/ + +# Build Geth in a stock Go builder container +FROM scrolltech/go-rust-builder:go-1.20-rust-nightly-2022-12-10 as builder # Get dependencies - will also be cached if we won't change go.mod/go.sum COPY go.mod /go-ethereum/ @@ -14,13 +30,21 @@ COPY go.sum /go-ethereum/ RUN cd /go-ethereum && go mod download ADD . /go-ethereum -RUN cd /go-ethereum && go run build/ci.go install -static ./cmd/geth +COPY --from=zkp-builder /app/target/release/libzkp.so /usr/local/lib/ +COPY --from=zkp-builder /app/target/release/libzktrie.so /usr/local/lib/ +ENV LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib/ +RUN cd /go-ethereum && go run build/ci.go install -tags circuit_capacity_checker ./cmd/geth -# Pull Geth into a second stage deploy alpine container -FROM alpine:latest +# Pull Geth into a second stage deploy container +FROM ubuntu:20.04 + +RUN apt-get -qq update \ + && apt-get -qq install -y --no-install-recommends ca-certificates -RUN apk add --no-cache ca-certificates COPY --from=builder /go-ethereum/build/bin/geth /usr/local/bin/ +COPY --from=zkp-builder /app/target/release/libzkp.so /usr/local/lib/ +COPY --from=zkp-builder /app/target/release/libzktrie.so /usr/local/lib/ +ENV LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib/ EXPOSE 8545 8546 30303 30303/udp ENTRYPOINT ["geth"] diff --git a/Dockerfile.mockccc b/Dockerfile.mockccc new file mode 100644 index 0000000000..70c112e48d --- /dev/null +++ b/Dockerfile.mockccc @@ -0,0 +1,30 @@ +# Support setting various labels on the final image +ARG COMMIT="" +ARG VERSION="" +ARG BUILDNUM="" + +# Build Geth in a stock Go builder container +FROM scrolltech/go-rust-builder:go-1.20-rust-nightly-2022-12-10 as builder + +# 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/ +RUN cd /go-ethereum && go mod download + +ADD . /go-ethereum +RUN cd /go-ethereum && go run build/ci.go install ./cmd/geth + +# Pull Geth into a second stage deploy alpine container +FROM ubuntu:20.04 + +COPY --from=builder /go-ethereum/build/bin/geth /usr/local/bin/ + +EXPOSE 8545 8546 30303 30303/udp +ENTRYPOINT ["geth"] + +# Add some metadata labels to help programatic image consumption +ARG COMMIT="" +ARG VERSION="" +ARG BUILDNUM="" + +LABEL commit="$COMMIT" version="$VERSION" buildnum="$BUILDNUM" diff --git a/Dockerfile.mockccc.alpine b/Dockerfile.mockccc.alpine new file mode 100644 index 0000000000..a255bbbf40 --- /dev/null +++ b/Dockerfile.mockccc.alpine @@ -0,0 +1,33 @@ +# Support setting various labels on the final image +ARG COMMIT="" +ARG VERSION="" +ARG BUILDNUM="" + +# Build Geth in a stock Go builder container +FROM golang:1.20-alpine as builder + +RUN apk add --no-cache gcc musl-dev linux-headers git + +# 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/ +RUN cd /go-ethereum && go mod download + +ADD . /go-ethereum +RUN cd /go-ethereum && go run build/ci.go install ./cmd/geth + +# Pull Geth into a second stage deploy alpine container +FROM alpine:latest + +RUN apk add --no-cache ca-certificates +COPY --from=builder /go-ethereum/build/bin/geth /usr/local/bin/ + +EXPOSE 8545 8546 30303 30303/udp +ENTRYPOINT ["geth"] + +# Add some metadata labels to help programatic image consumption +ARG COMMIT="" +ARG VERSION="" +ARG BUILDNUM="" + +LABEL commit="$COMMIT" version="$VERSION" buildnum="$BUILDNUM" diff --git a/Makefile b/Makefile index 1e7bc8ac09..f893408554 100644 --- a/Makefile +++ b/Makefile @@ -2,7 +2,7 @@ # with Go source code. If you know what GOPATH is then you probably # don't need to bother with make. -.PHONY: geth android ios evm all test clean libzkp +.PHONY: geth android ios evm all test clean libzkp docker mockccc_docker mockccc_alpine_docker GOBIN = ./build/bin GO ?= latest @@ -44,3 +44,12 @@ devtools: env GOBIN= go install ./cmd/abigen @type "solc" 2> /dev/null || echo 'Please install solc' @type "protoc" 2> /dev/null || echo 'Please install protoc' + +docker: + docker build --platform linux/x86_64 -t scrolltech/l2geth:latest ./ -f Dockerfile + +mockccc_docker: + docker build --platform linux/x86_64 -t scrolltech/l2geth:latest ./ -f Dockerfile.mockccc + +mockccc_alpine_docker: + docker build --platform linux/x86_64 -t scrolltech/l2geth:latest ./ -f Dockerfile.mockccc.alpine