Automatically sync a git repository using Docker and simonthum/git-sync.
See exmple use in docker-compose.yml, replace image
with newest version in runarsf/gitsync/packages (docker.pkg.github.com/runarsf/gitsync/gitsync:1.0.2
), and remove build
.
Required environment variables are GIT_NAME
and GIT_EMAIL
, either set these in .env
or directly in docker-compose.yml
.
NB! Remember to properly configure .gitignore
, git-sync will automatically push all changes, so ignoring your ssh-key could be a good idea.
- Generate ssh keys (no passphrase), or use already existing ssh keys.
ssh-keygen -t rsa -b 4096 -o -a 100 -f ./id_rsa -q -N "" -C "gitsync"
- Add the public key (
id_rsa.pub
) to the deploy keys for your project, remember to allow write access.
Run these commands from the root of the repository.
Don't add user: "1000:1000"
to docker-compose.yml
.
find .git -type d | xargs sudo chmod 755
find .git/objects -type f | xargs sudo chmod 444
find .git -type f | grep -v /objects/ | xargs sudo chmod 644
Reading materials for Docker and docker-compose file permissions:
- What file permissions should the contents of $GIT_DIR have?
- docker-file-permissions
- Docker compose volume Permissions linux
- Add a volume to Docker, but exclude a sub-folder
- Working with docker bind mounts and node_modules
docker-compose \
--project-directory ./repo \
--file ./repo/docker-compose.yml \
exec -u root gitsync bash -c 'wget --spider --quiet https://${GIT_HOST} && (cd /root/repo && /root/git-sync/git-sync)'
- Add support for password protected ssh keys
- Document / add option for
git config --local status.showUntrackedFiles no
andgit config --local pull.rebase false
. - Investigate file permissions