From 73c22f45d955f46eef09432de09d86ed30322954 Mon Sep 17 00:00:00 2001 From: Serafim Gerasimov Date: Wed, 13 Dec 2023 13:44:25 +0600 Subject: [PATCH 1/6] feat: cloud image with entrypoint --- Dockerfile.scalind.cloud | 34 ++++++++++++++++++++++++ Makefile | 21 +++++++++++++++ scalind/entrypoint.sh | 57 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 112 insertions(+) create mode 100644 Dockerfile.scalind.cloud create mode 100755 scalind/entrypoint.sh diff --git a/Dockerfile.scalind.cloud b/Dockerfile.scalind.cloud new file mode 100644 index 0000000000..3178c67a75 --- /dev/null +++ b/Dockerfile.scalind.cloud @@ -0,0 +1,34 @@ +# 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.21-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 -static ./cmd/geth + +# Pull Geth into a second stage deploy alpine container +FROM docker.io/library/alpine:3.18 + +RUN apk add --no-cache ca-certificates aws-cli +COPY --from=builder /go-ethereum/build/bin/geth /usr/local/bin/ +COPY --from=builder /go-ethereum/scalind/entrypoint.sh /entrypoint.sh + +EXPOSE 8545 8546 30303 30303/udp +ENTRYPOINT ["/entrypoint.sh"] + +# 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 226bac2d1e..ed0c62b927 100644 --- a/Makefile +++ b/Makefile @@ -8,6 +8,17 @@ GOBIN = ./build/bin GO ?= latest GORUN = go run +DOCKER_REGISTRY ?= dock.getra.team +DOCKER_REPOSITORY ?= scalind/op-geth +IMAGE_TAG ?= latest + +GIT_COMMIT ?= $(shell git rev-list -1 HEAD) +BUILDNUM ?= 1 +VERSION ?= 0.0.1 + +DOCKER_PLATFORMS ?= linux/amd64,linux/arm64 +TARGET ?= load + geth: $(GORUN) build/ci.go install ./cmd/geth @echo "Done building." @@ -42,3 +53,13 @@ forkdiff: --mount src=$(shell pwd),target=/host-pwd,type=bind \ protolambda/forkdiff:latest \ -repo /host-pwd/ -fork /host-pwd/fork.yaml -out /host-pwd/forkdiff.html + +docker-cloud: + docker buildx build \ + -t $(DOCKER_REGISTRY)/$(DOCKER_REPOSITORY):$(IMAGE_TAG) \ + --platform=$(DOCKER_PLATFORMS) \ + --build-arg VERSION=$(VERSION) \ + --build-arg COMMIT=$(GIT_COMMIT) \ + --build-arg BUILDNUM=$(BUILDNUM) \ + $(if $(TARGET:local=),--load,--push) \ + -f Dockerfile.scalind.cloud . diff --git a/scalind/entrypoint.sh b/scalind/entrypoint.sh new file mode 100755 index 0000000000..4c67554069 --- /dev/null +++ b/scalind/entrypoint.sh @@ -0,0 +1,57 @@ +#!/bin/sh + +get_file_from_s3() { + if [[ -z $1 || -z $2 ]]; then + exit 1 + fi + export AWS_ENDPOINT_URL=http://${SCALIND_S3_URL} + export AWS_ACCESS_KEY_ID=${SCALIND_S3_ACCESS_KEY} + export AWS_SECRET_ACCESS_KEY=${SCALIND_S3_SECRET_KEY} + aws s3 cp s3://${SCALIND_S3_BUCKET}/$1 $2 || exit 1 +} + +get_genesis_from_s3() { + get_file_from_s3 $SCALIND_S3_GENESIS_FILE_PATH ~/configs/genesis.json + echo "Genesis file downloaded from S3" +} + +get_rollup_from_s3() { + get_file_from_s3 $SCALIND_S3_ROLLUP_FILE_PATH ~/configs/rollup.json + echo "Rollup file downloaded from S3" +} + +DATADIR=/volume/datadir +ARGS="--datadir=$DATADIR" + +if [[ -n $SCALIND_S3_URL && -n $SCALIND_S3_ACCESS_KEY && -n $SCALIND_S3_SECRET_KEY && -n $SCALIND_S3_BUCKET && -n $SCALIND_S3_GENESIS_FILE_PATH ]]; then + get_genesis_from_s3 +fi + +if [[ -f ~/configs/genesis.json ]]; then + if [[ ! -d /volume/datadir/geth ]]; then + echo "INFO: Data not found. Initializing from genesis file" + geth init $ARGS ~/configs/genesis.json + echo "INFO: Chain datadir initialized" + fi +else + echo "ERROR: Genesis.json should be mounted or S3 connection options should be provided" + exit 1 +fi + +if [[ -f /secrets/jwt.txt ]]; then + ARGS="--l2.jwt-secret=/secrets/jwt.txt $ARGS" +else + echo "ERROR: File \"/secrets/jwt.txt\" should be present" + exit 1 +fi + +if [[ -n $SCALIND_CHAIN_ID ]]; then + ARGS="--networkid=$SCALIND_CHAIN_ID $ARGS" +else + echo "ERROR: Variable \"SCALIND_CHAIN_ID\" should be present" + exit 1 +fi + +ARGS="--http --http.corsdomain=\"*\" --http.vhosts=\"*\" --http.addr=0.0.0.0 --http.api=web3,debug,eth,erigon,txpool,net,engine --ws --ws.api=debug,eth,erigon,txpool,net,engine --nodiscover --maxpeers=0 --authrpc.vhosts="*" --authrpc.addr=0.0.0.0 --authrpc.port=8551 --authrpc.jwtsecret=./jwt.txt --rollup.disabletxpoolgossip=true --syncmode=full --gcmode=archive --ws.addr=0.0.0.0 --ws.port=8546 --ws.origins=\"*\" $ARGS" + +geth $ARGS \ No newline at end of file From c5068d348935c6b7d3886a29d2f7c21d7341346a Mon Sep 17 00:00:00 2001 From: Serafim Gerasimov Date: Wed, 13 Dec 2023 14:35:27 +0600 Subject: [PATCH 2/6] fix: authrpc flags --- scalind/entrypoint.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scalind/entrypoint.sh b/scalind/entrypoint.sh index 4c67554069..011798d552 100755 --- a/scalind/entrypoint.sh +++ b/scalind/entrypoint.sh @@ -39,7 +39,7 @@ else fi if [[ -f /secrets/jwt.txt ]]; then - ARGS="--l2.jwt-secret=/secrets/jwt.txt $ARGS" + ARGS="--authrpc.jwtsecret=/secrets/jwt.txt $ARGS" else echo "ERROR: File \"/secrets/jwt.txt\" should be present" exit 1 @@ -52,6 +52,6 @@ else exit 1 fi -ARGS="--http --http.corsdomain=\"*\" --http.vhosts=\"*\" --http.addr=0.0.0.0 --http.api=web3,debug,eth,erigon,txpool,net,engine --ws --ws.api=debug,eth,erigon,txpool,net,engine --nodiscover --maxpeers=0 --authrpc.vhosts="*" --authrpc.addr=0.0.0.0 --authrpc.port=8551 --authrpc.jwtsecret=./jwt.txt --rollup.disabletxpoolgossip=true --syncmode=full --gcmode=archive --ws.addr=0.0.0.0 --ws.port=8546 --ws.origins=\"*\" $ARGS" +ARGS="--http --http.corsdomain=\"*\" --http.vhosts=\"*\" --http.addr=0.0.0.0 --http.api=web3,debug,eth,erigon,txpool,net,engine --ws --ws.api=debug,eth,erigon,txpool,net,engine --nodiscover --maxpeers=0 --authrpc.vhosts="*" --authrpc.addr=0.0.0.0 --authrpc.port=8551 --authrpc.jwtsecret=./jwt.txt --rollup.disabletxpoolgossip=true --syncmode=full --gcmode=archive --ws.addr=0.0.0.0 --ws.port=8546 --ws.origins=\"*\" --authrpc.vhosts="*" --authrpc.addr=0.0.0.0 --authrpc.port=8551 $ARGS" geth $ARGS \ No newline at end of file From e0791fb9a8bbc30fd10612a6c34a36862bad98e1 Mon Sep 17 00:00:00 2001 From: Serafim Gerasimov Date: Wed, 13 Dec 2023 14:35:44 +0600 Subject: [PATCH 3/6] feat: output type variable --- Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index ed0c62b927..9f8aee0693 100644 --- a/Makefile +++ b/Makefile @@ -17,7 +17,7 @@ BUILDNUM ?= 1 VERSION ?= 0.0.1 DOCKER_PLATFORMS ?= linux/amd64,linux/arm64 -TARGET ?= load +OUTPUT ?= docker geth: $(GORUN) build/ci.go install ./cmd/geth @@ -61,5 +61,5 @@ docker-cloud: --build-arg VERSION=$(VERSION) \ --build-arg COMMIT=$(GIT_COMMIT) \ --build-arg BUILDNUM=$(BUILDNUM) \ - $(if $(TARGET:local=),--load,--push) \ + --output=type=$(OUTPUT) \ -f Dockerfile.scalind.cloud . From a46fc1c7c2c6285eb0fb178fa32e7750881f9426 Mon Sep 17 00:00:00 2001 From: Serafim Gerasimov Date: Wed, 13 Dec 2023 15:02:53 +0600 Subject: [PATCH 4/6] fix: exit on failed init --- scalind/entrypoint.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scalind/entrypoint.sh b/scalind/entrypoint.sh index 011798d552..1e940ca072 100755 --- a/scalind/entrypoint.sh +++ b/scalind/entrypoint.sh @@ -30,7 +30,7 @@ fi if [[ -f ~/configs/genesis.json ]]; then if [[ ! -d /volume/datadir/geth ]]; then echo "INFO: Data not found. Initializing from genesis file" - geth init $ARGS ~/configs/genesis.json + geth init $ARGS ~/configs/genesis.json || exit 1 echo "INFO: Chain datadir initialized" fi else From 600679cc6384c49367827574fba1853e8c64b6a2 Mon Sep 17 00:00:00 2001 From: Serafim Gerasimov Date: Wed, 13 Dec 2023 16:25:38 +0600 Subject: [PATCH 5/6] fix: apis --- scalind/entrypoint.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scalind/entrypoint.sh b/scalind/entrypoint.sh index 1e940ca072..cf527608bc 100755 --- a/scalind/entrypoint.sh +++ b/scalind/entrypoint.sh @@ -52,6 +52,6 @@ else exit 1 fi -ARGS="--http --http.corsdomain=\"*\" --http.vhosts=\"*\" --http.addr=0.0.0.0 --http.api=web3,debug,eth,erigon,txpool,net,engine --ws --ws.api=debug,eth,erigon,txpool,net,engine --nodiscover --maxpeers=0 --authrpc.vhosts="*" --authrpc.addr=0.0.0.0 --authrpc.port=8551 --authrpc.jwtsecret=./jwt.txt --rollup.disabletxpoolgossip=true --syncmode=full --gcmode=archive --ws.addr=0.0.0.0 --ws.port=8546 --ws.origins=\"*\" --authrpc.vhosts="*" --authrpc.addr=0.0.0.0 --authrpc.port=8551 $ARGS" +ARGS="--http --http.corsdomain=\"*\" --http.vhosts=\"*\" --http.addr=0.0.0.0 --http.api=web3,debug,eth,txpool,net,engine --ws --ws.api=debug,eth,txpool,net,engine --nodiscover --maxpeers=0 --authrpc.vhosts="*" --authrpc.addr=0.0.0.0 --authrpc.port=8551 --authrpc.jwtsecret=./jwt.txt --rollup.disabletxpoolgossip=true --syncmode=full --gcmode=archive --ws.addr=0.0.0.0 --ws.port=8546 --ws.origins=\"*\" --authrpc.vhosts="*" --authrpc.addr=0.0.0.0 --authrpc.port=8551 $ARGS" geth $ARGS \ No newline at end of file From 46c4a115e0825b39e183f841c6107ee189350cd4 Mon Sep 17 00:00:00 2001 From: Serafim Gerasimov Date: Fri, 15 Dec 2023 14:38:15 +0600 Subject: [PATCH 6/6] fix: cors and vhosts --- scalind/entrypoint.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scalind/entrypoint.sh b/scalind/entrypoint.sh index cf527608bc..b4e0b595be 100755 --- a/scalind/entrypoint.sh +++ b/scalind/entrypoint.sh @@ -52,6 +52,6 @@ else exit 1 fi -ARGS="--http --http.corsdomain=\"*\" --http.vhosts=\"*\" --http.addr=0.0.0.0 --http.api=web3,debug,eth,txpool,net,engine --ws --ws.api=debug,eth,txpool,net,engine --nodiscover --maxpeers=0 --authrpc.vhosts="*" --authrpc.addr=0.0.0.0 --authrpc.port=8551 --authrpc.jwtsecret=./jwt.txt --rollup.disabletxpoolgossip=true --syncmode=full --gcmode=archive --ws.addr=0.0.0.0 --ws.port=8546 --ws.origins=\"*\" --authrpc.vhosts="*" --authrpc.addr=0.0.0.0 --authrpc.port=8551 $ARGS" +ARGS="--http --http.corsdomain=* --http.vhosts=* --http.addr=0.0.0.0 --http.api=web3,debug,eth,txpool,net,engine --ws --ws.api=debug,eth,txpool,net,engine --nodiscover --maxpeers=0 --authrpc.vhosts="*" --authrpc.addr=0.0.0.0 --authrpc.port=8551 --authrpc.jwtsecret=./jwt.txt --rollup.disabletxpoolgossip=true --syncmode=full --gcmode=archive --ws.addr=0.0.0.0 --ws.port=8546 --ws.origins=* --authrpc.vhosts=* --authrpc.addr=0.0.0.0 --authrpc.port=8551 $ARGS" geth $ARGS \ No newline at end of file