Skip to content

Commit

Permalink
update makefile and dockerfile
Browse files Browse the repository at this point in the history
  • Loading branch information
tuky191 committed Sep 12, 2023
1 parent c75da60 commit 81abbd3
Show file tree
Hide file tree
Showing 2 changed files with 102 additions and 41 deletions.
72 changes: 48 additions & 24 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,33 +1,42 @@
# docker build . -t cosmwasm/wasmd:latest
# docker run --rm -it cosmwasm/wasmd:latest /bin/sh
FROM golang:1.18-alpine3.17 AS go-builder
ARG GO_VERSION="1.20"
ARG ALPINE_VERSION="3.16"
ARG BUILDPLATFORM=linux/amd64
ARG BASE_IMAGE="golang:${GO_VERSION}-alpine${ALPINE_VERSION}"
FROM --platform=${BUILDPLATFORM} ${BASE_IMAGE} as base

###############################################################################
# Builder
###############################################################################
FROM base as builder-stage-1

ARG BUILDPLATFORM

# NOTE: add libusb-dev to run with LEDGER_ENABLED=true
RUN set -eux &&\
apk update &&\
apk add --no-cache \
ca-certificates \
linux-headers \
ca-certificates \
build-base \
cmake \
git

WORKDIR /go/src/mimalloc

# use mimalloc for musl
WORKDIR ${GOPATH}/src/mimalloc
RUN set -eux &&\
git clone --depth 1 \
git clone --depth 1 --branch v2.0.9 \
https://github.com/microsoft/mimalloc . &&\
mkdir -p build &&\
cd build &&\
cmake .. &&\
make -j$(nproc) &&\
make install

WORKDIR /code
COPY . /code/
WORKDIR /go/src/mantlemint
COPY . .

# Cosmwasm - Download correct libwasmvm version and verify checksum
# Cosmwasm - Download correct libwasmvm version
# See https://github.com/CosmWasm/wasmvm/releases
RUN set -eux &&\
WASMVM_VERSION=$(go list -m github.com/CosmWasm/wasmvm | cut -d ' ' -f 2) && \
WASMVM_DOWNLOADS="https://github.com/CosmWasm/wasmvm/releases/download/${WASMVM_VERSION}"; \
Expand All @@ -43,29 +52,44 @@ RUN set -eux &&\
wget ${WASMVM_URL} -O /lib/libwasmvm_muslc.a; \
CHECKSUM=`sha256sum /lib/libwasmvm_muslc.a | cut -d" " -f1`; \
grep ${CHECKSUM} /tmp/checksums.txt; \
rm /tmp/checksums.txt
rm /tmp/checksums.txt

# force it to use static lib (from above) not standard libgo_cosmwasm.so file
RUN LEDGER_ENABLED=false \
go build \
RUN set -eux &&\
LEDGER_ENABLED=false \
go build -work \
-tags muslc,linux \
-mod=readonly \
-tags "muslc,linux" \
-ldflags " \
-w -s -linkmode=external -extldflags \
'-L/go/src/mimalloc/build -lmimalloc -Wl,-z,muldefs -static' \
" \
-trimpath \
-o build/mantlemint ./sync.go
-ldflags="-extldflags '-L/go/src/mimalloc/build -lmimalloc -static'" \
-o /go/bin/mantlemint \
./sync.go

FROM alpine:3.17
###############################################################################
FROM alpine:${ALPINE_VERSION} as terra-core

WORKDIR /root

COPY --from=go-builder /code/build/mantlemint /usr/local/bin/mantlemint
COPY --from=builder-stage-1 /go/bin/mantlemint /usr/local/bin/mantlemint

ENV CHAIN_ID="localterra" \
MANTLEMINT_HOME="/app" \
## db paths relative to MANTLEMINT_HOME
INDEXER_DB="/data/indexer" \
MANTLEMINT_DB="/data/mantlemint" \
GENESIS_PATH="/app/config/genesis.json" \
DISABLE_SYNC="false" \
RUST_BACKTRACE="full" \
ENABLE_EXPORT_MODULE="false" \
RICHLIST_LENGTH="100" \
RICHLIST_THRESHOLD="0uluna" \
ACCOUNT_ADDRESS_PREFIX="terra" \
BOND_DENOM="uluna" \
LCD_ENDPOINTS="http://localhost:1317" \
RPC_ENDPOINTS="http://localhost:26657" \
WS_ENDPOINTS="ws://localhost:26657/websocket"

