diff --git a/CHANGELOG.md b/CHANGELOG.md index 882aeac1432..c4daf2eb52e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -137,6 +137,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ * By default store has a no op metric gatherer, the application developer must set another metric gatherer or us the provided one in `store/metrics`. * [#14406](https://github.com/cosmos/cosmos-sdk/issues/14406) Migrate usage of types/store.go to store/types/.. * (x/staking) [#14590](https://github.com/cosmos/cosmos-sdk/pull/14590) Return undelegate amount in MsgUndelegateResponse +* (tools) [#14793](https://github.com/cosmos/cosmos-sdk/pull/14793) Dockerfile optimization. ### State Machine Breaking diff --git a/Dockerfile b/Dockerfile index fff99095d41..6bf838809b0 100644 --- a/Dockerfile +++ b/Dockerfile @@ -10,15 +10,20 @@ # > docker run -it -p 26657:26657 -p 26656:26656 -v ~/.simappcli:/root/.simapp simapp simd keys add foo # > docker run -it -p 26657:26657 -p 26656:26656 -v ~/.simappcli:/root/.simapp simapp simd keys list # TODO: demo connecting rest-server (or is this in server now?) -FROM --platform=$BUILDPLATFORM golang:1.19-alpine AS build-env -# Install minimum necessary dependencies -ENV PACKAGES curl make git libc-dev bash gcc linux-headers eudev-dev python3 -RUN apk add --no-cache $PACKAGES +# bullseye already comes with build dependencies, so we don't need anything extra to install +FROM --platform=$BUILDPLATFORM golang:1.19-bullseye AS build-env # Set working directory for the build WORKDIR /go/src/github.com/cosmos/cosmos-sdk +# optimization: if go.sum didn't change, docker will use cached image +COPY go.mod go.sum ./ +COPY collections/go.mod collections/go.sum ./collections/ +COPY store/go.mod store/go.sum ./store/ + +RUN go mod download + # Add source files COPY . . @@ -30,17 +35,14 @@ ARG TARGETOS TARGETARCH RUN GOOS=$TARGETOS GOARCH=$TARGETARCH make build -# Final image -FROM alpine:edge +# Final image, without build artifacts. `/base` already contains openssl, glibc and all required libs to start an app +FROM gcr.io/distroless/base -# Install ca-certificates -RUN apk add --update ca-certificates +EXPOSE 26656 26657 1317 9090 +# Run simd by default, omit entrypoint to ease using container with simcli +CMD ["simd"] +STOPSIGNAL SIGTERM WORKDIR /root # Copy over binaries from the build-env COPY --from=build-env /go/src/github.com/cosmos/cosmos-sdk/build/simd /usr/bin/simd - -EXPOSE 26656 26657 1317 9090 - -# Run simd by default, omit entrypoint to ease using container with simcli -CMD ["simd"] diff --git a/Makefile b/Makefile index 4303d7db109..cdd92a9989d 100644 --- a/Makefile +++ b/Makefile @@ -20,26 +20,26 @@ ENABLE_ROCKSDB ?= false # process build tags build_tags = netgo ifeq ($(LEDGER_ENABLED),true) - ifeq ($(OS),Windows_NT) - GCCEXE = $(shell where gcc.exe 2> NUL) - ifeq ($(GCCEXE),) - $(error gcc.exe not installed for ledger support, please install or set LEDGER_ENABLED=false) - else - build_tags += ledger - endif - else - UNAME_S = $(shell uname -s) - ifeq ($(UNAME_S),OpenBSD) - $(warning OpenBSD detected, disabling ledger support (https://github.com/cosmos/cosmos-sdk/issues/1988)) - else - GCC = $(shell command -v gcc 2> /dev/null) - ifeq ($(GCC),) - $(error gcc not installed for ledger support, please install or set LEDGER_ENABLED=false) - else - build_tags += ledger - endif - endif - endif + ifeq ($(OS),Windows_NT) + GCCEXE = $(shell where gcc.exe 2> NUL) + ifeq ($(GCCEXE),) + $(error gcc.exe not installed for ledger support, please install or set LEDGER_ENABLED=false) + else + build_tags += ledger + endif + else + UNAME_S = $(shell uname -s) + ifeq ($(UNAME_S),OpenBSD) + $(warning OpenBSD detected, disabling ledger support (https://github.com/cosmos/cosmos-sdk/issues/1988)) + else + GCC = $(shell command -v gcc 2> /dev/null) + ifeq ($(GCC),) + $(error gcc not installed for ledger support, please install or set LEDGER_ENABLED=false) + else + build_tags += ledger + endif + endif + endif endif ifeq (secp,$(findstring secp,$(COSMOS_BUILD_OPTIONS))) @@ -124,7 +124,7 @@ build: BUILD_ARGS=-o $(BUILDDIR)/ build-linux-amd64: GOOS=linux GOARCH=amd64 LEDGER_ENABLED=false $(MAKE) build - + build-linux-arm64: GOOS=linux GOARCH=arm64 LEDGER_ENABLED=false $(MAKE) build @@ -165,9 +165,9 @@ $(MOCKS_DIR): distclean: clean tools-clean clean: rm -rf \ - $(BUILDDIR)/ \ - artifacts/ \ - tmp-swagger-gen/ + $(BUILDDIR)/ \ + artifacts/ \ + tmp-swagger-gen/ .PHONY: distclean clean @@ -187,11 +187,11 @@ go.sum: go.mod update-swagger-docs: statik $(BINDIR)/statik -src=client/docs/swagger-ui -dest=client/docs -f -m @if [ -n "$(git status --porcelain)" ]; then \ - echo "\033[91mSwagger docs are out of sync!!!\033[0m";\ - exit 1;\ - else \ - echo "\033[92mSwagger docs are in sync\033[0m";\ - fi + echo "\033[91mSwagger docs are out of sync!!!\033[0m";\ + exit 1;\ + else \ + echo "\033[92mSwagger docs are in sync\033[0m";\ + fi .PHONY: update-swagger-docs godocs: diff --git a/contrib/devtools/Dockerfile b/contrib/devtools/Dockerfile index b64b9e3a6c5..e354dd45c50 100644 --- a/contrib/devtools/Dockerfile +++ b/contrib/devtools/Dockerfile @@ -22,10 +22,10 @@ USER $UNAME ENV GOLANG_PROTOBUF_VERSION=1.28.1 \ GRPC_GATEWAY_VERSION=1.16.0 -RUN go install github.com/cosmos/cosmos-proto/cmd/protoc-gen-go-pulsar@latest -RUN go install google.golang.org/protobuf/cmd/protoc-gen-go@v${GOLANG_PROTOBUF_VERSION} -RUN go install github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway@v${GRPC_GATEWAY_VERSION} \ - github.com/grpc-ecosystem/grpc-gateway/protoc-gen-swagger@v${GRPC_GATEWAY_VERSION} +RUN go install github.com/cosmos/cosmos-proto/cmd/protoc-gen-go-pulsar@latest && \ + go install google.golang.org/protobuf/cmd/protoc-gen-go@v${GOLANG_PROTOBUF_VERSION} && \ + go install github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway@v${GRPC_GATEWAY_VERSION} \ + github.com/grpc-ecosystem/grpc-gateway/protoc-gen-swagger@v${GRPC_GATEWAY_VERSION} # install all gogo protobuf binaries RUN git clone https://github.com/cosmos/gogoproto.git; \ @@ -33,4 +33,4 @@ RUN git clone https://github.com/cosmos/gogoproto.git; \ go mod download; \ make install -COPY --from=BUILDER /usr/local/bin /usr/local/bin \ No newline at end of file +COPY --from=BUILDER /usr/local/bin /usr/local/bin diff --git a/contrib/images/Makefile b/contrib/images/Makefile index 0c936415511..9fd1c11c12a 100644 --- a/contrib/images/Makefile +++ b/contrib/images/Makefile @@ -2,13 +2,13 @@ all: simd-env simd-env: simd-rmi docker build --tag cosmossdk/simd -f simd-env/Dockerfile \ - $(shell git rev-parse --show-toplevel) + $(shell git rev-parse --show-toplevel) simd-dlv: simd-rmi docker build --tag cosmossdk/simd -f simd-dlv/Dockerfile \ - $(shell git rev-parse --show-toplevel) + $(shell git rev-parse --show-toplevel) simd-rmi: docker rmi cosmossdk/simd 2>/dev/null; true -.PHONY: all simd-env simd-dlv simd-rmi \ No newline at end of file +.PHONY: all simd-env simd-dlv simd-rmi diff --git a/contrib/images/simd-dlv/Dockerfile b/contrib/images/simd-dlv/Dockerfile index 85850839e69..0fbf1698bd3 100644 --- a/contrib/images/simd-dlv/Dockerfile +++ b/contrib/images/simd-dlv/Dockerfile @@ -10,21 +10,24 @@ COPY math/go.mod math/go.sum /work/math/ COPY api/go.mod api/go.sum /work/api/ COPY core/go.mod core/go.sum /work/core/ COPY depinject/go.mod depinject/go.sum /work/depinject/ - +COPY tools/rosetta/go.mod tools/rosetta/go.sum /work/tools/rosetta/ +COPY collections/go.mod collections/go.sum /work/collections/ +COPY store/go.mod store/go.sum /work/store/ RUN go mod download + COPY ./ /work RUN LEDGER_ENABLED=false make COSMOS_BUILD_OPTIONS="debug,nostrip" clean build + FROM alpine AS run RUN apk add bash curl jq -COPY contrib/images/simd-dlv/wrapper.sh /usr/bin/wrapper.sh - -VOLUME /simd -COPY --from=build /work/build/simd /simd/ -COPY --from=build /go/bin/dlv /usr/local/bin -WORKDIR /simd - -EXPOSE 26656 26657 2345 +EXPOSE 26656 26657 ENTRYPOINT ["/usr/bin/wrapper.sh"] CMD ["start", "--log_format", "plain"] STOPSIGNAL SIGTERM +VOLUME /simd +WORKDIR /simd + +COPY contrib/images/simd-dlv/wrapper.sh /usr/bin/wrapper.sh +COPY --from=build /work/build/simd /simd/ +COPY --from=build /go/bin/dlv /usr/local/bin diff --git a/contrib/images/simd-env/Dockerfile b/contrib/images/simd-env/Dockerfile index c75d1a56635..f5f3fe37e43 100644 --- a/contrib/images/simd-env/Dockerfile +++ b/contrib/images/simd-env/Dockerfile @@ -12,20 +12,21 @@ COPY depinject/go.mod depinject/go.sum /work/depinject/ COPY tools/rosetta/go.mod tools/rosetta/go.sum /work/tools/rosetta/ COPY collections/go.mod collections/go.sum /work/collections/ COPY store/go.mod store/go.sum /work/store/ - RUN go mod download + COPY ./ /work RUN LEDGER_ENABLED=false make clean build + FROM alpine AS run RUN apk add bash curl jq -COPY contrib/images/simd-env/wrapper.sh /usr/bin/wrapper.sh - -VOLUME /simd -COPY --from=build /work/build/simd /simd/ -WORKDIR /simd - EXPOSE 26656 26657 ENTRYPOINT ["/usr/bin/wrapper.sh"] CMD ["start", "--log_format", "plain"] STOPSIGNAL SIGTERM +VOLUME /simd +WORKDIR /simd + +COPY contrib/images/simd-env/wrapper.sh /usr/bin/wrapper.sh +COPY --from=build /work/build/simd /simd/ + diff --git a/contrib/rosetta/rosetta-ci/Dockerfile b/contrib/rosetta/rosetta-ci/Dockerfile index 951f135881f..a255f0171b7 100644 --- a/contrib/rosetta/rosetta-ci/Dockerfile +++ b/contrib/rosetta/rosetta-ci/Dockerfile @@ -6,9 +6,9 @@ ARG ROSETTA_VERSION="v0.10.0" # build rosetta CLI WORKDIR /rosetta -RUN git clone https://github.com/coinbase/rosetta-cli . -RUN git checkout tags/$ROSETTA_VERSION -RUN go build -o rosetta-cli ./main.go +RUN git clone https://github.com/coinbase/rosetta-cli . && \ + git checkout tags/$ROSETTA_VERSION && \ + go build -o rosetta-cli ./main.go # prepare node data WORKDIR /node @@ -24,19 +24,17 @@ FROM alpine RUN apk add gcc git libc-dev python3 --no-cache ENV PATH=$PATH:/bin +# Set GENESIS_HASH env needed for api correctness +ENV GENESIS_HASH "01331100220a94b9acc0ceef697a6db44ba70fc61e9e6c24802974a0b6cba29b" COPY --from=build /rosetta/rosetta-cli /bin/rosetta-cli COPY --from=build /simd/simapp/simd/simd /bin/simd WORKDIR /rosetta COPY ./contrib/rosetta/configuration ./ - -# Set GENESIS_HASH env needed for api correctness -ENV GENESIS_HASH "01331100220a94b9acc0ceef697a6db44ba70fc61e9e6c24802974a0b6cba29b" - -RUN chmod +x run_tests.sh -RUN chmod +x send_funds.sh -RUN chmod +x faucet.py +RUN chmod +x run_tests.sh && \ + chmod +x send_funds.sh && \ + chmod +x faucet.py COPY --from=build /node/root /root/ WORKDIR /root/.simapp diff --git a/types/coin.go b/types/coin.go index 79c0da1f167..e1dccdf18e8 100644 --- a/types/coin.go +++ b/types/coin.go @@ -421,7 +421,7 @@ func (coins Coins) SafeMulInt(x Int) (Coins, bool) { } // QuoInt performs the scalar division of coins with a `divisor` -// All coins are divided by x and trucated. +// All coins are divided by x and truncated. // e.g. // {2A, 30B} / 2 = {1A, 15B} // {2A} / 2 = {1A}