Refactor pike contract Dockerfile
@@ -17,6 +17,7 @@ FROM ubuntu:bionic as grid-pike-builder
RUN apt-get update \
&& apt-get install gnupg -y
+# Install base dependencies
RUN echo "deb http://repo.sawtooth.me/ubuntu/nightly bionic universe" >> /etc/apt/sources.list \
&& (apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 44FC67F19B2466EA \
|| apt-key adv --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys 44FC67F19B2466EA) \
@@ -47,25 +48,34 @@ RUN curl -OLsS https://github.com/google/protobuf/releases/download/v3.7.1/proto
&& unzip -o protoc-3.7.1-linux-x86_64.zip -d /usr/local \
&& rm protoc-3.7.1-linux-x86_64.zip
-COPY ./sdk /sdk
+RUN mkdir /build
+# Copy grid sdk dependency
+COPY sdk/ /build/sdk/
+
+# Create empty cargo project
+WORKDIR /build
RUN mkdir contracts \
&& USER=root cargo new --bin contracts/pike
-WORKDIR /contracts/pike
-# Build TP with dummy source in order to cache dependencies in Docker image.
-COPY ./contracts/pike/Cargo.toml ./Cargo.toml
-RUN cargo build --release
+# Copy over Cargo.toml file
+COPY contracts/pike/Cargo.toml /build/contracts/pike/Cargo.toml
-COPY contracts/pike/Cargo.toml contracts/pike/Cargo.lock* ./
-RUN cargo build
+# Do a release build to cache dependencies
+WORKDIR /build/contracts/pike
+RUN cargo build --release
+# Remove the auto-generated .rs files and the built files
RUN rm src/*.rs
-COPY ./contracts/pike/src ./src
+RUN rm target/release/grid-pike-tp* target/release/deps/grid_pike*
+
+# Copy over source files
+COPY contracts/pike/src /build/contracts/pike/src
-RUN rm ./target/release/grid-pike-tp* ./target/release/deps/grid_pike*
+# Build the contract
RUN cargo build --target wasm32-unknown-unknown --release
-COPY ./contracts/pike/pike.yaml ./pike.yaml
+# Copy the contract definition
+COPY contracts/pike/pike.yaml /build/contracts/pike/pike.yaml
ENTRYPOINT []
