-
Notifications
You must be signed in to change notification settings - Fork 2
/
alpine.Dockerfile
141 lines (115 loc) · 4.11 KB
/
alpine.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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
ARG GO_VERSION="1.20"
################################################################################
FROM golang:${GO_VERSION}-alpine as base
# NOTE: add libusb-dev to run with LEDGER_ENABLED=true
RUN set -eu && \
apk update && \
apk add --no-cache \
bash \
bison \
build-base \
ca-certificates \
curl \
git \
gcompat \
linux-headers \
lz4-static \
lz4-dev \
musl-dev \
perl \
snappy-static \
snappy-dev \
zlib-static \
zlib-dev
COPY ./bin/install-mimalloc ./bin/install-wasmvm ./bin/install-rocksdb /usr/local/bin/
################################################################################
FROM base as builder
ARG APP_NAME="terra"
ARG BIN_NAME="${APP_NAME}d"
ARG COSMOS_BUILD_OPTIONS="nostrip"
ARG DENOM
ARG GIT_TAG="v2.4.1"
ARG GIT_REPO="terra-money/core"
ARG MIMALLOC_VERSION
ARG ROCKSDB_VERSION
ARG GO_VERSION
ENV MIMALLOC_VERSION=${MIMALLOC_VERSION}
# install mimalloc if version is specified
RUN set -eu && \
if [ -n "${MIMALLOC_VERSION}" ]; then install-mimalloc "${MIMALLOC_VERSION}"; fi
ENV ROCKSDB_VERSION=${ROCKSDB_VERSION}
# install rocksdb if version is specified
RUN set -eu && \
if [ -n "${ROCKSDB_VERSION}" ]; then install-rocksdb "${ROCKSDB_VERSION}"; fi
# download dependencies to cache as layer
WORKDIR ${GOPATH}/src/app
ENV GIT_TAG=${GIT_TAG} \
GIT_REPO=${GIT_REPO}
SHELL [ "/bin/bash", "-c" ]
RUN set -e && \
git clone -b ${GIT_TAG} https://github.com/${GIT_REPO}.git ./ && \
# export GO_MOD_VERSION="$(awk '/^go /{print $2}' go.mod)" && \
# if [[ "${GO_VERSION}" != "${GO_MOD_VERSION}"* ]]; then \
# /bin/bash < <(curl -sSL https://raw.githubusercontent.com/moovweb/gvm/master/binscripts/gvm-installer) && \
# source ${HOME}/.gvm/scripts/gvm && \
# gvm install go${GO_MOD_VERSION} && \
# gvm use go${GO_MOD_VERSION}; \
# fi && \
go mod download -x || true
# download wasmvm if version is specified
RUN set -ux && \
WASMVM_VERSION="$(go list -m github.com/CosmWasm/wasmvm | cut -d ' ' -f 2)" && \
[ -n "${WASMVM_VERSION}" ] && install-wasmvm "${WASMVM_VERSION}" || true
# build the binary
ARG BUILD_COMMAND="make install"
ARG BUILD_TAGS="netgo,ledger,muslc"
ARG BUILD_TAGS=""
ARG LDFLAGS='-w -s -linkmode external -extldflags "-Wl,-z,muldefs -static"'
#ARG LDFLAGS="-extldflags '-L/go/src/mimalloc/build -lmimalloc -Wl,-z,muldefs -static'"
ARG CHECK_STATICALLY="true"
ENV APP_NAME=${APP_NAME} \
BUILD_COMMAND=${BUILD_COMMAND} \
DENOM=${DENOM} \
LDFLAGS=${LDFLAGS} \
LEDGER_ENABLED=false \
LINK_STATICALLY=true
RUN --mount=type=cache,target=/root/.cache/go-build \
--mount=type=cache,target=/root/go/pkg/mod \
set -eux && \
export COMMIT=GIT_COMMIT="$(git log -1 --format='%h')" && \
export VERSION=GIT_VERSION="$(git describe --tags --dirty --always)" && \
export DENOM=${DENOM:-"u$(echo ${APP_NAME} | head -c 4)"} && \
export GOWORK=off && \
eval ${BUILD_COMMAND}
# verify static binary
RUN set -x && \
file ${GOPATH}/bin/${BIN_NAME} && \
if [ "${CHECK_STATICALLY}" = "true" ]; then \
echo "Ensuring binary is statically linked ..." && \
(file ${GOPATH}/bin/${BIN_NAME} | grep "statically linked"); \
fi
################################################################################
FROM --platform=${BUILDPLATFORM} alpine:latest as prod
# build args passed down to env var
ARG APP_NAME="terra"
ARG BIN_NAME="${APP_NAME}d"
ARG CHAIN_REGISTRY_NAME
ENV APP_NAME=${APP_NAME} \
BIN_NAME=${BIN_NAME} \
CHAIN_REGISTRY_NAME=${CHAIN_REGISTRY_NAME}
# copy binary and entrypoint
COPY --from=builder /go/bin/${BIN_NAME} /usr/local/bin/${BIN_NAME}
COPY ./bin/entrypoint.sh /usr/local/bin/
# install jq and create user
RUN set -eux && \
apk update && \
apk add --no-cache bash curl jq && \
addgroup -g 1000 ${APP_NAME} && \
adduser -u 1000 -G ${APP_NAME} -D -s /bin/bash -h /home/${APP_NAME} ${APP_NAME} && \
ln -s /usr/local/bin/${BIN_NAME} /usr/local/bin/chaind
# setup execution environment
USER ${APP_NAME}
SHELL [ "/bin/bash" ]
WORKDIR /home/${APP_NAME}
ENTRYPOINT [ "entrypoint.sh" ]
CMD ["chaind", "start"]