https://github.com/ttys3/git2consul-go
The git2consul-go tool is used to populate a Consul key/value store from a git repo.
The baseline source code was forked from go-git2consul which was inspired by the orginal git2consul tool.
git2consul-go comes in two variants:
Simple example usage.
$ git2consul -config config.json -basic -user mygituser -password mygitpass -once
Simple example config file.
repos:
- name: example
url: http://github.com/DummyOrg/ExampleRepo.git
$ git2consul -help
Usage of git2consul:
-config string
path to config file
-loglvl
set log level [debug | info | warn | error]
-logfmt string
specify log format [text | cli | json] (default "text")
-once
run git2consul once and exit
-version
show version
Configuration is provided with a JSON file and passed in via the -config flag. Repository
configuration will take care of cloning the repository into local_store, but it will not
be responsible for creating the actual local_store directory. Similarly, it is expected
that there is no collision of directory or file that contains the same name as the repository
name under local_store, or git2consul will exit with an error. If there is a git repository
under a specified repo name, and the origin URL is different from the one provided in the
configuration, it will be overwritten.
git2consul will attempt to use sane defaults for configuration. However, since git2consul needs to know which repository to pull from, minimal configuration is necessary.
| Configuration | Required | Default Value | Available Values | Description |
|---|---|---|---|---|
| local_store | no | os.TempDir() | string | Local cache for git2consul to store its tracked repositories |
| webhook:address | no | string | Webhook listener address that git2consul will be using | |
| webhook:port | no | 9000 | int | Webhook listener port that git2consul will be using |
| repos:name | yes | string | Name of the repository. This will match the webhook path, if any are enabled | |
| repos:url | yes | string | The URL of the repository | |
| repos:branches | no | master | string | Tracking branches of the repository |
| repos:source_root | no | string | Source root to apply on the repo. | |
| repos:expand_keys | no | true, false | Enable/disable file content evaluation. | |
| repos:skip_branch_name | no | false | true, false | Enable/disable branch name pruning. |
| repos:skip_repo_name | no | false | true, false | Enable/disable repository name pruning. |
| repos:mount_point | no | string | Sets the prefix which should be used for the path in the Consul KV Store | |
| repos:credentials:username | no | string | Username for the Basic Auth | |
| repos:credentials:password | no | string | Password/token for the Basic Auth | |
| repos:credentials:private_key:pk_key | no | string | Path to the private key used for the authentication | |
| repos:credentials:private_key:pk_username | no | git | string | Username used with the ssh authentication |
| repos:credentials:private_key:pk_password | no | string | Password used with the ssh authentication | |
| repos:hooks:type | no | polling | polling, webhook | Type of hook to use to fetch changes on the repository. See below. |
| repos:hooks:interval | no | 60 | int | Interval, in seconds, to poll if polling is enabled |
| repos:hooks:url | no | ?? | string | ??? |
| consul:address | no | 127.0.0.1:8500 | string | Consul address to connect to. It can be either the IP or FQDN with port included |
| consul:ssl_enable | no | false | true, false | Whether to use HTTPS to communicate with Consul |
| consul:token | no | string | Consul API Token |
Webhooks will be served from a single port, and different repositories will be given different endpoints according to their name
Available endpoints:
<webhook:address>:<webhook:port>/{repos:name}/github also works for Gitea<webhook:address>:<webhook:port>/{repos:name}/stash<webhook:address>:<webhook:port>/{repos:name}/bitbucket<webhook:address>:<webhook:port>/{repos:name}/gitlabThe "source_root" instructs the app to navigate to the specified directory in the git repo making the value of source_root is trimed from the KV Store key. By default the entire repo is evaluated.
When you configure the source_root with /top_level/lower_level the file /top_level/lower_level/foo/web.json will be mapped to the KV store as /foo/web.json
The "mount_point" option sets the prefix for the path in the Consul KV Store under which the keys should be added.
The "expand_keys" instructs the app to evaluate known types of files. The content of the file is evaluated to key-value pair and pushed to the Consul KV store.
configuration.yml---
services:
apache:
port: 80
ssh:
port: 22
will be evaluated to the following keys:
/configuration/services/apache/port/configuration/services/ssh/portThe "skip_branch_name" instructs the app to prune the branch name. If set to true the branch name is pruned from the KV store key.
The "skip_repo_name" instructs the app to prune the repository name. If set to true the repository name is pruned from the KV store key.
The "credentials" option provides the possibility to pass the credentials to authenticate to private git repositories.
Sample config with basic auth (login:password/token)
local_store: /var/lib/git2consul
webhook:
port: 8484
repos:
- name: consul-kv-config
url: ssh://[email protected]:2222/ttys3/consul-kv-config.git
branches:
- main
hooks:
- type: webhook
interval: 30s
url: ""
source_root: /
mount_point: ""
credentials:
username: foo
password: bar
consul:
address: 127.0.0.1:8500
ssl_enable: false
Sample config with ssh auth
local_store: /var/lib/git2consul
webhook:
port: 8484
repos:
- name: consul-kv-config
url: ssh://[email protected]:2222/ttys3/consul-kv-config.git
branches:
- main
hooks:
- type: webhook
interval: 30s
url: ""
source_root: /
mount_point: ""
credentials:
private_key:
key: ~/.ssh/id_ed25519
username: git
consul:
address: 127.0.0.1:8500
ssl_enable: false
See CONTRIBUTING.md for details.
$ make build
The end to end test can be run by simply running make test-e2e.
To run the test, you need to have the consul binary available in your path.
It simulates a create and update of consul KV pairs and confirms every operation is successful.
The test data is stored within this repo so developers do not have to setup an external repo to test.
The tests can manually be run by starting Consul in dev mode, and then manually running git2consul with one of the config files provided.
For example:
$ consul agent -dev
$ # In a separate terminal
$ ./git2consul -config pkg/e2e/data/create-config.json -once -debug
This project is using goreleaser. GitHub release creation is automated using Travis CI. New releases are automatically created when new tags are pushed to the repo.
$ TAG=v0.0.2 make tag
How to manually create a release without relying on Travis CI.
$ TAG=v0.0.2 make tag
$ GITHUB_TOKEN=xxx make clean release
See LICENSE for details.
See ACKNOWLEDGEMENT.md for details.
See CODE_OF_CONDUCT.md for details.
Content type
-
Digest
Size
-
Last updated
over 4 years ago
docker pull 80x86/git2consul:v0.2.7