/gitsync

A Docker image that runs simonthum/git-sync on a scheduled interval using cron.

Primary LanguageDockerfileMIT LicenseMIT

gitsync

Automatically sync a git repository using Docker and simonthum/git-sync.

Getting started

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.

  1. 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"
  2. Add the public key (id_rsa.pub) to the deploy keys for your project, remember to allow write access.

Permission errors?

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:

You can manually sync using this command

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)'

TODO:

  • Add support for password protected ssh keys
  • Document / add option for git config --local status.showUntrackedFiles no and git config --local pull.rebase false.
  • Investigate file permissions