A sidecar app which clones a git repo and keeps it in sync with the upstream.
Go to file
Chuanying Du ac70751767 Change git credential from cache to store and also add test for
username/password case.

For cache to store change:
* By default, cache only last 900 seconds, gitsync will break after
  that. See https://git-scm.com/docs/git-credential-cache.
* The test won't work with cache since the test don't have access to
  the default unix socket location; XDG_CACHE_HOME override also can
  pre-create a socket in advance.
* `store` put the credential into a file, much easier to debug than cache.
* Considering anyone have access to the pod already able to get the
  credential via environment variables or yaml configs, so put it in
  file won't make it less secure.

For the new password test:
1. askpass_git.sh provided to simulate a git with password challenge.
2. Need and only need to similate "clone" action, need to bypass other
  actions like config/credential setup.
3. See `credential fill` is the official git action to ask password,
  see https://git-scm.com/docs/git-credential.

This change resolved issue #196.
2019-12-18 09:55:01 -08:00
build Use vendor and build automatic build cache 2019-03-25 08:54:44 -07:00
cmd/git-sync Change git credential from cache to store and also add test for 2019-12-18 09:55:01 -08:00
demo Fix hugo demo and docs 2018-12-17 11:44:50 -08:00
docs Fix Typo 2019-02-21 15:46:51 +01:00
pkg Handle running as pid 1 2019-10-27 09:45:27 -07:00
vendor Use official logr rather than thockin 2019-03-25 08:54:44 -07:00
.gitignore Use the go-build-template 2016-10-30 17:09:06 -07:00
CONTRIBUTING.md Create CONTRIBUTING.md 2016-08-22 16:18:11 -07:00
Dockerfile.in Handle running as pid 1 2019-10-27 09:45:27 -07:00
LICENSE Initial commit 2016-08-20 14:09:57 -07:00
Makefile Bump Go to 1.13 2019-11-21 08:39:08 -08:00
OWNERS OWNERS wants 'approvers' not 'maintainers' 2019-01-15 08:39:42 -08:00
README.md Clean up docs 2019-11-26 14:12:47 -08:00
RELEASING.md Clean up / document build and release 2019-01-25 10:45:09 -08:00
SECURITY_CONTACTS Update embargo doc link in SECURITY_OWNERS and changes PST to PSC 2019-03-08 10:23:48 -07:00
askpass_git.sh Change git credential from cache to store and also add test for 2019-12-18 09:55:01 -08:00
code-of-conduct.md Update code-of-conduct.md 2017-12-20 13:32:20 -05:00
go.mod Clean up docs 2019-11-26 14:12:47 -08:00
go.sum Use official logr rather than thockin 2019-03-25 08:54:44 -07:00
slow_git.sh add timeout tests 2019-01-04 22:32:53 +00:00
test_e2e.sh Change git credential from cache to store and also add test for 2019-12-18 09:55:01 -08:00

README.md

git-sync

git-sync is a simple command that pulls a git repository into a local directory. It is a perfect "sidecar" container in Kubernetes - it can periodically pull files down from a repository so that an application can consume them.

git-sync can pull one time, or on a regular interval. It can pull from the HEAD of a branch, from a git tag, or from a specific git hash. It will only re-pull if the target of the run has changed in the upstream repository. When it re-pulls, it updates the destination directory atomically. In order to do this, it uses a git worktree in a subdirectory of the --root and flips a symlink.

git-sync can pull over HTTP(S) (with authentication or not) or SSH.

git-sync can also be configured to make a webhook call upon successful git repo synchronization. The call is made after the symlink is updated.

Building it

# build the container
make container REGISTRY=registry VERSION=tag
# build the container behind a proxy
make container REGISTRY=registry VERSION=tag \
    HTTP_PROXY=http://<proxy_address>:<proxy_port> \
    HTTPS_PROXY=https://<proxy_address>:<proxy_port>
# build the container for an OS/arch other than the current (e.g. you are on
# MacOS and want to run on Linux)
make container REGISTRY=registry VERSION=tag \
    GOOS=linux GOARCH=amd64

Usage

# run the container
docker run -d \
    -v /tmp/git-data:/tmp/git \
    registry/git-sync:tag \
        --repo=https://github.com/kubernetes/git-sync
        --branch=master
        --wait=30

# run an nginx container to serve the content
docker run -d \
    -p 8080:80 \
    -v /tmp/git-data:/usr/share/nginx/html \
    nginx

Webhooks

Webhooks are executed asynchronously from the main git-sync process. If a webhook-url is configured, when a change occurs to the local git checkout a call is sent using the method defined in webhook-method (default to POST). git-sync will continually attempt this webhook call until it succeeds (based on webhook-success-status). If unsuccessful, git-sync will wait webhook-backoff (default 3s) before re-attempting the webhook call.

Usage

A webhook is configured using a set of CLI flags. At its most basic only webhook-url needs to be set.

docker run -d \
    -v /tmp/git-data:/git \
    registry/git-sync:tag \
        --repo=https://github.com/kubernetes/git-sync
        --branch=master
        --wait=30
        --webhook-url="http://localhost:9090/-/reload"

Analytics