-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile
117 lines (95 loc) · 3.59 KB
/
Dockerfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# syntax=docker/dockerfile:1
ARG GO_VERSION="1.18.10"
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 GIT_COMMIT
ARG GIT_VERSION
ARG BUILDPLATFORM
ARG GOOS=linux \
GOARCH=amd64
ENV GOOS=$GOOS \
GOARCH=$GOARCH
# NOTE: add libusb-dev to run with LEDGER_ENABLED=true
RUN set -eux &&\
apk update &&\
apk add --no-cache \
ca-certificates \
linux-headers \
build-base \
cmake \
git
# install mimalloc for musl
WORKDIR ${GOPATH}/src/mimalloc
RUN set -eux &&\
git clone --depth 1 --branch v2.0.9 \
https://github.com/microsoft/mimalloc . &&\
mkdir -p build &&\
cd build &&\
cmake .. &&\
make -j$(nproc) &&\
make install
# download dependencies to cache as layer
WORKDIR ${GOPATH}/src/app
COPY go.mod go.sum ./
RUN --mount=type=cache,target=/root/.cache/go-build \
--mount=type=cache,target=/root/go/pkg/mod \
go mod download -x
# Cosmwasm - Download correct libwasmvm version
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}"; \
wget ${WASMVM_DOWNLOADS}/checksums.txt -O /tmp/checksums.txt; \
if [ ${BUILDPLATFORM} = "linux/amd64" ]; then \
WASMVM_URL="${WASMVM_DOWNLOADS}/libwasmvm_muslc.x86_64.a"; \
elif [ ${BUILDPLATFORM} = "linux/arm64" ]; then \
WASMVM_URL="${WASMVM_DOWNLOADS}/libwasmvm_muslc.aarch64.a"; \
# elif [ ${BUILDPLATFORM} = "darwin/amd64" ]; then \
# WASMVM_URL="${WASMVM_DOWNLOADS}/libwasmvm.dylib"; \
# elif [ ${BUILDPLATFORM} = "darwin/arm64" ]; then \
# WASMVM_URL="${WASMVM_DOWNLOADS}/libwasmvm.dylib"; \
else \
echo "Unsupported Build Platfrom ${BUILDPLATFORM}"; \
exit 1; \
fi; \
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
###############################################################################
FROM builder-stage-1 as builder-stage-2
ARG GOOS=linux \
GOARCH=amd64
ENV GOOS=$GOOS \
GOARCH=$GOARCH
# Copy the remaining files
COPY . .
# Build app binary
RUN --mount=type=cache,target=/root/.cache/go-build \
--mount=type=cache,target=/root/go/pkg/mod \
go install \
-mod=readonly \
-tags "netgo,muslc" \
-ldflags " \
-w -s -linkmode=external -extldflags \
'-L/go/src/mimalloc/build -lmimalloc -Wl,-z,muldefs -static' \
-X github.com/cosmos/cosmos-sdk/version.Name='merlind' \
-X github.com/cosmos/cosmos-sdk/version.AppName='merlind' \
-X github.com/cosmos/cosmos-sdk/version.Version=${GIT_VERSION} \
-X github.com/cosmos/cosmos-sdk/version.Commit=${GIT_COMMIT} \
-X github.com/cosmos/cosmos-sdk/version.BuildTags='netgo,muslc' \
" \
-trimpath \
./...
################################################################################
FROM alpine:${ALPINE_VERSION} as merlin-chain
COPY --from=builder-stage-2 /go/bin/merlind /usr/local/bin/merlind
RUN addgroup -g 1000 merlin-chain && \
adduser -u 1000 -G merlin-chain -D -h /app merlin-chain
WORKDIR /app
CMD ["merlind", "--home", "/app", "start"]