|
1 | | -# TagIt |
| 1 | +# TagIt |
| 2 | + |
2 | 3 | [](https://goreportcard.com/report/github.com/ncode/tagit) |
3 | 4 | [](https://opensource.org/licenses/Apache-2.0) |
4 | 5 | [](https://codecov.io/gh/ncode/tagit) |
5 | 6 |
|
| 7 | +TagIt is a tool that updates Consul service registration tags with outputs of a script. It copies the current service registration and appends the output of the script line by line as tags, while keeping the original tags. |
| 8 | + |
| 9 | +## Table of Contents |
6 | 10 |
|
7 | | -Update consul registration tags with outputs of a script. |
8 | | -It copies the current service registration and appends the output of the script line by line as tags, while keeping the original tags. |
| 11 | +- [Why TagIt?](#why) |
| 12 | +- [Installation](#installation) |
| 13 | +- [Usage](#usage) |
| 14 | +- [How It Works](#how-it-works) |
| 15 | +- [Examples](#examples) |
| 16 | +- [Contributing](#contributing) |
| 17 | +- [License](#license) |
9 | 18 |
|
10 | 19 | ## Why? |
11 | 20 |
|
12 | | -Basically because it's a very useful feature that is missing from consul. Read more about it [here](https://github.com/hashicorp/consul/issues/1048). |
13 | | -A few scenarios where this can be useful: |
| 21 | +TagIt addresses a feature that's currently missing from Consul. You can read more about the need for this functionality in [this Consul issue](https://github.com/hashicorp/consul/issues/1048). |
| 22 | + |
| 23 | +Here are some scenarios where TagIt can be useful: |
| 24 | + |
| 25 | +1. **Database Leader Tagging**: Your databases are under `mydb.service.consul`, and you want to ensure all writes go to the leader. |
| 26 | + - Run a script that checks for the leader and updates the tag accordingly. |
14 | 27 |
|
15 | | -1. Your databases are under mydb.service.consul, and you would like to ensure that all the writes go to the leader |
16 | | - 1. You run a script that checks the leader and updates the tag |
17 | | -2. You have a service that is not consul aware, but you would like to use consul for service discovery |
18 | | - 1. You run a script that checks the service and updates the tags |
19 | | -3. You have a load or a webserver, and you would like to have tags for all vhosts that are served by this server |
20 | | - 1. You run a script that checks the vhosts and updates the tags |
21 | | -4. Pretty much any services that are not consul aware, but you would like to use consul for service discovery |
22 | | - 1. You run a script that checks the service and updates the tags |
| 28 | +2. **Non-Consul-Aware Service Discovery**: You have a service that isn't Consul-aware, but you want to use Consul for service discovery. |
| 29 | + - Run a script that checks the service status and updates the tags. |
23 | 30 |
|
24 | | -## How to test it? |
| 31 | +3. **Web Server VHost Tagging**: You have a load balancer or web server, and you want tags for all vhosts served by this server. |
| 32 | + - Run a script that checks the vhosts and updates the tags. |
| 33 | + |
| 34 | +4. **Generic Service Tagging**: For any services that aren't Consul-aware, but you want to use Consul for service discovery. |
| 35 | + - Run a script that checks the service and updates the tags. |
| 36 | + |
| 37 | +## Installation |
| 38 | + |
| 39 | +To install TagIt, you can use the following commands: |
25 | 40 |
|
26 | 41 | ```bash |
27 | | -$ git clone github.com/ncode/tagit |
28 | | -$ cd configs/development |
29 | | -$ make |
| 42 | +$ git clone https://github.com/ncode/tagit |
| 43 | +$ cd tagit |
| 44 | +$ go build |
30 | 45 | ``` |
31 | 46 |
|
| 47 | +## Usage |
| 48 | + |
| 49 | +TagIt provides two main commands: `run` and `cleanup`. |
| 50 | + |
| 51 | +### Run Command |
| 52 | + |
| 53 | +The `run` command starts TagIt and continuously updates the tags based on the script output: |
| 54 | + |
| 55 | +```bash |
| 56 | +$ ./tagit run --consul-addr=127.0.0.1:8500 --service-id=my-service1 --script=./examples/tagit/example.sh --interval=5s --tag-prefix=tagit |
| 57 | +``` |
| 58 | + |
| 59 | +### Cleanup Command |
| 60 | + |
| 61 | +The `cleanup` command removes all tags with the specified prefix from the service: |
| 62 | + |
| 63 | +```bash |
| 64 | +$ ./tagit cleanup --consul-addr=127.0.0.1:8500 --service-id=my-service1 --tag-prefix=tagit |
| 65 | +``` |
| 66 | + |
| 67 | +## How It Works |
| 68 | + |
| 69 | +Here's a sequence diagram illustrating how TagIt interacts with Consul: |
| 70 | + |
| 71 | +>>>>>>> 6a3e346 (update readme) |
32 | 72 | ```mermaid |
33 | 73 | sequenceDiagram |
34 | 74 | participant tagit |
35 | 75 | participant consul |
36 | 76 | loop execute script on interval |
37 | 77 | tagit->>consul: Do you have a service with id my-service1? |
38 | 78 | consul->>tagit: Yes, here it is and that's the current registration |
39 | | - tagit->>consul: Update current registration adding or removing prefixed tags wiht the output of the script |
| 79 | + tagit->>consul: Update current registration adding or removing prefixed tags with the output of the script |
40 | 80 | end |
41 | 81 | ``` |
42 | 82 |
|
43 | | -## Todo |
| 83 | +## Examples |
| 84 | + |
| 85 | +Here's an example of how to test TagIt: |
| 86 | + |
| 87 | +1. Start a Consul agent in development mode: |
| 88 | + ```bash |
| 89 | + consul agent -dev & |
| 90 | + ``` |
| 91 | + |
| 92 | +2. Register a service with Consul: |
| 93 | + ```bash |
| 94 | + curl --request PUT --data @examples/consul/my-service1.json http://127.0.0.1:8500/v1/agent/service/register |
| 95 | + ``` |
| 96 | + |
| 97 | +3. Run TagIt: |
| 98 | + ```bash |
| 99 | + ./tagit run --consul-addr=127.0.0.1:8500 --service-id=my-service1 --script=./examples/tagit/example.sh --interval=5s --tag-prefix=tagit |
| 100 | + ``` |
| 101 | + |
| 102 | +4. Clean up the tags: |
| 103 | + ```bash |
| 104 | + ./tagit cleanup --consul-addr=127.0.0.1:8500 --service-id=my-service1 --tag-prefix=tagit |
| 105 | + ``` |
| 106 | + |
| 107 | +## Contributing |
| 108 | + |
| 109 | +Contributions to TagIt are welcome! Please feel free to submit a Pull Request. |
| 110 | + |
| 111 | +## License |
44 | 112 |
|
45 | | -- [ ] Adds a systemd unit file generator |
| 113 | +TagIt is licensed under the Apache License, Version 2.0. See the [LICENSE](LICENSE) file for details. |
0 commit comments