Skip to content
This repository was archived by the owner on Mar 23, 2023. It is now read-only.

Commit d31cc3a

Browse files
committed
Refactor product contract Dockerfile
Signed-off-by: Ryan Beck-Buysse <[email protected]>
1 parent 622fa66 commit d31cc3a

File tree

1 file changed

+35
-27
lines changed

1 file changed

+35
-27
lines changed

contracts/product/Dockerfile

Lines changed: 35 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -22,21 +22,21 @@ RUN echo "deb http://repo.sawtooth.me/ubuntu/nightly bionic universe" >> /etc/ap
2222
&& (apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 44FC67F19B2466EA \
2323
|| apt-key adv --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys 44FC67F19B2466EA) \
2424
&& apt-get update \
25-
&& apt-get install -y -q \
26-
build-essential \
27-
curl \
28-
gcc \
29-
g++ \
30-
libpq-dev \
31-
libssl-dev \
32-
libsasl2-dev \
33-
libzmq3-dev \
34-
openssl \
35-
pkg-config \
36-
sabre-cli \
37-
unzip \
38-
&& apt-get clean \
39-
&& rm -rf /var/lib/apt/lists/*
25+
&& apt-get install -y -q \
26+
build-essential \
27+
curl \
28+
gcc \
29+
g++ \
30+
libpq-dev \
31+
libssl-dev \
32+
libsasl2-dev \
33+
libzmq3-dev \
34+
openssl \
35+
pkg-config \
36+
sabre-cli \
37+
unzip \
38+
&& apt-get clean \
39+
&& rm -rf /var/lib/apt/lists/*
4040

4141
ENV PATH=$PATH:/protoc3/bin:/root/.cargo/bin
4242

@@ -46,33 +46,41 @@ RUN curl https://sh.rustup.rs -sSf > /usr/bin/rustup-init \
4646
&& rustup-init -y
4747

4848
RUN rustup update \
49-
&& rustup default \
50-
&& rustup target add wasm32-unknown-unknown --toolchain stable
49+
&& rustup target add wasm32-unknown-unknown
5150

5251
# Install protoc
5352
RUN curl -OLsS https://github.com/google/protobuf/releases/download/v3.7.1/protoc-3.7.1-linux-x86_64.zip \
5453
&& unzip -o protoc-3.7.1-linux-x86_64.zip -d /usr/local \
5554
&& rm protoc-3.7.1-linux-x86_64.zip
5655

57-
COPY ./sdk /sdk
56+
RUN mkdir /build
5857

58+
# Copy grid sdk dependency
59+
COPY sdk/ /build/sdk/
60+
61+
# Create empty cargo project
62+
WORKDIR /build
5963
RUN mkdir contracts \
6064
&& USER=root cargo new --bin contracts/product
61-
WORKDIR /contracts/product
6265

63-
# Build TP with dummy source in order to cache dependencies in Docker image.
64-
COPY ./contracts/product/Cargo.toml ./Cargo.toml
65-
RUN cargo build --release
66+
# Copy over Cargo.toml file
67+
COPY contracts/product/Cargo.toml /build/contracts/product/Cargo.toml
6668

67-
COPY contracts/product/Cargo.toml contracts/product/Cargo.lock* ./
68-
RUN cargo build
69+
# Do a release build to cache dependencies
70+
WORKDIR /build/contracts/product
71+
RUN cargo build --release
6972

73+
# Remove the auto-generated .rs files and the built files
7074
RUN rm src/*.rs
71-
COPY ./contracts/product/src ./src
72-
7375
RUN rm ./target/release/grid-product-tp* ./target/release/deps/grid_product*
76+
77+
# Copy over source files
78+
COPY contracts/product/src /build/contracts/product/src
79+
80+
# Build the contract
7481
RUN cargo build --target wasm32-unknown-unknown --release
7582

76-
COPY ./contracts/product/product.yaml ./product.yaml
83+
# Copy the contract definition
84+
COPY contracts/product/product.yaml /build/contracts/product/product.yaml
7785

7886
ENTRYPOINT []

0 commit comments

Comments
 (0)