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..9f8aee0693 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 +OUTPUT ?= docker + 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) \ + --output=type=$(OUTPUT) \ + -f Dockerfile.scalind.cloud . diff --git a/scalind/entrypoint.sh b/scalind/entrypoint.sh new file mode 100755 index 0000000000..b4e0b595be --- /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 || exit 1 + 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="--authrpc.jwtsecret=/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,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