Skip to content

Commit

Permalink
Better cache optimizing Dockerfile
Browse files Browse the repository at this point in the history
  • Loading branch information
alpe committed Jul 3, 2020
1 parent 0dd6b58 commit cc37320
Showing 1 changed file with 21 additions and 15 deletions.
36 changes: 21 additions & 15 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,39 +1,45 @@
# 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
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
Expand Down

0 comments on commit cc37320

Please sign in to comment.