Skip to content

Instantly share code, notes, and snippets.

@pr0cf5
Created December 19, 2022 07:11
Show Gist options
  • Save pr0cf5/6f338f08733b965f09da0fa6eccf513a to your computer and use it in GitHub Desktop.
Save pr0cf5/6f338f08733b965f09da0fa6eccf513a to your computer and use it in GitHub Desktop.
Building wasmd from static
#!/bin/sh
sudo docker build -t static-build .
sudo docker rm -f static-build
sudo docker run -d --name static-build static-build sleep infinity
sudo docker cp static-build:/usr/local/bin/terrad ./terrad-static
# Dockerfile
'''
# docker build . -t cosmwasm/wasmd:latest
# docker run --rm -it cosmwasm/wasmd:latest /bin/sh
FROM golang:1.17.8-alpine3.15 AS go-builder
# See https://github.com/CosmWasm/wasmvm/releases
ENV LIBWASMVM_VERSION=0.16.6
ENV LIBWASMVM_SHA256=fe63ff6bb75cad9116948d96344391d6786b6009d28e7016a85e1a268033d8f8
# this comes from standard alpine nightly file
# https://github.com/rust-lang/docker-rust-nightly/blob/master/alpine3.12/Dockerfile
# with some changes to support our toolchain, etc
RUN set -eux; apk add --no-cache ca-certificates build-base;
RUN apk add git cmake
# NOTE: add these to run with LEDGER_ENABLED=true
# RUN apk add libusb-dev linux-headers
WORKDIR /code
COPY . /code/
# Install mimalloc
RUN git clone --depth 1 https://github.com/microsoft/mimalloc; cd mimalloc; mkdir build; cd build; cmake ..; make -j$(nproc); make install
ENV MIMALLOC_RESERVE_HUGE_OS_PAGES=4
# See https://github.com/CosmWasm/wasmvm/releases
ADD https://github.com/CosmWasm/wasmvm/releases/download/v${LIBWASMVM_VERSION}/libwasmvm_muslc.x86_64.a /lib/libwasmvm_muslc.a
RUN sha256sum /lib/libwasmvm_muslc.a | grep ${LIBWASMVM_SHA256}
# force it to use static lib (from above) not standard libgo_cosmwasm.so file
RUN LEDGER_ENABLED=false BUILD_TAGS=muslc LDFLAGS="-linkmode=external -extldflags \"-L/code/mimalloc/build -lmimalloc -Wl,-z,muldefs -static\"" make build
FROM alpine:3.15.4
RUN addgroup terra \
&& adduser -G terra -D -h /terra terra
WORKDIR /terra
COPY --from=go-builder /code/build/terrad /usr/local/bin/terrad
USER terra
# rest server
EXPOSE 1317
# grpc
EXPOSE 9090
# tendermint p2p
EXPOSE 26656
# tendermint rpc
EXPOSE 26657
CMD ["/usr/local/bin/terrad", "version"]
'''
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment