Refactor daemon Dockerfile
@@ -43,35 +43,42 @@ RUN curl -OLsS https://github.com/google/protobuf/releases/download/v3.7.1/proto
ENV PATH=$PATH:/root/.cargo/bin
+RUN mkdir /build
+
# Copy grid sdk dependency
-COPY ./sdk/ ../sdk/
+COPY sdk/ /build/sdk/
+# Create empty cargo projects
+WORKDIR /build
RUN USER=root cargo new --bin daemon
-WORKDIR /daemon
-
-COPY ./daemon/Cargo.toml ./Cargo.toml
-RUN cargo build --release
-
-RUN rm src/*.rs
-COPY ./daemon/src ./src
-COPY ./daemon/migrations ./migrations
-COPY ./daemon/migrations ../daemon/migrations
+RUN USER=root cargo new --bin cli
+# Copy over Cargo.toml files
+COPY daemon/Cargo.toml /build/daemon/Cargo.toml
+COPY cli/Cargo.toml /build/cli/Cargo.toml
-RUN rm ./target/release/gridd* ./target/release/deps/gridd*
+# Do a release build to cache dependencies
+WORKDIR /build/daemon
RUN cargo build --release
-
-WORKDIR ..
-RUN USER=root cargo new --bin cli
-WORKDIR /cli
-
-COPY ./cli/Cargo.toml ./Cargo.toml
+WORKDIR /build/cli
RUN cargo build --release
-RUN rm src/*.rs
-COPY ./cli/src ./src
+# Remove the auto-generated .rs files and the built files
+WORKDIR /build
+RUN rm */src/*.rs
+RUN rm daemon/target/release/gridd* daemon/target/release/deps/gridd*
+RUN rm cli/target/release/grid* cli/target/release/deps/grid*
+
+# Copy over source files
+COPY sdk/src /build/sdk/src
+COPY daemon/src /build/daemon/src
+COPY daemon/migrations /build/daemon/migrations
+COPY cli/src /build/cli/src
-RUN rm ./target/release/grid* ./target/release/deps/grid*
+# Build the projects
+WORKDIR /build/daemon
+RUN cargo build --release
+WORKDIR /build/cli
RUN cargo build --release
# create the standalone image
@@ -82,8 +89,7 @@ RUN apt-get update \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
-COPY --from=BUILDER /daemon/target/release/gridd /
-COPY --from=BUILDER /cli/target/release/grid /
-
+COPY --from=BUILDER /build/daemon/target/release/gridd /usr/sbin/gridd
+COPY --from=BUILDER /build/cli/target/release/grid /usr/bin/grid
-CMD ["/gridd"]
+CMD ["gridd"]
