Skip to content

Commit

Permalink
perf: dockerfiles (#14793)
Browse files Browse the repository at this point in the history
  • Loading branch information
robert-zaremba committed Jan 26, 2023
1 parent 938143f commit be9bd7a
Show file tree
Hide file tree
Showing 9 changed files with 82 additions and 77 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
28 changes: 15 additions & 13 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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 . .

Expand All @@ -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"]
58 changes: 29 additions & 29 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand All @@ -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:
Expand Down
10 changes: 5 additions & 5 deletions contrib/devtools/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@ 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; \
cd gogoproto; \
go mod download; \
make install

COPY --from=BUILDER /usr/local/bin /usr/local/bin
COPY --from=BUILDER /usr/local/bin /usr/local/bin
6 changes: 3 additions & 3 deletions contrib/images/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
.PHONY: all simd-env simd-dlv simd-rmi
21 changes: 12 additions & 9 deletions contrib/images/simd-dlv/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
15 changes: 8 additions & 7 deletions contrib/images/simd-env/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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/

18 changes: 8 additions & 10 deletions contrib/rosetta/rosetta-ci/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion types/coin.go
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down

0 comments on commit be9bd7a

Please sign in to comment.