working script

This commit is contained in:
Jonas Maier 2024-05-11 23:49:07 +02:00
parent b0d0f53243
commit 69bcf40df5
3 changed files with 14 additions and 13 deletions

View File

@ -1,6 +1,9 @@
FROM alpine:3.14
RUN apk add --no-cache git openssh
RUN mkdir -p /var/git-cloner/{repo,auth}
RUN apk add --no-cache git
RUN adduser -D git-cloner
RUN mkdir -p /var/git-cloner/repo \
&& chown -R git-cloner:git-cloner /var/git-cloner
USER git-cloner
WORKDIR /var/git-cloner
COPY ./run.sh ./
ENTRYPOINT ["sh", "-c", "/var/git-cloner/run.sh"]

View File

@ -2,8 +2,7 @@
# Environment
- `INTERVAL`: interval to pull the repo, seconds
- `URL`: git URL, in ssh format
- `URL`: git URL
# Mounts
- `/var/git-cloner/repo`: the cloned repo
- `/var/git-cloner/auth`: directory containing ssh key

17
run.sh
View File

@ -1,20 +1,19 @@
set -euxo pipefail
KEYFILE="$(find /var/git-cloner/auth -type f | grep -v 'pub$')"
ls -alh "$KEYFILE"
whoami
export GIT_SSH_COMMAND="ssh -i $KEYFILE -o IdentitiesOnly=yes"
REPOPATH="/var/git-cloner/repo"
git config --global --add safe.directory "$REPOPATH"
cd "$REPOPATH"
while true
do
if [ -d "repo/.git" ]; then
# pull or clone
if [ -d ".git" ]; then
git pull
else
git clone "$URL" aa
git clone "$URL" .
fi
sleep "$INTERVAL"
# allow sleep to be interrupted
sleep "$INTERVAL" &
wait $!
done