From cc37320aed58803c89f9f54ff11214cbc4ee2b86 Mon Sep 17 00:00:00 2001 From: Alex Peters Date: Fri, 3 Jul 2020 13:22:38 +0200 Subject: [PATCH] Better cache optimizing Dockerfile --- Dockerfile | 36 +++++++++++++++++++++--------------- 1 file changed, 21 insertions(+), 15 deletions(-) diff --git a/Dockerfile b/Dockerfile index d4f9ad4433..cb77659afb 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,6 @@ # docker build . -t cosmwasm/wasmd:latest # docker run --rm -it cosmwasm/wasmd:latest /bin/sh -FROM cosmwasm/go-ext-builder:0.8.2-alpine AS builder +FROM cosmwasm/go-ext-builder:0.8.2-alpine AS rust-builder RUN apk add git # without this, build with LEDGER_ENABLED=false @@ -8,32 +8,38 @@ RUN apk add libusb-dev linux-headers # copy all code into /code WORKDIR /code -COPY . /code +COPY go.* /code/ # download all deps -RUN go mod download -# TODO: how to use this instead of hardcoding GO_COSMWASM -RUN basename $(ls -d /go/pkg/mod/github.com/\!cosm\!wasm/go-cosmwasm@v*) - -ENV GO_COSMWASM="v0.9.1" +RUN go mod download github.com/CosmWasm/go-cosmwasm # build go-cosmwasm *.a and install it -WORKDIR /go/pkg/mod/github.com/\!cosm\!wasm/go-cosmwasm@${GO_COSMWASM} -RUN cargo build --release --features backtraces --example muslc -RUN mv /go/pkg/mod/github.com/\!cosm\!wasm/go-cosmwasm@${GO_COSMWASM}/target/release/examples/libmuslc.a /lib/libgo_cosmwasm_muslc.a -# I got errors from go mod verify (called from make build) if I didn't clean this up -RUN rm -rf /go/pkg/mod/github.com/\!cosm\!wasm/go-cosmwasm@${GO_COSMWASM}/target +RUN export GO_WASM_DIR=$(go list -f "{{ .Dir }}" -m github.com/CosmWasm/go-cosmwasm) && \ + cd ${GO_WASM_DIR} && \ + cargo build --release --features backtraces --example muslc && \ + mv ${GO_WASM_DIR}/target/release/examples/libmuslc.a /lib/libgo_cosmwasm_muslc.a + + +# -------------------------------------------------------- +FROM cosmwasm/go-ext-builder:0.8.2-alpine AS go-builder + +RUN apk add git +# without this, build with LEDGER_ENABLED=false +RUN apk add libusb-dev linux-headers -# build the go wasm binary WORKDIR /code +COPY . /code/ + +COPY --from=rust-builder /lib/libgo_cosmwasm_muslc.a /lib/libgo_cosmwasm_muslc.a # force it to use static lib (from above) not standard libgo_cosmwasm.so file RUN BUILD_TAGS=muslc make build +# -------------------------------------------------------- FROM alpine:3.12 -COPY --from=builder /code/build/wasmd /usr/bin/wasmd -COPY --from=builder /code/build/wasmcli /usr/bin/wasmcli +COPY --from=go-builder /code/build/wasmd /usr/bin/wasmd +COPY --from=go-builder /code/build/wasmcli /usr/bin/wasmcli COPY docker/* /opt/ RUN chmod +x /opt/*.sh