Simple SSH based Git cache
gitcache-ssh
is a simple SSH based Git cache.
This tool was conceived and written to dramatically reduce the bandwidth
consumed by developers and CI/CD build and test systems that constantly
communicate with geographically remote Git repositories.
It is designed to be (for the most part, after initial setup), transparrent to
the user or automation systems that are using it.
It provides an asymetric (pull/read-only) cache function to shim between the Git
client and the originating remote upstream Git repository.
$ make
$ make deb
$ make rpm
$GOROOT
, $GOPATH
and $GOBIN
environment variables.Create a suitable /var/cache/git/
directory to store the local cached copies
of remote Git repositories.
# mkdir -p /var/cache/git/
Add a suitable Match Group
or Match User
block to your OpenSSH/etc/ssh/sshd_config
configuration file to force the gitcache-ssh
wrapper
command to be executed upon login instead of the user’s shell.
For example, to enable the gitcache-ssh
command for all users who are a member
of the developers
group:
# cat << 'EOF' >> /etc/ssh/sshd_config
AcceptEnv LANG LC_* GIT_CACHESSH_*
Match Group developers
AllowTCPForwarding no
X11Forwarding no
ForceCommand /usr/local/bin/gitcache-ssh
EOF
# systemctl restart ssh
Git clients need to be configured to pull from the cache for specific
repositories or hosts. This is done using the insteadOf
and pushInsteadOf
configuration directives.
The following example will enable the cache for SSH-based access to all
GitHub.com repositories:
$ git config --global --add url."ssh://gitcache.host/git@github.com:".insteadOf "git@github.com:"
$ git config --global --add url."ssh://gitcache.host/git@github.com:".insteadOf "ssh://git@github.com/"
$ git config --global --add url."git@github.com:".pushInsteadOf "git@github.com:"
$ git config --global --add url."ssh://git@github.com/".pushInsteadOf "ssh://git@github.com/"
Enabling for HTTP and HTTPS-based access can be achieved by simply modifying the
URLs that are being re-written:
$ git config --global --add url."ssh://gitcache.host/git@github.com:".insteadOf "https://github.com/"
$ git config --global --add url."ssh://gitcache.host/git@github.com:".insteadOf "http://github.com/"
$ git config --global --add url."https://github.com/".pushInsteadOf "https://github.com/"
$ git config --global --add url."http://github.com/".pushInsteadOf "http://github.com/"
The git config -l | grep insteadof
command will display your current URL
re-writing configuration.
The gitcache-ssh
wrapper can be forced to refresh the local cache by setting
the environment variable GIT_CACHESSH_SYNC=true
. The OpenSSH client will not
forward this environment variable to the remote SSH Git cache host by default,
so a small change is necessary either to the local client’s ~/.ssh/ssh_config
file, or to the SSH command line that Git will invoke.
Ad-hoc command line based solution:
$ GIT_CACHESSH_SYNC=true GIT_SSH_COMMAND="ssh -o SendEnv=GIT_CACHESSH_*" git pull
Permanent configuration based solution:
$ cat >> ~/.ssh/config <<EOF
Host gitcache.host
SendEnv GIT_CACHESSH_*
EOF
$ GIT_CACHESSH_SYNC=true git pull
fpm
packaging with native RPM spec file and Debian packageTODO
and FIXME
mentioned in the source.git
command.BSD 3-Clause “New” or “Revised” License.
A permissive license similar to the BSD 2-Clause License, but with a 3rd clause
that prohibits others from using the name of the project or its contributors to
promote derived products without written consent.
See LICENSE file for full details.
Nicola Worthington nicola.worthington@nokia.com, nicolaw@tfb.net.