diff --git a/Dockerfile b/Dockerfile index 194bfbce28..9efbc1a362 100644 --- a/Dockerfile +++ b/Dockerfile @@ -15,12 +15,26 @@ RUN cargo build --release --locked --no-default-features RUN rm -f target/release/deps/git_cliff* FROM debian:buster-slim as runner + +# 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 + COPY --from=builder /app/target/release/git-cliff /usr/local/bin -WORKDIR git-home -RUN cat <<'EOF' > entrypoint.sh +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 +# even when being run by a non priviledged user on their own files. Here we +# 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 #!/bin/sh -cp -r /app /git-home/app -cd /git-home/app -exec git-cliff "$@" +if [ "$(id -u)" -ne "$(stat -c '%u' .)" ]; then + eids="$(stat -c '--euid %u --egid %g' .)" +fi +exec ${eids:+setpriv --clear-groups $eids} git-cliff $@ EOF -ENTRYPOINT ["sh", "entrypoint.sh"] +ENTRYPOINT ["sh", "/usr/local/bin/entrypoint.sh"] diff --git a/website/docs/docker.md b/website/docs/docker.md index f195e4b635..0d3b0793c7 100644 --- a/website/docs/docker.md +++ b/website/docs/docker.md @@ -15,13 +15,13 @@ Docker builds are [automated](https://github.com/orhun/git-cliff/tree/main/.gith The easiest way of running **git-cliff** (in the git root directory with [configuration file](/docs/configuration) present) is to use the available tags from [Docker Hub](https://hub.docker.com/r/orhunp/git-cliff): ```bash -docker run -t -v "$(pwd)/.git":/app/ "orhunp/git-cliff:${TAG:-latest}" +docker run -t -v "$(pwd)":/app/ "orhunp/git-cliff:${TAG:-latest}" ``` Or you can use the image from the [GitHub Package Registry](https://github.com/orhun/git-cliff/pkgs/container/git-cliff%2Fgit-cliff): ```bash -docker run -t -v "$(pwd)/.git":/app/ "ghcr.io/orhun/git-cliff/git-cliff:${TAG:-latest}" +docker run -t -v "$(pwd)":/app/ "ghcr.io/orhun/git-cliff/git-cliff:${TAG:-latest}" ``` ### Building