From 22a33929e26299695fd4ea113401851d4faa852f Mon Sep 17 00:00:00 2001 From: Dessalines Date: Mon, 13 Jul 2020 12:31:06 -0400 Subject: [PATCH] Adding docker workspace caching. Fixes #940 (#958) --- docker/dev/Dockerfile | 14 ++++---------- docker/prod/Dockerfile | 19 +++++++------------ 2 files changed, 11 insertions(+), 22 deletions(-) diff --git a/docker/dev/Dockerfile b/docker/dev/Dockerfile index 4445e4feb..b86618d85 100644 --- a/docker/dev/Dockerfile +++ b/docker/dev/Dockerfile @@ -17,20 +17,14 @@ WORKDIR /app RUN sudo chown -R rust:rust . RUN USER=root cargo new server WORKDIR /app/server -RUN mkdir -p lemmy_db/src/ lemmy_utils/src/ COPY server/Cargo.toml server/Cargo.lock ./ -COPY server/lemmy_db/Cargo.toml ./lemmy_db/ -COPY server/lemmy_utils/Cargo.toml ./lemmy_utils/ -RUN sudo chown -R rust:rust . +COPY server/lemmy_db ./lemmy_db +COPY server/lemmy_utils ./lemmy_utils RUN mkdir -p ./src/bin \ - && echo 'fn main() { println!("Dummy") }' > ./src/bin/main.rs \ - && cp ./src/bin/main.rs ./lemmy_db/src/main.rs \ - && cp ./src/bin/main.rs ./lemmy_utils/src/main.rs + && echo 'fn main() { println!("Dummy") }' > ./src/bin/main.rs RUN cargo build -RUN rm -f ./target/x86_64-unknown-linux-musl/release/deps/lemmy_server* +RUN find target/debug -type f -name "$(echo "lemmy_server" | tr '-' '_')*" -exec touch -t 200001010000 {} + COPY server/src ./src/ -COPY server/lemmy_db ./lemmy_db/ -COPY server/lemmy_utils ./lemmy_utils/ COPY server/migrations ./migrations/ # Build for debug diff --git a/docker/prod/Dockerfile b/docker/prod/Dockerfile index 9000ca3a8..774387404 100644 --- a/docker/prod/Dockerfile +++ b/docker/prod/Dockerfile @@ -10,20 +10,15 @@ WORKDIR /app RUN sudo chown -R rust:rust . RUN USER=root cargo new server WORKDIR /app/server -RUN mkdir -p lemmy_db/src/ lemmy_utils/src/ -COPY --chown=rust:rust server/Cargo.toml server/Cargo.lock ./ -COPY --chown=rust:rust server/lemmy_db/Cargo.toml ./lemmy_db/ -COPY --chown=rust:rust server/lemmy_utils/Cargo.toml ./lemmy_utils/ +COPY server/Cargo.toml server/Cargo.lock ./ +COPY server/lemmy_db ./lemmy_db +COPY server/lemmy_utils ./lemmy_utils RUN mkdir -p ./src/bin \ - && echo 'fn main() { println!("Dummy") }' > ./src/bin/main.rs \ - && cp ./src/bin/main.rs ./lemmy_db/src/main.rs \ - && cp ./src/bin/main.rs ./lemmy_utils/src/main.rs + && echo 'fn main() { println!("Dummy") }' > ./src/bin/main.rs RUN cargo build --release -RUN rm -f ./target/$CARGO_BUILD_TARGET/$RUSTRELEASEDIR/deps/lemmy_server* -COPY --chown=rust:rust server/src ./src/ -COPY --chown=rust:rust server/lemmy_db ./lemmy_db/ -COPY --chown=rust:rust server/lemmy_utils ./lemmy_utils/ -COPY --chown=rust:rust server/migrations ./migrations/ +RUN find target/$CARGO_BUILD_TARGET/$RUSTRELEASEDIR -type f -name "$(echo "lemmy_server" | tr '-' '_')*" -exec touch -t 200001010000 {} + +COPY server/src ./src/ +COPY server/migrations ./migrations/ # build for release # workaround for https://github.com/rust-lang/rust/issues/62896