Skip to content

Commit 33986a3

Browse files
mergify[bot]robert-zarembajulienrbrt
authored
perf: dockerfiles (backport #14793) (#14795)
Co-authored-by: Robert Zaremba <robert@zaremba.ch> Co-authored-by: Julien Robert <julien@rbrt.fr>
1 parent d4b2897 commit 33986a3

File tree

9 files changed

+76
-77
lines changed

9 files changed

+76
-77
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
3939

4040
### Improvements
4141

42+
* (tools) [#14793](https://github.com/cosmos/cosmos-sdk/pull/14793) Dockerfile optimization.
4243
* (x/gov) [#13010](https://github.com/cosmos/cosmos-sdk/pull/13010) Partial cherry-pick of this issue for adding proposer migration.
4344
* [#14691](https://github.com/cosmos/cosmos-sdk/pull/14691) Change behavior of `sdk.StringifyEvents` to not flatten events attributes by events type.
4445
* This change only affects ABCI message logs, and not the actual events.

Dockerfile

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,33 +10,32 @@
1010
# > docker run -it -p 26657:26657 -p 26656:26656 -v ~/.simappcli:/root/.simapp simapp simd keys add foo
1111
# > docker run -it -p 26657:26657 -p 26656:26656 -v ~/.simappcli:/root/.simapp simapp simd keys list
1212
# TODO: demo connecting rest-server (or is this in server now?)
13-
FROM golang:1.19-alpine AS build-env
1413

15-
# Install minimum necessary dependencies
16-
ENV PACKAGES curl make git libc-dev bash gcc linux-headers eudev-dev python3
17-
RUN apk add --no-cache $PACKAGES
14+
# bullseye already comes with build dependencies, so we don't need anything extra to install
15+
FROM --platform=$BUILDPLATFORM golang:1.19-bullseye AS build-env
1816

1917
# Set working directory for the build
2018
WORKDIR /go/src/github.com/cosmos/cosmos-sdk
2119

20+
# optimization: if go.sum didn't change, docker will use cached image
21+
COPY go.mod go.sum ./
22+
RUN go mod download
23+
2224
# Add source files
2325
COPY . .
2426

2527
# install simapp, remove packages
2628
RUN make build
2729

2830

29-
# Final image
30-
FROM alpine:edge
31+
# Final image, without build artifacts. `/base` already contains openssl, glibc and all required libs to start an app
32+
FROM gcr.io/distroless/base
3133

32-
# Install ca-certificates
33-
RUN apk add --update ca-certificates
34+
EXPOSE 26656 26657 1317 9090
35+
# Run simd by default, omit entrypoint to ease using container with simcli
36+
CMD ["simd"]
37+
STOPSIGNAL SIGTERM
3438
WORKDIR /root
3539

3640
# Copy over binaries from the build-env
3741
COPY --from=build-env /go/src/github.com/cosmos/cosmos-sdk/build/simd /usr/bin/simd
38-
39-
EXPOSE 26656 26657 1317 9090
40-
41-
# Run simd by default, omit entrypoint to ease using container with simcli
42-
CMD ["simd"]

Makefile

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -21,26 +21,26 @@ ENABLE_ROCKSDB ?= false
2121
# process build tags
2222
build_tags = netgo
2323
ifeq ($(LEDGER_ENABLED),true)
24-
ifeq ($(OS),Windows_NT)
25-
GCCEXE = $(shell where gcc.exe 2> NUL)
26-
ifeq ($(GCCEXE),)
27-
$(error gcc.exe not installed for ledger support, please install or set LEDGER_ENABLED=false)
28-
else
29-
build_tags += ledger
30-
endif
31-
else
32-
UNAME_S = $(shell uname -s)
33-
ifeq ($(UNAME_S),OpenBSD)
34-
$(warning OpenBSD detected, disabling ledger support (https://github.com/cosmos/cosmos-sdk/issues/1988))
35-
else
36-
GCC = $(shell command -v gcc 2> /dev/null)
37-
ifeq ($(GCC),)
38-
$(error gcc not installed for ledger support, please install or set LEDGER_ENABLED=false)
39-
else
40-
build_tags += ledger
41-
endif
42-
endif
43-
endif
24+
ifeq ($(OS),Windows_NT)
25+
GCCEXE = $(shell where gcc.exe 2> NUL)
26+
ifeq ($(GCCEXE),)
27+
$(error gcc.exe not installed for ledger support, please install or set LEDGER_ENABLED=false)
28+
else
29+
build_tags += ledger
30+
endif
31+
else
32+
UNAME_S = $(shell uname -s)
33+
ifeq ($(UNAME_S),OpenBSD)
34+
$(warning OpenBSD detected, disabling ledger support (https://github.com/cosmos/cosmos-sdk/issues/1988))
35+
else
36+
GCC = $(shell command -v gcc 2> /dev/null)
37+
ifeq ($(GCC),)
38+
$(error gcc not installed for ledger support, please install or set LEDGER_ENABLED=false)
39+
else
40+
build_tags += ledger
41+
endif
42+
endif
43+
endif
4444
endif
4545

4646
ifeq (secp,$(findstring secp,$(COSMOS_BUILD_OPTIONS)))
@@ -125,7 +125,7 @@ build: BUILD_ARGS=-o $(BUILDDIR)/
125125

126126
build-linux-amd64:
127127
GOOS=linux GOARCH=amd64 LEDGER_ENABLED=false $(MAKE) build
128-
128+
129129
build-linux-arm64:
130130
GOOS=linux GOARCH=arm64 LEDGER_ENABLED=false $(MAKE) build
131131

@@ -157,9 +157,9 @@ $(MOCKS_DIR):
157157
distclean: clean tools-clean
158158
clean:
159159
rm -rf \
160-
$(BUILDDIR)/ \
161-
artifacts/ \
162-
tmp-swagger-gen/
160+
$(BUILDDIR)/ \
161+
artifacts/ \
162+
tmp-swagger-gen/
163163

164164
.PHONY: distclean clean
165165

@@ -179,11 +179,11 @@ go.sum: go.mod
179179
update-swagger-docs: statik
180180
$(BINDIR)/statik -src=client/docs/swagger-ui -dest=client/docs -f -m
181181
@if [ -n "$(git status --porcelain)" ]; then \
182-
echo "\033[91mSwagger docs are out of sync!!!\033[0m";\
183-
exit 1;\
184-
else \
185-
echo "\033[92mSwagger docs are in sync\033[0m";\
186-
fi
182+
echo "\033[91mSwagger docs are out of sync!!!\033[0m";\
183+
exit 1;\
184+
else \
185+
echo "\033[92mSwagger docs are in sync\033[0m";\
186+
fi
187187
.PHONY: update-swagger-docs
188188

189189
godocs:

contrib/devtools/Dockerfile

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,15 @@ USER $UNAME
2222
ENV GOLANG_PROTOBUF_VERSION=1.28.1 \
2323
GRPC_GATEWAY_VERSION=1.16.0
2424

25-
RUN go install github.com/cosmos/cosmos-proto/cmd/protoc-gen-go-pulsar@latest
26-
RUN go install google.golang.org/protobuf/cmd/protoc-gen-go@v${GOLANG_PROTOBUF_VERSION}
27-
RUN go install github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway@v${GRPC_GATEWAY_VERSION} \
28-
github.com/grpc-ecosystem/grpc-gateway/protoc-gen-swagger@v${GRPC_GATEWAY_VERSION}
25+
RUN go install github.com/cosmos/cosmos-proto/cmd/protoc-gen-go-pulsar@latest && \
26+
go install google.golang.org/protobuf/cmd/protoc-gen-go@v${GOLANG_PROTOBUF_VERSION} && \
27+
go install github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway@v${GRPC_GATEWAY_VERSION} \
28+
github.com/grpc-ecosystem/grpc-gateway/protoc-gen-swagger@v${GRPC_GATEWAY_VERSION}
2929

3030
# install all gogo protobuf binaries
3131
RUN git clone https://github.com/cosmos/gogoproto.git; \
3232
cd gogoproto; \
3333
go mod download; \
3434
make install
3535

36-
COPY --from=BUILDER /usr/local/bin /usr/local/bin
36+
COPY --from=BUILDER /usr/local/bin /usr/local/bin

contrib/images/Makefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@ all: simd-env
22

33
simd-env: simd-rmi
44
docker build --tag cosmossdk/simd -f simd-env/Dockerfile \
5-
$(shell git rev-parse --show-toplevel)
5+
$(shell git rev-parse --show-toplevel)
66

77
simd-dlv: simd-rmi
88
docker build --tag cosmossdk/simd -f simd-dlv/Dockerfile \
9-
$(shell git rev-parse --show-toplevel)
9+
$(shell git rev-parse --show-toplevel)
1010

1111
simd-rmi:
1212
docker rmi cosmossdk/simd 2>/dev/null; true
1313

14-
.PHONY: all simd-env simd-dlv simd-rmi
14+
.PHONY: all simd-env simd-dlv simd-rmi

contrib/images/simd-dlv/Dockerfile

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,22 @@ COPY math/go.mod math/go.sum /work/math/
1010
COPY api/go.mod api/go.sum /work/api/
1111
COPY core/go.mod core/go.sum /work/core/
1212
COPY depinject/go.mod depinject/go.sum /work/depinject/
13-
13+
COPY tools/rosetta/go.mod tools/rosetta/go.sum /work/tools/rosetta/
1414
RUN go mod download
15+
1516
COPY ./ /work
1617
RUN LEDGER_ENABLED=false make COSMOS_BUILD_OPTIONS="debug,nostrip" clean build
1718

19+
1820
FROM alpine AS run
1921
RUN apk add bash curl jq
20-
COPY contrib/images/simd-dlv/wrapper.sh /usr/bin/wrapper.sh
21-
22-
VOLUME /simd
23-
COPY --from=build /work/build/simd /simd/
24-
COPY --from=build /go/bin/dlv /usr/local/bin
25-
WORKDIR /simd
26-
27-
EXPOSE 26656 26657 2345
22+
EXPOSE 26656 26657
2823
ENTRYPOINT ["/usr/bin/wrapper.sh"]
2924
CMD ["start", "--log_format", "plain"]
3025
STOPSIGNAL SIGTERM
26+
VOLUME /simd
27+
WORKDIR /simd
28+
29+
COPY contrib/images/simd-dlv/wrapper.sh /usr/bin/wrapper.sh
30+
COPY --from=build /work/build/simd /simd/
31+
COPY --from=build /go/bin/dlv /usr/local/bin

contrib/images/simd-env/Dockerfile

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,20 @@ COPY api/go.mod api/go.sum /work/api/
1010
COPY core/go.mod core/go.sum /work/core/
1111
COPY depinject/go.mod depinject/go.sum /work/depinject/
1212
COPY tools/rosetta/go.mod tools/rosetta/go.sum /work/tools/rosetta/
13-
1413
RUN go mod download
14+
1515
COPY ./ /work
1616
RUN LEDGER_ENABLED=false make clean build
1717

18+
1819
FROM alpine AS run
1920
RUN apk add bash curl jq
20-
COPY contrib/images/simd-env/wrapper.sh /usr/bin/wrapper.sh
21-
22-
VOLUME /simd
23-
COPY --from=build /work/build/simd /simd/
24-
WORKDIR /simd
25-
2621
EXPOSE 26656 26657
2722
ENTRYPOINT ["/usr/bin/wrapper.sh"]
2823
CMD ["start", "--log_format", "plain"]
2924
STOPSIGNAL SIGTERM
25+
VOLUME /simd
26+
WORKDIR /simd
27+
28+
COPY contrib/images/simd-env/wrapper.sh /usr/bin/wrapper.sh
29+
COPY --from=build /work/build/simd /simd/

contrib/rosetta/rosetta-ci/Dockerfile

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ ARG ROSETTA_VERSION="v0.10.0"
66

77
# build rosetta CLI
88
WORKDIR /rosetta
9-
RUN git clone https://github.com/coinbase/rosetta-cli .
10-
RUN git checkout tags/$ROSETTA_VERSION
11-
RUN go build -o rosetta-cli ./main.go
9+
RUN git clone https://github.com/coinbase/rosetta-cli . && \
10+
git checkout tags/$ROSETTA_VERSION && \
11+
go build -o rosetta-cli ./main.go
1212

1313
# prepare node data
1414
WORKDIR /node
@@ -24,19 +24,17 @@ FROM alpine
2424
RUN apk add gcc git libc-dev python3 --no-cache
2525

2626
ENV PATH=$PATH:/bin
27+
# Set GENESIS_HASH env needed for api correctness
28+
ENV GENESIS_HASH "01331100220a94b9acc0ceef697a6db44ba70fc61e9e6c24802974a0b6cba29b"
2729

2830
COPY --from=build /rosetta/rosetta-cli /bin/rosetta-cli
2931
COPY --from=build /simd/simapp/simd/simd /bin/simd
3032

3133
WORKDIR /rosetta
3234
COPY ./contrib/rosetta/configuration ./
33-
34-
# Set GENESIS_HASH env needed for api correctness
35-
ENV GENESIS_HASH "01331100220a94b9acc0ceef697a6db44ba70fc61e9e6c24802974a0b6cba29b"
36-
37-
RUN chmod +x run_tests.sh
38-
RUN chmod +x send_funds.sh
39-
RUN chmod +x faucet.py
35+
RUN chmod +x run_tests.sh && \
36+
chmod +x send_funds.sh && \
37+
chmod +x faucet.py
4038

4139
COPY --from=build /node/root /root/
4240
WORKDIR /root/.simapp

types/coin.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,7 @@ func (coins Coins) SafeMulInt(x Int) (Coins, bool) {
424424
}
425425

426426
// QuoInt performs the scalar division of coins with a `divisor`
427-
// All coins are divided by x and trucated.
427+
// All coins are divided by x and truncated.
428428
// e.g.
429429
// {2A, 30B} / 2 = {1A, 15B}
430430
// {2A} / 2 = {1A}

0 commit comments

Comments
 (0)