2022-09-20 18:53:30 +03:00
|
|
|
# syntax=docker/dockerfile:1.4.3-labs
|
2023-08-30 18:02:58 +03:00
|
|
|
FROM lukemathwalker/cargo-chef:0.1.62-rust-1.72-buster AS chef
|
2021-06-11 21:41:03 +03:00
|
|
|
WORKDIR app
|
2022-10-06 17:43:56 +03:00
|
|
|
|
|
|
|
FROM chef AS planner
|
2021-06-11 21:41:03 +03:00
|
|
|
COPY . .
|
|
|
|
RUN cargo chef prepare --recipe-path recipe.json
|
|
|
|
|
2022-10-06 17:43:56 +03:00
|
|
|
FROM chef AS builder
|
2021-06-11 21:41:03 +03:00
|
|
|
COPY --from=planner /app/recipe.json recipe.json
|
2022-11-20 16:18:49 +03:00
|
|
|
ENV CARGO_NET_GIT_FETCH_WITH_CLI=true
|
2021-06-11 21:41:03 +03:00
|
|
|
RUN cargo chef cook --release --recipe-path recipe.json
|
|
|
|
COPY . .
|
2022-04-24 14:13:47 +03:00
|
|
|
RUN cargo build --release --locked --no-default-features
|
2021-06-11 21:41:03 +03:00
|
|
|
RUN rm -f target/release/deps/git_cliff*
|
|
|
|
|
|
|
|
FROM debian:buster-slim as runner
|
2023-05-18 21:45:32 +03:00
|
|
|
|
|
|
|
# Everything inside this container will be explicitly mounted by the end user,
|
|
|
|
# so we can sidestep some Git security restrictions. This app recommends
|
|
|
|
# mounting data to /app, but this *can* be changed externally and *will* be
|
|
|
|
# changed when run by GitHub Actions, so we need to cover our bases.
|
|
|
|
RUN echo '[safe]\n\tdirectory = *' > /etc/gitconfig
|
|
|
|
|
2021-06-11 21:41:03 +03:00
|
|
|
COPY --from=builder /app/target/release/git-cliff /usr/local/bin
|
2023-05-18 21:45:32 +03:00
|
|
|
WORKDIR app
|
|
|
|
|
|
|
|
# Even if the repository as marked as safe, GitHub Actions and some other
|
|
|
|
# environments insist on running the entrypoint as root inside the container
|
2023-10-19 16:34:17 +03:00
|
|
|
# even when being run by a non privileged user on their own files. Here we
|
2023-05-18 21:45:32 +03:00
|
|
|
# check the ownership of the workdir (which may or may not be /app) and change
|
|
|
|
# our effective user/group ID to match.
|
|
|
|
RUN cat <<'EOF' > /usr/local/bin/entrypoint.sh
|
2022-09-20 18:53:30 +03:00
|
|
|
#!/bin/sh
|
2023-05-18 21:45:32 +03:00
|
|
|
if [ "$(id -u)" -ne "$(stat -c '%u' .)" ]; then
|
|
|
|
eids="$(stat -c '--euid %u --egid %g' .)"
|
|
|
|
fi
|
|
|
|
exec ${eids:+setpriv --clear-groups $eids} git-cliff $@
|
2022-09-20 18:53:30 +03:00
|
|
|
EOF
|
2023-05-18 21:45:32 +03:00
|
|
|
ENTRYPOINT ["sh", "/usr/local/bin/entrypoint.sh"]
|