Skip to content

Commit

Permalink
feat: disable safe directory via .gitconfig (#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
guangie88 authored Aug 21, 2023
1 parent 924a9dd commit 76b16e6
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
3 changes: 3 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ RUN --mount=source=.git,target=./.git,type=bind \
pip install -e .

RUN addgroup clog && adduser --home /app --disabled-password --gecos "" --ingroup clog clog

# Disable safe directory since it impedes the use of the application
RUN printf '[safe]\n directory = *\n' > /app/.gitconfig && chown clog:clog /app/.gitconfig
USER clog

ENTRYPOINT ["cc-changelog-gen"]
28 changes: 28 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,3 +124,31 @@ The `~..` is simply dropped, to start from the beginning of all commits, equival
```bash
cc-changelog-gen HEAD
```

## Docker Build and Usage

To build the image from scratch:

```bash
IMAGE_TAG="latest"
docker build . -t "dsaidgovsg/cc-changelog-gen:${IMAGE_TAG}"
```

The entrypoint of the image is set to `cc-changelog-gen`, so to run with the CLI within the image:

```bash
docker run --rm -it -v /host/git/repo:/app/repo:ro -v /host/.clog.yaml:/app/.clog.yaml:ro "dsaidgovsg/cc-changelog-gen:${IMAGE_TAG}" \
-t "SOME_TITLE" -r /app/repo ~..HEAD
```

### Docker Image Caveat

`git`'s' `safe.directory` configuration by default to allow all directories from any users. This is
because the most likely use case is to mount the host git repo into the running container, and this
mounted directory is very likely to have a different user from the `clog` non-root user in the
image.

This setting can be found in `/app/.gitconfig` and amendable as `clog` non-root image user.

For more details on `safe.directory`:
<https://git-scm.com/docs/git-config/2.35.2#Documentation/git-config.txt-safedirectory>

0 comments on commit 76b16e6

Please sign in to comment.