75 lines
4.1 KiB
Markdown
75 lines
4.1 KiB
Markdown
# docker-git-puller
|
|
|
|
An alpine-based docker container that pulls a git repo (updates it) every given amount of time (default 60s) with a shell script. The resulting image is approx. 20MB at size.
|
|
|
|
[![Docker Pulls](https://shields.privacynerd.de/docker/pulls/bluefox42/git-puller.svg?style=for-the-badge)](https://hub.docker.com/r/bluefox42/git-puller/)
|
|
|
|
## Purpose
|
|
|
|
There are many scenarios where such a container could help. For example (as I use it), this image could be used to pull a hugo built website (living in a public git repo) to a local folder, so that another docker container can serve the most recent files.
|
|
|
|
Please **be aware** of the fact that this image currently does no merging if some local file changed (maybe up to the future).
|
|
|
|
See the [docker-compose example](example/) for a quick overview how this works.
|
|
|
|
|
|
## Building
|
|
|
|
Building this docker image is quite easy. For a quick start, just use this:
|
|
|
|
```sh
|
|
docker build -t git-puller .
|
|
```
|
|
|
|
To do a multi-platform build (here with basic architectures) and upload to Docker Hub (make sure to replace <USER> with your Docker Hub username):
|
|
|
|
```sh
|
|
docker buildx build --no-cache --platform linux/amd64,linux/arm64/v8 -t <USER>/git-puller . --push
|
|
```
|
|
|
|
After this is done successfully, you can check out the new image in your local image store with `docker images`.
|
|
|
|
|
|
## Configuration
|
|
|
|
Essentially, this image can be configured over environment variables.
|
|
|
|
- **`PULL_LOCATION`**: used to set the container-internal folder which is getting pulled frequently (you should mount one into this direction) - defaults to `/to-pull`
|
|
- **`PULL_INTERVAL`**: the interval between pulls in seconds (minimum is 5, default is 60)
|
|
- **`PULLER_UID`**: the uid of the user that executes the `git pull` command (defaults to 1000)
|
|
- **`GIT_OUTPUT`**: if set to 0, the `git pull` stdout will be hidden from docker logs (redirected to /dev/null ;) (if not set, everything is visible in the docker logs)
|
|
|
|
|
|
## Useful links
|
|
|
|
Similar projects:
|
|
|
|
- [https://github.com/abes-esr/gitpuller-docker/](https://github.com/abes-esr/gitpuller-docker/)
|
|
- [https://github.com/Ekito/docker-cron/](https://github.com/Ekito/docker-cron/)
|
|
- [https://github.com/keckelt/cron-alpine/](https://github.com/keckelt/cron-alpine/)
|
|
- [https://github.com/theohbrothers/docker-alpine-cron/](https://github.com/theohbrothers/docker-alpine-cron/)
|
|
|
|
Forum posts:
|
|
|
|
- [https://serverfault.com/questions/599103/make-a-docker-application-write-to-stdout](https://serverfault.com/questions/599103/make-a-docker-application-write-to-stdout)
|
|
- [https://stackoverflow.com/questions/71557316/docker-alpine-execute-command-as-another-user](https://stackoverflow.com/questions/71557316/docker-alpine-execute-command-as-another-user)
|
|
|
|
I learnt much about shell scripts (as I never did any shell coding before) while developing the [docker-entrypoint.sh](docker-entrypoint.sh) script, and forum posts, websites, etc. helped me alot along my journey (below just an excerpt):
|
|
|
|
- [Shell exit codes explained](https://tldp.org/LDP/abs/html/exitcodes.html)
|
|
- [The "shell script" if-else statement](https://linuxize.com/post/bash-if-else-statement/)
|
|
- [The "shell script" while loop](https://www.cyberciti.biz/faq/bash-while-loop/)
|
|
- [Checking environment variables](https://ioflood.com/blog/bash-check-if-environment-variable-is-set/)
|
|
- [Another check for the existence of env vars](https://stackoverflow.com/questions/2981878/checking-for-environment-variables)
|
|
- [Check if a variable is a number](https://www.baeldung.com/linux/bash-variable-is-numeric)
|
|
- [Check for the existence of a directory](https://stackoverflow.com/questions/59838/how-do-i-check-if-a-directory-exists-or-not-in-a-bash-shell-script)
|
|
- [Check if current directory is a git repository](https://stackoverflow.com/questions/2180270/check-if-current-directory-is-a-git-repository)
|
|
- [Differences between the different braces in the shell](https://unix.stackexchange.com/questions/306111/what-is-the-difference-between-the-bash-operators-vs-vs-vs)
|
|
|
|
Also, [ShellCheck](https://www.shellcheck.net/) helped me while developing and "optimizing" (if a total beginner can do so ;) this project.
|
|
|
|
|
|
## License
|
|
|
|
see [LICENSE.md](LICENSE.md)
|