在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称:breser/git2consul开源软件地址:https://github.com/breser/git2consul开源编程语言:JavaScript 94.8%开源软件介绍:git2consulgit2consul takes one or many git repositories and mirrors them into Consul KVs. The goal is for organizations of any size to use git as the backing store, audit trail, and access control mechanism for configuration changes and Consul as the delivery mechanism. Installation
DockerThe docker image for git2consul is available at Cimpress-MCP/docker-git2consul Requirements / Caveats
Quick Start GuideLet's start off with a simple example to show you how it works. You can use this as a starting point and then tailor it to your use-case. I've created a simple repo with a few sample configuration files of different types. Of course, I could have used thousands of files with arbitrarily nested directories, but this is a quick start guide. The most minimalistic viable git2consul configuration mirrors a single git repo into the KV store with a given prefix. Here's how that would look mirroring the dev branch at cat <<EOF > /tmp/git2consul.json
{
"version": "1.0",
"repos" : [{
"name" : "sample_configuration",
"url" : "https://github.com/ryanbreen/git2consul_data.git",
"branches" : ["dev"],
"hooks": [{
"type" : "polling",
"interval" : "1"
}]
}]
}
EOF Start git2consul:
or for remote Consul endpoint:
git2consul will now poll the "dev" branch of the "git2consul_data.git" repo once per minute. On first run, it will mirror the 3 files into your Consul K/V with keys:
The Values of those Keys are the contents of the respective files. Changing the contents of that git branch will change the corresponding KVs within 1 minute. Once you are happy with your configuration, you can run git2consul as a daemon either in a Configurationgit2consul expects to be run on the same node as a Consul agent. git2consul expects its own configuration to be stored as a JSON object in '/git2consul/config' in your Consul KV. The utility Configuration Format{
"version": "1.0",
"local_store": "/var/lib/git2consul_cache",
"logger" : {
"name" : "git2consul",
"streams" : [{
"level": "trace",
"stream": "process.stdout"
},
{
"level": "debug",
"type": "rotating-file",
"path": "/var/log/git2consul/git2consul.log"
}]
},
"repos" : [{
"name" : "vp_config",
"url" : "ssh://stash.mydomain.com/team_configuration_data.git",
"include_branch_name" : false,
"source_root": "path/in/git/repo",
"mountpoint": "nested/root/for/keys",
"branches" : ["development", "staging", "production"],
"hooks": [{
"type" : "stash",
"port" : "5050",
"url" : "/gitpoke"
},
{
"type" : "polling",
"interval" : "1"
}]
},{
"name" : "github_data",
"expand_keys" : true,
"url" : "[email protected]:ryanbreen/git2consul_data.git",
"branches" : [ "master" ],
"hooks": [{
"type" : "github",
"port" : "5151",
"url" : "/gitpoke"
}]
}]
} The above example illustrates a 2 repo git2consul setup: one repo lives in an on-premises Git solution and the other is hosted at Github. The hooks array under each repository defines how git2consul will be notified of changes. git2consul supports Atlassian Stash, Atlassian Bitbucket, GitHub, and Gitlab webhooks as well as a basic polling model. Note that multiple webhooks can share the same port. The only constraint is that webhooks for different repos do not share the same port and path. The above example also logs to stdout as well as to file. Logging is handled via Bunyan. The value of the How it worksgit2consul uses the name and branches of configured repos to namespace the created KVs. The goal is to allow multiple teams to use the same Consul agents and KV store to migrate configuration data around a network without needing to worry about data conflicts. In the above example, a settings file stored at If you are using a more Twelve-Factor approach, where you wish to configure your applications via environment variables, you would store these settings as files in Git whose name is the key and whose body is the value. For example, we could create the file As changes are detected in the specified Git repos, git2consul determines which files have been added, updated, or deleted and replicates those changes to the KV. Because only changed branches and files are analyzed, git2consul should have a very slim profile on hosting systems. Environment variablesThere are environment variable equivalents for the parameters that git2consul accept
Alternative Modes of OperationAlternate Config LocationsBy default, git2consul looks for its configuration at the Consul Key git2consul -c git2consul/alternative_config No DaemonIf there are no webhooks or polling watchers configured, git2consul will terminate as soon as all tracked repos and branches have been synced with Consul. If you would like to force git2consul not to attach any webhooks or polling watchers, you can either pass the command-line switch Halt-on-changeIf you would like git2consul to shutdown every time its configuration changes, you can enable halt-on-change with the command-line switch Http maxSocketsSince version v0.12.0 of NodeJs, maxSockets is set to Infinity. This result in a lot of http connections being created when writing k/v to Consul, especially if you have a lot of branches / tags. In order to avoid hammering Consul with too many requests, you can specify the maximum amount of sockets that can be created by using the Example : {
"version": "1.0",
"max_sockets": 1,
"repos": [
...
],
...
} Will allow Node to only maintain one socket at a time. expand_keysThere are a couple of general behaviors in regards to
JSONIf you would like git2consul to treat JSON documents in your repo as fully formed subtrees, you can enable expand_keys mode via inclusion of the field {
'first_level' : {
'second_level' : {
'third_level' : {
'you get the picture' : 'right?'
}
}
}
} git2consul in expand_keys mode will generate the following KV:
The value in that KV pair will be A few notes on how this behaves:
YAMLSimilarly to JSON, git2consul can treat YAML documents in your repo as fully formed subtrees. ---
# file: example.yaml or example.yml
first_level:
second_level:
third_level:
my_key: my_value git2consul in expand_keys mode will generate the following KV:
The value in that KV pair will be .propertiesSimilarly to JSON, git2consul can also treat Java .properties as a simple k/v format. This is useful for teams willing to keep using legacy .properties files or don't want to use consul locally. Additionally, it has support for local variable :
Note:
Example, if you have a file
git2consul will generate
returning You can combine .properties files with the common_properties option, if you need a way to inject shared/common properties into other files. Optionsinclude_branch_name (default: true)
mountpoint (default: undefined)A Note: mountpoints can neither begin or end in with the character '/'. git2consul will reject your repo config if that's the case. source_root (default: undefined)A If you have a repo configured with the source_root support_tags (default: undefined)A This is useful if you want to version your property changes. It allows to create this kind of structure in consul :
usage example : {
"version": "1.0",
"repos" : [{
"name" : "sample_configuration",
"url" : "https://github.com/ryanbreen/git2consul_data.git",
"support_tags" : true,
"branches" : ["dev"],
"hooks": [{
"type" : "polling",
"interval" : "1"
}]
}]
} This feature will only work with annotated tags. common_properties (default: undefined)a Usage example : {
"version": "1.0",
"repos" : [{
"name" : "sample_configuration",
"url" : "https://github.com/ryanbreen/git2consul_data.git",
"expand_keys": true,
"common_properties" : "common.properties",
"branches" : ["dev"],
"hooks": [{
"type" : "polling",
"interval" : "1"
}]
}]
} If you have a file
and
git2consul will generate
returning Note :
ignore_repo_name (default: false)
ignore_file_extension (default: false)an Usage example : {
"version": "1.0",
"repos" : [{
"name" : "sample_configuration",
"url" : "https://github.com/ryanbreen/git2consul_data.git",
"ignore_file_extension" : true,
"branches" : ["dev"],
"hooks": [{
"type" : "polling",
"interval" : "1"
}]
}]
} Let say that you have a file called Debian packagingIf you don't have grunt git2consul can be packaged in .deb file. Simply run
This task uses the grunt-debian-package and depends on two debian tools :
Usage example :
The logs are stored in syslog by default, to check the logs just do The service assumes that consul is running on the machine with the default port(8500). The generated debian depends on If you want to use a custom configuration you can find the debian config in the Tested only on jessie. ClientsA client system should query Consul for the subset of the KV containing the data relevant to its operation. To extend the above example, our TokensIf you are using tokens for ACLs, you can pass a token to git2consul by specifying the LicenseApache 2.0 |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论