Skip to content

Commit 1f58ab2

Browse files
committed
Add a Dockerfile to hack
1 parent 9b4b058 commit 1f58ab2

File tree

4 files changed

+244
-8
lines changed

4 files changed

+244
-8
lines changed

hacking/Dockerfile

Lines changed: 236 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,236 @@
1+
# syntax=docker/dockerfile:1.4
2+
# To try and avoid the dockerfile clutter I've included everything in this single file
3+
# To use you want to choose a specific target based on your use case:
4+
#
5+
# `--target release-image` - a full node docker image
6+
# `--target build-deb` - the image used to generate a .deb package
7+
# `--target build-deb-mainnet` - the image used to generate deb package for mainnet (will pull precompiled enclave)
8+
# `--target compile-secretd` - image with compiled enclave and secretd
9+
10+
ARG SCRT_BASE_IMAGE_SECRETD=enigmampc/rocksdb:v6.24.2-1.1.5
11+
ARG TEST=enigmampc/rocksdb:v6.24.2
12+
ARG SCRT_BASE_IMAGE_ENCLAVE=enigmampc/rocksdb:v6.24.2-1.1.5
13+
ARG SCRT_RELEASE_BASE_IMAGE=enigmampc/enigma-sgx-base:2004-1.1.5
14+
15+
# ***************** PREPARE COMPILE ENCLAVE ************** #
16+
17+
FROM $SCRT_BASE_IMAGE_ENCLAVE AS prepare-compile-enclave
18+
19+
RUN apt-get update && \
20+
apt-get install -y --no-install-recommends \
21+
clang-10 && \
22+
rm -rf /var/lib/apt/lists/*
23+
24+
ENV PATH="/root/.cargo/bin:$PATH"
25+
26+
# Set working directory for the build
27+
WORKDIR /go/src/github.com/enigmampc/SecretNetwork/
28+
29+
COPY rust-toolchain rust-toolchain
30+
RUN rustup component add rust-src
31+
RUN --mount=type=cache,target=/root/.cargo/registry cargo install xargo --version 0.3.25
32+
33+
# Add submodules
34+
COPY third_party third_party
35+
36+
# Add source files
37+
COPY go-cosmwasm go-cosmwasm/
38+
COPY cosmwasm cosmwasm/
39+
40+
# ***************** COMPILE ENCLAVE ************** #
41+
42+
FROM prepare-compile-enclave AS compile-enclave
43+
44+
ARG BUILD_VERSION="v0.0.0"
45+
ARG SGX_MODE=SW
46+
ARG FEATURES
47+
ARG FEATURES_U
48+
ARG MITIGATION_CVE_2020_0551=LOAD
49+
50+
ENV VERSION=${BUILD_VERSION}
51+
ENV SGX_MODE=${SGX_MODE}
52+
ENV FEATURES=${FEATURES}
53+
ENV FEATURES_U=${FEATURES_U}
54+
ENV MITIGATION_CVE_2020_0551=${MITIGATION_CVE_2020_0551}
55+
56+
WORKDIR /go/src/github.com/enigmampc/SecretNetwork/go-cosmwasm
57+
58+
RUN --mount=type=cache,target=/root/.cargo/registry . /opt/sgxsdk/environment && env \
59+
&& MITIGATION_CVE_2020_0551={MITIGATION_CVE_2020_0551} VERSION=${VERSION} FEATURES=${FEATURES} FEATURES_U=${FEATURES_U} SGX_MODE=${SGX_MODE} make build-rust
60+
61+
ENTRYPOINT ["/bin/bash"]
62+
63+
# ***************** COMPILE SECRETD ************** #
64+
FROM $TEST AS compile-secretd
65+
66+
ENV GOROOT=/usr/local/go
67+
ENV GOPATH=/go/
68+
ENV PATH=$PATH:/usr/local/go/bin:$GOPATH/bin
69+
70+
ADD https://go.dev/dl/go1.19.linux-amd64.tar.gz go.linux-amd64.tar.gz
71+
RUN tar -C /usr/local -xzf go.linux-amd64.tar.gz
72+
RUN go install github.com/jteeuwen/go-bindata/go-bindata@latest && go-bindata -version
73+
74+
# Set working directory for the build
75+
WORKDIR /go/src/github.com/enigmampc/SecretNetwork
76+
77+
ARG BUILD_VERSION="v0.0.0"
78+
ARG SGX_MODE=SW
79+
ARG FEATURES
80+
ARG FEATURES_U
81+
ARG DB_BACKEND=goleveldb
82+
ARG CGO_LDFLAGS
83+
84+
ENV VERSION=${BUILD_VERSION}
85+
ENV SGX_MODE=${SGX_MODE}
86+
ENV FEATURES=${FEATURES}
87+
ENV FEATURES_U=${FEATURES_U}
88+
ENV CGO_LDFLAGS=${CGO_LDFLAGS}
89+
90+
# Add source files
91+
COPY go-cosmwasm go-cosmwasm
92+
COPY cosmos-sdk cosmos-sdk
93+
94+
# This is due to some esoteric docker bug with the underlying filesystem, so until I figure out a better way, this should be a workaround
95+
RUN true
96+
COPY x x
97+
RUN true
98+
COPY types types
99+
RUN true
100+
COPY app app
101+
COPY go.mod .
102+
COPY go.sum .
103+
COPY cmd cmd
104+
COPY Makefile .
105+
RUN true
106+
COPY client client
107+
108+
RUN ln -s /usr/lib/x86_64-linux-gnu/liblz4.so /usr/local/lib/liblz4.so && ln -s /usr/lib/x86_64-linux-gnu/libzstd.so /usr/local/lib/libzstd.so
109+
110+
RUN mkdir -p /go/src/github.com/enigmampc/SecretNetwork/go-cosmwasm/target/release/
111+
112+
COPY --from=compile-enclave /go/src/github.com/enigmampc/SecretNetwork/go-cosmwasm/target/release/libgo_cosmwasm.so /go/src/github.com/enigmampc/SecretNetwork/go-cosmwasm/target/release/libgo_cosmwasm.so
113+
COPY --from=compile-enclave /go/src/github.com/enigmampc/SecretNetwork/go-cosmwasm/librust_cosmwasm_enclave.signed.so /go/src/github.com/enigmampc/SecretNetwork/go-cosmwasm/librust_cosmwasm_enclave.signed.so
114+
# COPY --from=compile-enclave /go/src/github.com/enigmampc/SecretNetwork/go-cosmwasm/librust_cosmwasm_query_enclave.signed.so /go/src/github.com/enigmampc/SecretNetwork/go-cosmwasm/librust_cosmwasm_query_enclave.signed.so
115+
116+
RUN mkdir -p /go/src/github.com/enigmampc/SecretNetwork/ias_keys/develop
117+
RUN mkdir -p /go/src/github.com/enigmampc/SecretNetwork/ias_keys/sw_dummy
118+
RUN mkdir -p /go/src/github.com/enigmampc/SecretNetwork/ias_keys/production
119+
120+
RUN --mount=type=secret,id=SPID,dst=/run/secrets/spid.txt cat /run/secrets/spid.txt > /go/src/github.com/enigmampc/SecretNetwork/ias_keys/develop/spid.txt
121+
RUN --mount=type=secret,id=SPID,dst=/run/secrets/spid.txt cat /run/secrets/spid.txt > /go/src/github.com/enigmampc/SecretNetwork/ias_keys/sw_dummy/spid.txt
122+
RUN --mount=type=secret,id=SPID,dst=/run/secrets/spid.txt cat /run/secrets/spid.txt > /go/src/github.com/enigmampc/SecretNetwork/ias_keys/production/spid.txt
123+
124+
RUN --mount=type=secret,id=API_KEY,dst=/run/secrets/api_key.txt cat /run/secrets/api_key.txt > /go/src/github.com/enigmampc/SecretNetwork/ias_keys/develop/api_key.txt
125+
RUN --mount=type=secret,id=API_KEY,dst=/run/secrets/api_key.txt cat /run/secrets/api_key.txt > /go/src/github.com/enigmampc/SecretNetwork/ias_keys/sw_dummy/api_key.txt
126+
RUN --mount=type=secret,id=API_KEY,dst=/run/secrets/api_key.txt cat /run/secrets/api_key.txt > /go/src/github.com/enigmampc/SecretNetwork/ias_keys/production/api_key.txt
127+
128+
RUN . /opt/sgxsdk/environment && env && CGO_LDFLAGS=${CGO_LDFLAGS} DB_BACKEND=${DB_BACKEND} VERSION=${VERSION} FEATURES=${FEATURES} SGX_MODE=${SGX_MODE} make build_local_no_rust
129+
RUN . /opt/sgxsdk/environment && env && VERSION=${VERSION} FEATURES=${FEATURES} SGX_MODE=${SGX_MODE} make build_cli
130+
131+
FROM scratch as secret-artifacts
132+
COPY --from=compile-secretd /go/src/github.com/enigmampc/SecretNetwork/go-cosmwasm/target/release/libgo_cosmwasm.so .
133+
COPY --from=compile-secretd /go/src/github.com/enigmampc/SecretNetwork/go-cosmwasm/librust_cosmwasm_enclave.signed.so .
134+
COPY --from=compile-secretd /go/src/github.com/enigmampc/SecretNetwork/secretd .
135+
136+
# ******************* RELEASE IMAGE ******************** #
137+
#FROM $SCRT_RELEASE_BASE_IMAGE as release-image
138+
FROM compile-secretd as release-image
139+
140+
# wasmi-sgx-test script requirements
141+
RUN apt-get update && \
142+
apt-get install -y --no-install-recommends \
143+
#### Base utilities ####
144+
jq \
145+
openssl \
146+
curl \
147+
wget \
148+
libsnappy-dev \
149+
libgflags-dev \
150+
bash-completion
151+
152+
RUN echo "source /etc/profile.d/bash_completion.sh" >> ~/.bashrc
153+
154+
RUN curl -sL https://deb.nodesource.com/setup_16.x | bash - && \
155+
apt-get install -y nodejs && \
156+
rm -rf /var/lib/apt/lists/* && \
157+
npm i -g local-cors-proxy
158+
159+
ARG SGX_MODE=SW
160+
ENV SGX_MODE=${SGX_MODE}
161+
162+
ARG SECRET_NODE_TYPE=NODE
163+
ENV SECRET_NODE_TYPE=${SECRET_NODE_TYPE}
164+
165+
ENV PKG_CONFIG_PATH=""
166+
ENV SCRT_ENCLAVE_DIR=/usr/lib/
167+
168+
# workaround because paths seem kind of messed up
169+
RUN ln -s /opt/sgxsdk/lib64/libsgx_urts_sim.so /usr/lib/x86_64-linux-gnu/libsgx_urts_sim.so
170+
RUN ln -s /opt/sgxsdk/lib64/libsgx_uae_service_sim.so /usr/lib/x86_64-linux-gnu/libsgx_uae_service_sim.so
171+
172+
# Install ca-certificates
173+
WORKDIR /root
174+
175+
# Copy over binaries from the build-env
176+
#COPY --from=compile-secretd /go/src/github.com/enigmampc/SecretNetwork/go-cosmwasm/target/release/libgo_cosmwasm.so /usr/lib/
177+
#COPY --from=compile-secretd /go/src/github.com/enigmampc/SecretNetwork/go-cosmwasm/librust_cosmwasm_enclave.signed.so /usr/lib/
178+
#COPY --from=compile-secretd /go/src/github.com/enigmampc/SecretNetwork/secretd /usr/bin/secretd
179+
RUN cp /go/src/github.com/enigmampc/SecretNetwork/go-cosmwasm/target/release/libgo_cosmwasm.so /usr/lib/
180+
RUN cp /go/src/github.com/enigmampc/SecretNetwork/go-cosmwasm/librust_cosmwasm_enclave.signed.so /usr/lib/
181+
RUN cp /go/src/github.com/enigmampc/SecretNetwork/secretd /usr/bin/secretd
182+
183+
COPY deployment/docker/testnet/bootstrap_init.sh .
184+
COPY deployment/docker/testnet/node_init.sh .
185+
COPY deployment/docker/testnet/startup.sh .
186+
COPY deployment/docker/testnet/node_key.json .
187+
COPY deployment/docker/localsecret/faucet/faucet_server.js .
188+
189+
RUN chmod +x /usr/bin/secretd
190+
RUN chmod +x bootstrap_init.sh
191+
RUN chmod +x startup.sh
192+
RUN chmod +x node_init.sh
193+
194+
RUN secretd completion > /root/secretd_completion
195+
196+
RUN echo "SECRET_NODE_TYPE=${SECRET_NODE_TYPE}" >> ~/.bashrc
197+
RUN echo 'source /root/secretd_completion' >> ~/.bashrc
198+
199+
RUN mkdir -p /root/.secretd/.compute/
200+
RUN mkdir -p /opt/secret/.sgx_secrets/
201+
RUN mkdir -p /root/.secretd/.node/
202+
RUN mkdir -p /root/config/
203+
204+
205+
####### Node parameters
206+
ARG MONIKER=default
207+
ARG CHAINID=secretdev-1
208+
ARG GENESISPATH=https://raw.githubusercontent.com/enigmampc/SecretNetwork/master/secret-testnet-genesis.json
209+
ARG PERSISTENT_PEERS=201cff36d13c6352acfc4a373b60e83211cd3102@bootstrap.southuk.azure.com:26656
210+
211+
ENV GENESISPATH="${GENESISPATH}"
212+
ENV CHAINID="${CHAINID}"
213+
ENV MONIKER="${MONIKER}"
214+
ENV PERSISTENT_PEERS="${PERSISTENT_PEERS}"
215+
216+
#ENV LD_LIBRARY_PATH=/opt/sgxsdk/libsgx-enclave-common/:/opt/sgxsdk/lib64/
217+
218+
# Run secretd by default, omit entrypoint to ease using container with secretcli
219+
ENTRYPOINT ["/bin/bash", "startup.sh"]
220+
221+
222+
# ***************** LOCALSECRET ************** #
223+
FROM release-image as build-localsecret
224+
225+
COPY deployment/docker/localsecret/bootstrap_init_no_stop.sh bootstrap_init.sh
226+
227+
RUN chmod +x bootstrap_init.sh
228+
229+
COPY deployment/docker/localsecret/faucet/faucet_server.js .
230+
231+
HEALTHCHECK --interval=5s --timeout=1s --retries=120 CMD bash -c 'curl -sfm1 http://localhost:26657/status && curl -s http://localhost:26657/status | jq -e "(.result.sync_info.latest_block_height | tonumber) > 0"'
232+
233+
#ENTRYPOINT ["./bootstrap_init.sh"]
234+
COPY hacking/scripts ./scripts
235+
RUN chmod +x ./scripts/startup.sh
236+
ENTRYPOINT ["./scripts/startup.sh"]

hacking/docker-compose.yml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ services:
44
image: devlocalsecret
55
build:
66
context: ..
7-
dockerfile: deployment/dockerfiles/Dockerfile
7+
dockerfile: hacking/Dockerfile
88
target: build-localsecret
99
args:
1010
#BUILD_VERSION: ${VERSION}
@@ -31,15 +31,15 @@ services:
3131
SECRET_NODE_TYPE: BOOTSTRAP
3232
# NOTE: mount source code that may be changed and rebuilt in a container
3333
volumes:
34-
- ../go-cosmwasm/src:/go/src/github.com/enigmampc/SecretNetwork/go-cosmwasm/src
34+
# - ../go-cosmwasm/src:/go/src/github.com/enigmampc/SecretNetwork/go-cosmwasm/src
3535
- ./secretd-1:/root/.secretd/
3636
- ./scripts/:/root/scripts
3737

3838
localsecret-2:
3939
image: devlocalsecret
4040
build:
4141
context: ..
42-
dockerfile: deployment/dockerfiles/Dockerfile
42+
dockerfile: hacking/Dockerfile
4343
target: build-localsecret
4444
args:
4545
#BUILD_VERSION: ${VERSION}
@@ -67,11 +67,11 @@ services:
6767
DUMMY_STORE: "true"
6868
# NOTE: mount source code that may be changed and rebuilt in a container
6969
volumes:
70-
- ../go-cosmwasm/src:/go/src/github.com/enigmampc/SecretNetwork/go-cosmwasm/src
71-
- ../go-cosmwasm/api:/go/src/github.com/enigmampc/SecretNetwork/go-cosmwasm/api
72-
- ../app:/go/src/github.com/enigmampc/SecretNetwork/app
73-
- ../proto:/go/src/github.com/enigmampc/SecretNetwork/proto
74-
- ../x:/go/src/github.com/enigmampc/SecretNetwork/x
70+
# - ../go-cosmwasm/src:/go/src/github.com/enigmampc/SecretNetwork/go-cosmwasm/src
71+
# - ../go-cosmwasm/api:/go/src/github.com/enigmampc/SecretNetwork/go-cosmwasm/api
72+
# - ../app:/go/src/github.com/enigmampc/SecretNetwork/app
73+
# - ../proto:/go/src/github.com/enigmampc/SecretNetwork/proto
74+
# - ../x:/go/src/github.com/enigmampc/SecretNetwork/x
7575
- ./scripts/:/root/scripts
7676
- ./secretd-2:/root/.secretd/
7777
- ./genesis:/tmp/genesis

hacking/scripts/startup.sh

100644100755
File mode changed.

hacking/scripts/test_swap.sh

100644100755
File mode changed.

0 commit comments

Comments
 (0)