lemmy/docker/dev/Dockerfile

63 lines
1.5 KiB
Docker
Raw Permalink Normal View History

2021-05-03 14:46:12 +00:00
ARG RUST_BUILDER_IMAGE=ekidd/rust-musl-builder:1.51.0
2019-04-10 18:10:57 +00:00
# Cargo chef plan
FROM $RUST_BUILDER_IMAGE as planner
WORKDIR /app
2021-02-24 22:10:28 +00:00
RUN cargo install cargo-chef
# Copy dirs
COPY ./ ./
RUN sudo chown -R rust:rust .
RUN cargo chef prepare --recipe-path recipe.json
# Cargo chef cache dependencies
FROM $RUST_BUILDER_IMAGE as cacher
ARG CARGO_BUILD_TARGET=x86_64-unknown-linux-musl
WORKDIR /app
2021-02-24 22:10:28 +00:00
RUN cargo install cargo-chef
COPY --from=planner /app/recipe.json ./recipe.json
RUN sudo chown -R rust:rust .
RUN cargo chef cook --target ${CARGO_BUILD_TARGET} --recipe-path recipe.json
# Build the project
FROM $RUST_BUILDER_IMAGE as builder
ARG CARGO_BUILD_TARGET=x86_64-unknown-linux-musl
ARG RUSTRELEASEDIR="debug"
2020-09-02 15:42:48 +00:00
2020-10-24 15:23:45 +00:00
WORKDIR /app
2020-09-02 15:42:48 +00:00
# Copy over the cached dependencies
COPY --from=cacher /app/target target
COPY --from=cacher /home/rust/.cargo /home/rust/.cargo
# Copy the rest of the dirs
COPY ./ ./
RUN sudo chown -R rust:rust .
RUN echo "pub const VERSION: &str = \"$(git describe --tag)\";" > "crates/utils/src/version.rs"
RUN cargo build
2019-04-10 18:10:57 +00:00
# reduce binary size
RUN strip ./target/$CARGO_BUILD_TARGET/$RUSTRELEASEDIR/lemmy_server
2020-01-01 17:01:49 +00:00
RUN cp ./target/$CARGO_BUILD_TARGET/$RUSTRELEASEDIR/lemmy_server /app/lemmy_server
# The alpine runner
2021-08-17 20:31:16 +00:00
FROM alpine:3.14 as lemmy
# Install libpq for postgres
RUN apk add libpq
RUN addgroup -g 1000 lemmy
RUN adduser -D -s /bin/sh -u 1000 -G lemmy lemmy
# Copy resources
COPY --chown=lemmy:lemmy --from=builder /app/lemmy_server /app/lemmy
RUN chown lemmy:lemmy /app/lemmy
USER lemmy
EXPOSE 8536
CMD ["/app/lemmy"]