-
Notifications
You must be signed in to change notification settings - Fork 2
/
Dockerfile
187 lines (155 loc) · 5.79 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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
# syntax=docker/dockerfile:1
# Define the Go version to use and the base image
ARG GO_VERSION="1.20"
ARG BUILDPLATFORM=linux/amd64
ARG BASE_IMAGE="golang:${GO_VERSION}-alpine3.18"
# Use the base image for the initial stage
FROM --platform=${BUILDPLATFORM} ${BASE_IMAGE} as base
###############################################################################
# Builder Stage 1
###############################################################################
# Inherit from the base stage
FROM base as builder-stage-1
# Define environment variables for the build process
ARG BUILDPLATFORM=linux/amd64
ARG GOOS=linux
ARG GOARCH=amd64
ENV GOOS=$GOOS
ENV GOARCH=$GOARCH
# Install necessary packages and dependencies
RUN set -eux &&\
apk update &&\
apk add --no-cache \
ca-certificates \
linux-headers \
build-base \
cmake \
git
# Clone and install mimalloc for musl
WORKDIR ${GOPATH}/src/mimalloc
RUN set -eux &&\
git clone --depth 1 --branch v2.1.2 \
https://github.com/microsoft/mimalloc . &&\
mkdir -p build &&\
cd build &&\
cmake .. &&\
make -j$(nproc) &&\
make install
# Clone the implementation repo
WORKDIR /code
RUN git clone --branch main --depth 1 https://github.com/mint-cash/terra-classic-core .
# Set the GIT_COMMIT and GIT_VERSION using Git commands
WORKDIR /code
RUN set -eux && \
GIT_COMMIT=$(git log -1 --format='%H') && \
GIT_VERSION=$(git describe --tags | sed 's/^v//') && \
echo "GIT_COMMIT=${GIT_COMMIT}" > .env && \
echo "GIT_VERSION=${GIT_VERSION}" >> .env
# Install dependencies using the go.mod and go.sum from the cloned repository
WORKDIR /code
RUN --mount=type=cache,target=/root/.cache/go-build \
--mount=type=cache,target=/root/go/pkg/mod \
go mod download -x
# Cosmwasm - Download the correct libwasmvm version and verify checksum
RUN set -eux &&\
WASMVM_VERSION=$(go list -m github.com/CosmWasm/wasmvm | cut -d ' ' -f 5) && \
WASMVM_DOWNLOADS="https://github.com/classic-terra/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"; \
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
###############################################################################
# Builder Stage 2
###############################################################################
FROM builder-stage-1 as builder-stage-2
# Import GIT_COMMIT and GIT_VERSION as arguments
ARG GIT_COMMIT
ARG GIT_VERSION
# Set environment variables for the build stage
ARG GOOS=linux
ARG GOARCH=amd64
ENV GOOS=$GOOS
ENV GOARCH=$GOARCH
# Build the application binary using the cloned source
WORKDIR /code
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='terra' \
-X github.com/cosmos/cosmos-sdk/version.AppName='terrad' \
-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 \
./...
################################################################################
# Final stage to build the terra-core image with Nginx setup
FROM alpine as terra-core
WORKDIR /app
# Install necessary packages including Nginx
RUN apk update && apk add wget lz4 aria2 curl jq gawk coreutils "zlib>1.2.12-r2" libssl3 nginx
# Create a non-root user and set permissions
RUN addgroup -g 1000 terra && \
adduser -u 1000 -G terra -D -h /app terra
# Setup Nginx and logs directory with correct permissions
RUN mkdir -p /var/lib/nginx/logs && \
chown -R terra:terra /var/lib/nginx && \
ln -sf /dev/stdout /var/lib/nginx/logs/access.log && \
ln -sf /dev/stderr /var/lib/nginx/logs/error.log
# Copy the built binary from the builder stage
COPY --from=builder-stage-2 /go/bin/terrad /usr/local/bin/terrad
# Setup localterra (columbus-5)
RUN set -eux &&\
mkdir -p /app/config && \
mkdir -p /app/data && \
chown -R terra:terra /app && \
terrad init columbus-5 \
--home /app \
--chain-id columbus-5 && \
echo '{"height": "0","round": 0,"step": 0}' > /app/data/priv_validator_state.json
# Copy the Nginx configuration, entrypoint script, and Terra configuration files
COPY --chmod=644 nginx.conf /etc/nginx/nginx.conf
COPY --chmod=755 entrypoint.sh /usr/local/bin/entrypoint.sh
COPY ./terra/priv_validator_key.json \
./terra/genesis.json \
/app/config/
# Set the entry point
ENTRYPOINT [ "entrypoint.sh" ]
# rest server
EXPOSE 1317
# grpc server
EXPOSE 9090
# tendermint p2p
EXPOSE 26656
# tendermint rpc
EXPOSE 26657
# Set the default command
CMD terrad start \
--home /app \
--minimum-gas-prices "0.01133uluna,0.15uusd,0.104938usdr,169.77ukrw,428.571umnt,0.125ueur,0.98ucny,16.37ujpy,0.11ugbp,10.88uinr,0.19ucad,0.14uchf,0.19uaud,0.2usgd,4.62uthb,1.25usek" \
--moniker columbus-5 \
--p2p.upnp true \
--rpc.laddr tcp://0.0.0.0:26657 \
--api.enable true \
--api.swagger true \
--api.address tcp://0.0.0.0:1317 \
--api.enabled-unsafe-cors true \
--grpc.enable true \
--grpc.address 0.0.0.0:9090 \
--grpc-web.enable \
--grpc-web.address 0.0.0.0:9091