-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update Dockerfile to build in stages for caching
- Loading branch information
Showing
1 changed file
with
20 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,28 @@ | ||
FROM rust:1.62 | ||
|
||
WORKDIR /usr/src/oxen-server | ||
FROM rust:1.62 as builder | ||
|
||
USER root | ||
RUN apt-get update && apt-get install --assume-yes apt-utils | ||
RUN apt-get install -y libclang-dev | ||
RUN cargo install cargo-build-deps | ||
|
||
# create an empty project to install dependencies | ||
RUN cd /usr/src && cargo new --bin oxen-server | ||
WORKDIR /usr/src/oxen-server | ||
COPY Cargo.toml Cargo.lock ./ | ||
COPY src/lib/Cargo.toml src/lib/Cargo.toml | ||
COPY src/cli/Cargo.toml src/cli/Cargo.toml | ||
COPY src/server/Cargo.toml src/server/Cargo.toml | ||
# build just the deps for caching | ||
RUN cargo build-deps --release | ||
|
||
COPY . . | ||
RUN cargo install --path . | ||
# copy the rest of the source and build the server | ||
COPY src src | ||
RUN cargo build --release --bin oxen-server | ||
|
||
# Minimal image to run the binary (without Rust toolchain) | ||
FROM debian:bullseye-slim AS runtime | ||
WORKDIR /oxen-server | ||
COPY --from=builder /usr/src/oxen-server/target/release/oxen-server /usr/local/bin | ||
ENV SYNC_DIR=/var/oxen/data | ||
EXPOSE 3000 | ||
CMD ["oxen-server", "start"] | ||
CMD ["oxen-server", "start"] |