From 1d3821e2354dbecc05cb04b62cf3ce6c11ba1be6 Mon Sep 17 00:00:00 2001 From: Carlos Santiago Yanzon <27785807+bizk@users.noreply.github.com> Date: Wed, 10 Jan 2024 13:04:57 -0300 Subject: [PATCH] feat: coinbase accurate dockerfile (#70) * docker image init * dockerfile with rosetta working * added health check instead of sleep command --- .go-version | 1 + Dockerfile | 52 +++++++++++++++++++++++++++++++++---------- Makefile | 5 +++-- scripts/entrypoint.sh | 5 +++++ 4 files changed, 49 insertions(+), 14 deletions(-) create mode 100644 .go-version create mode 100644 scripts/entrypoint.sh diff --git a/.go-version b/.go-version new file mode 100644 index 0000000..8909929 --- /dev/null +++ b/.go-version @@ -0,0 +1 @@ +1.20.7 diff --git a/Dockerfile b/Dockerfile index 7850725..c347f1c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,22 +1,50 @@ -FROM golang:1.20 AS build-env +# ------------------------------------------------------------------------------ +# Build gaia +# ------------------------------------------------------------------------------ +FROM golang:1.20 AS cosmos -# Set working directory for the build -WORKDIR /go/src/github.com/cosmos/rosetta +ARG COSMOS_VERSION + +RUN git clone https://github.com/cosmos/cosmos-sdk \ + /go/src/github.com/cosmos/cosmos-sdk + +WORKDIR /go/src/github.com/cosmos/cosmos-sdk + +RUN git checkout v0.50.2 && make build +RUN export SIMD_BIN=/go/src/github.com/cosmos/cosmos-sdk/build/simd && make init-simapp + +# ------------------------------------------------------------------------------ +# Build rosetta +# ------------------------------------------------------------------------------ +FROM golang:1.21.5 AS rosetta -# optimization: if go.sum didn't change, docker will use cached image -COPY go.mod go.sum ./ +ARG ROSETTA_VERSION -RUN go mod download +RUN git clone https://github.com/cosmos/rosetta.git \ + /go/src/github.com/cosmos/rosetta -# Add source files -COPY . . +WORKDIR /go/src/github.com/cosmos/rosetta + +RUN git checkout $ROSETTA_VERSION && \ + go mod download RUN make build -RUN make plugin +RUN cd plugins/cosmos-hub && make plugin + +COPY --from=cosmos \ + /go/src/github.com/cosmos/cosmos-sdk/build/simd \ + /app/simd + +COPY --from=cosmos \ + /root/.simapp \ + /root/.simapp + +ADD scripts/entrypoint.sh /scripts/entrypoint.sh +RUN chmod +x /scripts/entrypoint.sh +EXPOSE 9650 +EXPOSE 9651 EXPOSE 8080 -# Run simd by default -CMD ["./rosetta", "--blockchain", "app", "--network", "network", "--tendermint", "cosmos:26657", "--grpc", "cosmos:9090", "--addr", ":8080"] -ENTRYPOINT ["./rosetta"] +ENTRYPOINT ["sh","/scripts/entrypoint.sh"] STOPSIGNAL SIGTERM \ No newline at end of file diff --git a/Makefile b/Makefile index bf1c812..f432ff4 100644 --- a/Makefile +++ b/Makefile @@ -2,10 +2,11 @@ all: build -rosetta: +build: + cd plugins/cosmos-hub && make plugin go build -mod=readonly ./cmd/rosetta -build: +rosetta: go build -mod=readonly ./cmd/rosetta plugin: diff --git a/scripts/entrypoint.sh b/scripts/entrypoint.sh new file mode 100644 index 0000000..83a3fee --- /dev/null +++ b/scripts/entrypoint.sh @@ -0,0 +1,5 @@ +/app/simd start & +until curl --output /dev/null --silent --head --fail http://localhost:26657/health; do + sleep 1 +done +./rosetta --blockchain "cosmos" --network "cosmos" --tendermint "tcp://localhost:26657" --addr "localhost:8080" --grpc "localhost:9090" \ No newline at end of file