# rest server
# lcd & grpc ports
EXPOSE 1317
# grpc
EXPOSE 9090

CMD ["/usr/local/bin/mantlemint"]
71 changes: 54 additions & 17 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
#!/usr/bin/make -f

BUILDDIR ?= $(CURDIR)/build
DOCKER := $(shell which docker)
SHA256_CMD = sha256sum
GO_VERSION ?= "1.20"

ifeq (,$(VERSION))
VERSION := $(shell git describe --tags)
# if VERSION is empty, then populate it with branch's name and raw commit hash
ifeq (,$(VERSION))
VERSION := $(BRANCH)-$(COMMIT)
endif
endif

build: go.sum
ifeq ($(OS),Windows_NT)
Expand All @@ -9,28 +20,54 @@ else
go build -mod=readonly $(BUILD_FLAGS) -o build/mantlemint ./sync.go
endif

lint:
golangci-lint run --out-format=tab

lint-fix:
golangci-lint run --fix --out-format=tab --issues-exit-code=0

lint-strict:
find . -path './_build' -prune -o -type f -name '*.go' -exec gofumpt -w -l {} +

build-static:
mkdir -p $(BUILDDIR)
docker buildx build --tag terramoney/mantlemint ./
docker create --name temp terramoney/mantlemint:latest
docker cp temp:/usr/local/bin/mantlemint $(BUILDDIR)/
docker rm temp
$(DOCKER) buildx build --tag terramoney/mantlemint ./
$(DOCKER) create --name temp terramoney/mantlemint:latest
$(DOCKER) cp temp:/usr/local/bin/mantlemint $(BUILDDIR)/
$(DOCKER) rm temp

install: go.sum
go install -mod=readonly $(BUILD_FLAGS) ./

go.sum: go.mod
@echo "--> Ensure dependencies have not been modified"
@go mod verify

clean:
rm -rf $(BUILDDIR)/
build-release-amd64: go.sum $(BUILDDIR)/
$(DOCKER) buildx create --name mantlemint-builder || true
$(DOCKER) buildx use mantlemint-builder
$(DOCKER) buildx build \
--build-arg GO_VERSION=$(GO_VERSION) \
--build-arg GIT_VERSION=$(VERSION) \
--build-arg GIT_COMMIT=$(COMMIT) \
--build-arg BUILDPLATFORM=linux/amd64 \
--build-arg GOOS=linux \
--build-arg GOARCH=amd64 \
-t mantlemint:local-amd64 \
--load \
-f Dockerfile .
$(DOCKER) rm -f mantlemint-builder || true
$(DOCKER) create -ti --name mantlemint-builder mantlemint:local-amd64
$(DOCKER) cp mantlemint-builder:/usr/local/bin/mantlemint $(BUILDDIR)/release/mantlemint
tar -czvf $(BUILDDIR)/release/mantlemint_$(VERSION)_Linux_x86_64.tar.gz -C $(BUILDDIR)/release/ mantlemint
rm $(BUILDDIR)/release/mantlemint
$(DOCKER) rm -f mantlemint-builder

build-release-arm64: go.sum $(BUILDDIR)/
$(DOCKER) buildx create --name mantlemint-builder || true
$(DOCKER) buildx use mantlemint-builder
$(DOCKER) buildx build \
--build-arg GO_VERSION=$(GO_VERSION) \
--build-arg GIT_VERSION=$(VERSION) \
--build-arg GIT_COMMIT=$(COMMIT) \
--build-arg BUILDPLATFORM=linux/arm64 \
--build-arg GOOS=linux \
--build-arg GOARCH=arm64 \
-t mantlemint:local-arm64 \
--load \
-f Dockerfile .
$(DOCKER) rm -f mantlemint-builder || true
$(DOCKER) create -ti --name mantlemint-builder mantlemint:local-arm64
$(DOCKER) cp mantlemint-builder:/usr/local/bin/mantlemint $(BUILDDIR)/release/mantlemint
tar -czvf $(BUILDDIR)/release/mantlemint_$(VERSION)_Linux_aarch64.tar.gz -C $(BUILDDIR)/release/ mantlemint
rm $(BUILDDIR)/release/mantlemint
$(DOCKER) rm -f mantlemint-builder

0 comments on commit 81abbd3

Please sign in to comment.