From 461c0ddbefd48394e24be0fc30b626ee425cc838 Mon Sep 17 00:00:00 2001 From: Robert Zaremba Date: Wed, 11 Jan 2023 21:24:07 +0100 Subject: [PATCH] perf: optimize docker builds (#1708) ## Description closes: #1697 --- ### Author Checklist _All items are required. Please add a note to the item if the item is not applicable and please add links to any relevant follow up issues._ I have... - [ ] included the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title - [ ] added `!` to the type prefix if API or client breaking change - [ ] added appropriate labels to the PR - [ ] targeted the correct branch (see [PR Targeting](https://github.com/umee-network/umee/blob/main/CONTRIBUTING.md#pr-targeting)) - [ ] provided a link to the relevant issue or specification - [ ] added a changelog entry to `CHANGELOG.md` - [ ] included comments for [documenting Go code](https://blog.golang.org/godoc) - [ ] updated the relevant documentation or specification - [ ] reviewed "Files changed" and left comments if necessary - [ ] confirmed all CI checks have passed ### Reviewers Checklist _All items are required. Please add a note if the item is not applicable and please add your handle next to the items reviewed if you only reviewed selected items._ I have... - [ ] confirmed the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title - [ ] confirmed all author checklist items have been addressed - [ ] reviewed state machine logic - [ ] reviewed API design and naming - [ ] reviewed documentation is accurate - [ ] reviewed tests and test coverage - [ ] manually tested (if applicable) --- contrib/images/price-feeder.dockerfile | 13 ++++++++++--- contrib/images/umee.e2e-static.dockerfile | 14 +++++++++----- contrib/images/umee.e2e.dockerfile | 11 +++++++---- contrib/images/umeed.dockerfile | 15 +++++++++------ x/leverage/types/msgs.go | 2 +- 5 files changed, 36 insertions(+), 19 deletions(-) diff --git a/contrib/images/price-feeder.dockerfile b/contrib/images/price-feeder.dockerfile index a64f709652..172683a1e0 100644 --- a/contrib/images/price-feeder.dockerfile +++ b/contrib/images/price-feeder.dockerfile @@ -1,7 +1,12 @@ # Fetch base packages FROM golang:1.19-alpine AS builder RUN apk add --no-cache make git libc-dev gcc linux-headers build-base + WORKDIR /src/ +# optimization: if go.sum didn't change, docker will use cached image +COPY go.mod go.sum ./ +RUN go mod download + COPY . . # Cosmwasm - Download correct libwasmvm version @@ -14,9 +19,11 @@ RUN WASMVM_VERSION=$(go list -m github.com/CosmWasm/wasmvm | cut -d ' ' -f 2) && # Build the binary RUN cd price-feeder && LEDGER_ENABLED=false BUILD_TAGS=muslc LINK_STATICALLY=true make install +## Prepare the final clear binary FROM alpine:3.17 -RUN apk add bash curl jq -COPY --from=builder /go/bin/price-feeder /usr/local/bin/ EXPOSE 7171 -CMD ["price-feeder"] STOPSIGNAL SIGTERM +CMD ["price-feeder"] + +RUN apk add ca-certificates +COPY --from=builder /go/bin/price-feeder /usr/local/bin/ diff --git a/contrib/images/umee.e2e-static.dockerfile b/contrib/images/umee.e2e-static.dockerfile index 5c3304cc03..74be084e07 100644 --- a/contrib/images/umee.e2e-static.dockerfile +++ b/contrib/images/umee.e2e-static.dockerfile @@ -3,13 +3,16 @@ # umeed, price-feeder, peggo FROM golang:1.19-alpine AS builder -ENV PACKAGES make git gcc linux-headers ca-certificates build-base curl +ENV PACKAGES make git gcc linux-headers build-base curl RUN apk add --no-cache $PACKAGES ## Build umeed WORKDIR /src/umee -COPY . . +# optimization: if go.sum didn't change, docker will use cached image +COPY go.mod go.sum ./ RUN go mod download + +COPY . . # Cosmwasm - Download correct libwasmvm version RUN WASMVM_VERSION=$(go list -m github.com/CosmWasm/wasmvm | cut -d ' ' -f 2) && \ wget https://github.com/CosmWasm/wasmvm/releases/download/$WASMVM_VERSION/libwasmvm_muslc.$(uname -m).a -O /lib/libwasmvm_muslc.a && \ @@ -31,9 +34,10 @@ RUN cd /src/peggo; BUILD_TAGS=muslc LDFLAGS='-linkmode=external -extldflags "-Wl ## Prepare the final clear binary FROM alpine:latest +EXPOSE 26656 26657 1317 9090 7171 +ENTRYPOINT ["umeed", "start"] + # no need to copy libwasmvm_muslc.a because we created static COPY --from=builder /go/bin/* /usr/local/bin/ COPY --from=builder /src/peggo/build/peggo /usr/local/bin/ - -EXPOSE 26656 26657 1317 9090 7171 -ENTRYPOINT ["umeed", "start"] +RUN apk add ca-certificates diff --git a/contrib/images/umee.e2e.dockerfile b/contrib/images/umee.e2e.dockerfile index f8994cd0b1..4b3f042856 100644 --- a/contrib/images/umee.e2e.dockerfile +++ b/contrib/images/umee.e2e.dockerfile @@ -7,8 +7,11 @@ FROM golang:1.19-bullseye AS builder ## Build umeed WORKDIR /src/umee -COPY . . +# optimization: if go.sum didn't change, docker will use cached image +COPY go.mod go.sum ./ RUN go mod download + +COPY . . RUN make install && \ cd price-feeder && make install @@ -20,10 +23,10 @@ RUN wget https://github.com/umee-network/peggo/releases/download/v1.4.0/peggo-v1 ## Prepare the final clear binary FROM ubuntu:rolling +EXPOSE 26656 26657 1317 9090 7171 +ENTRYPOINT ["umeed", "start"] + COPY --from=builder /go/pkg/mod/github.com/\!cosm\!wasm/wasmvm\@v*/internal/api/libwasmvm.*.so /usr/lib/ COPY --from=builder /go/bin/* /usr/local/bin/ COPY --from=builder /src/peggo-v*/peggo /usr/local/bin/ RUN apt-get update && apt-get install ca-certificates -y - -EXPOSE 26656 26657 1317 9090 7171 -ENTRYPOINT ["umeed", "start"] diff --git a/contrib/images/umeed.dockerfile b/contrib/images/umeed.dockerfile index f5b1d3db3b..212e304a2d 100644 --- a/contrib/images/umeed.dockerfile +++ b/contrib/images/umeed.dockerfile @@ -4,19 +4,22 @@ FROM golang:1.19-bullseye AS builder WORKDIR /src/ -COPY . . +# optimization: if go.sum didn't change, docker will use cached image +COPY go.mod go.sum ./ +RUN go mod download +COPY . . RUN LEDGER_ENABLED=false BUILD_TAGS=badgerdb make install # Stage-2: copy binary and required artifacts to a fresh image # we need to use debian compatible system. FROM ubuntu:rolling -# RUN apt update && apt upgrade -y ca-certificates -COPY --from=builder /go/bin/umeed /usr/local/bin/ -COPY --from=builder /go/pkg/mod/github.com/\!cosm\!wasm/wasmvm\@v*/internal/api/libwasmvm.*.so /usr/lib/ - EXPOSE 26656 26657 1317 9090 -# Run umeed by default, omit entrypoint to ease using container with CLI CMD ["umeed"] +# Run umeed by default, omit entrypoint to ease using container with CLI STOPSIGNAL SIGTERM + +RUN apt-get update && apt-get install ca-certificates -y +COPY --from=builder /go/bin/umeed /usr/local/bin/ +COPY --from=builder /go/pkg/mod/github.com/\!cosm\!wasm/wasmvm\@v*/internal/api/libwasmvm.*.so /usr/lib/ diff --git a/x/leverage/types/msgs.go b/x/leverage/types/msgs.go index f10592dace..ab731e6531 100644 --- a/x/leverage/types/msgs.go +++ b/x/leverage/types/msgs.go @@ -21,7 +21,7 @@ func NewMsgUpdateRegistry(authority, title, description string, updateTokens, ad } } -// Type implements Msg +// Type implements Msg interface func (msg MsgGovUpdateRegistry) Type() string { return sdk.MsgTypeURL(&msg) } // String implements the Stringer interface.