From e970113653d12cfa6b424b04caa3021e5e2206f9 Mon Sep 17 00:00:00 2001 From: Ashok Siyani Date: Tue, 18 Mar 2025 16:48:53 +0000 Subject: [PATCH 1/2] update configuration doc --- .gitignore | 1 + config.yaml | 12 -------- readme.md | 86 ++++++++++++++++++++++++++++++++++++++++++++++++++--- 3 files changed, 83 insertions(+), 16 deletions(-) delete mode 100644 config.yaml diff --git a/.gitignore b/.gitignore index 248555b..6e0e886 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ git-mirror +config.yaml \ No newline at end of file diff --git a/config.yaml b/config.yaml deleted file mode 100644 index 81aa2e1..0000000 --- a/config.yaml +++ /dev/null @@ -1,12 +0,0 @@ -defaults: - interval: 30s - mirror_timeout: 2m - git_gc: always - auth: - ssh_key_path: /etc/git-secret/ssh - ssh_known_hosts_path: /etc/git-secret/known_hosts -repositories: - - remote: https://github.com/utilitywarehouse/system-alerts - worktrees: - - link: target/alerts - ref: main diff --git a/readme.md b/readme.md index 93b51b5..24d1ac4 100644 --- a/readme.md +++ b/readme.md @@ -1,11 +1,89 @@ -git-mirror is a golang library to periodically mirror (bare clones) remote repositories locally. -The mirror is created with `--mirror=fetch` hence everything in `refs/*` on the remote -will be directly mirrored into `refs/*` in the local repository. -it can also maintain multiple mirrored checked out worktrees on different references. +# git-mirror + +git-mirror is an app to periodically mirror (bare clones) remote repositories locally. +It supports multiple mirrored checked out worktrees on different references +and it can also mirror multiple repositories. +`git-mirror` can be used as golang library in your code. [docs](https://pkg.go.dev/github.com/utilitywarehouse/git-mirror/pkg/mirror) +The mirror is created with `--mirror=fetch` hence everything in `refs/*` on the remote +will be directly mirrored into `refs/*` in the local repository. The implementation borrows heavily from [kubernetes/git-sync](https://github.com/kubernetes/git-sync). If you want to sync single repository on one reference then you are probably better off with [kubernetes/git-sync](https://github.com/kubernetes/git-sync), as it provides a lot more customisation. `git-mirror` should be used if multiple mirrored repositories with multiple checked out branches (worktrees) is required. + +## Usage + +``` +Usage: + git-mirror [global options] + +GLOBAL OPTIONS: + -log-level value (default: 'info') Log level [$LOG_LEVEL] + -config value (default: '/etc/git-mirror/config.yaml') Absolute path to the config file. [$GIT_MIRROR_CONFIG] + -watch-config value (default: true) watch config for changes and reload when changes encountered. [$GIT_MIRROR_WATCH_CONFIG] +``` + +## Config +configuration file contains `default` parameters and list of repositories. +each repository also contains list of worktrees to checkout. +`defaults` fields values are used if repository parameters are not specified. + +```yaml +defaults: + # root is the absolute path to the root dir where all repositories directories + # will be created all repos worktree links will be created here if not + # specified in repo config (default: '/tmp/git-mirror') + root: /tmp/git-mirror + + # interval is time duration for how long to wait between mirrors. (default: '30s') + interval: 30s + + # mirrorTimeout represents the total time allowed for the complete mirror loop (default: '2m') + mirror_timeout: 2m + + # git_gc garbage collection string. valid values are + # 'auto', 'always', 'aggressive' or 'off' (default: 'always') + git_gc: always + + # auth config to fetch remote repos + auth: + # path to the ssh key & known hosts used to fetch remote + ssh_key_path: /etc/git-secret/ssh + ssh_known_hosts_path: /etc/git-secret/known_hosts +repositories: + - remote: https://github.com/utilitywarehouse/git-mirror # required + # remote is the git URL of the remote repository to mirror. + # supported urls are 'git@host.xz:org/repo.git','ssh://git@host.xz/org/repo.git' + # or 'https://host.xz/org/repo.git'. '.git' suffix is optional + + # following fields are optional. + # if these fields are not specified values from defaults section will be used + root: /some/other/location + interval: 1m + mirror_timeout: 5m + git_gc: always + auth: + ssh_key_path: /some/other/location + ssh_known_hosts_path: /some/other/location + worktrees: + - link: alerts # required + # link is the path at which to create a symlink to the worktree dir + # if path is not absolute it will be created under repository root + + ref: main + # ref represents the git reference of the worktree branch, tags or hash + # are supported. default is HEAD + + pathspec: example + # pathspec of the dirs to checkout if required, optional if omitted + # whole repo will be checked out +``` + +App can load changes in config without restart. At repository level only +adding and removing repository is supported. changes in interval, timeout +and auth will require an app restart. +At worktree level apart from adding or removing, changes in existing worktree's +link, ref and pathspec is supported. \ No newline at end of file From 3777a5eb90c865807c22fd5fc3177123df6cbb01 Mon Sep 17 00:00:00 2001 From: Ashok Siyani Date: Tue, 18 Mar 2025 16:49:46 +0000 Subject: [PATCH 2/2] fmted --- .gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 6e0e886..3d19233 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,2 @@ git-mirror -config.yaml \ No newline at end of file +config.yaml