Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ git2consul takes one or many git repositories and mirrors them into [Consul](htt
#### Requirements / Caveats

* git2consul does most of its Git work by shelling out to git. Git must be installed and on your path.
* git2consul does the rest of its work by calling Consul's REST API. A Consul agent must be running on localhost.
* git2consul does the rest of its work by calling Consul's REST API.
* git2consul requires write access to the KV store of its Consul agent.
* git2consul has only been tested on Unix.

Expand All @@ -42,18 +42,30 @@ The most minimalistic viable git2consul configuration mirrors a single git repo
}
```

Put that configuration in a file called `/tmp/git2consul.json`. From the git2consul directory, upload that JSON file into the KV as your git2consul config:
Put that configuration in a file called `/tmp/git2consul.json`. From the git2consul directory, upload that JSON file into the local KV as your git2consul config:

```
node utils/config_seeder.js /tmp/git2consul.json
```

or for remote Consul endpoint:

```
node utils/config_seeder.js --endpoint remote.consul.host --port 80 /tmp/git2consul.json
```

Start git2consul:

```
node .
```

or for remote Consul endpoint:

```
node . --endpoint remote.consul.host --port 80
```

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:

```
Expand Down
54 changes: 39 additions & 15 deletions utils/config_seeder.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,32 @@
var fs = require('fs');

var consul = require('consul')();
/**
* First, check if there is a command line override for the consul endpoint.
* If so, use it to seed the config.
*/

var endpoint = "127.0.0.1";
var port = 8500;
var secure = false;
for (var i=2; i<process.argv.length; ++i) {
if(process.argv[i] === '-s' || process.argv[i] === '--secure') secure = true;
if(process.argv[i] === '-e' || process.argv[i] === '--endpoint') {
if(i+1 >= process.argv.length) {
logger.error("No endpoint provided with --endpoint option");
process.exit(3);
}
endpoint = process.argv[i+1];
}
if(process.argv[i] === '-p' || process.argv[i] === '--port') {
if(i+1 >= process.argv.length) {
logger.error("No port provided with --port option");
process.exit(3);
}
port = process.argv[i+1];
}
}

var consul = require('consul')({'host': endpoint, 'port': port, 'secure': secure});

var _ = require('underscore');

Expand All @@ -26,21 +52,19 @@ exports.setConfig = function(path, value, cb) {
consul.kv.set(params, cb);
};

if (process.argv.length === 3) {
var config_file = process.argv[2];

console.log('Adding %s as consul config', config_file);
var config_file = process.argv[process.argv.length-1];

var config = fs.readFileSync(config_file, {'encoding':'utf8'});
console.log('Adding %s as consul config', config_file);

try {
JSON.parse(config);
} catch(e) {
console.error('config_file is not valid JSON');
process.exit(1);
}
var config = fs.readFileSync(config_file, {'encoding':'utf8'});

exports.setConfig(config, function(err) {
if (err) return console.error("Failed to write config: %s", err);
});
try {
JSON.parse(config);
} catch(e) {
console.error('config_file is not valid JSON');
process.exit(1);
}

exports.setConfig(config, function(err) {
if (err) return console.error("Failed to write config: %s", err);
});