Skip to content

Commit 74f847d

Browse files
committed
update readme
1 parent 7258ef1 commit 74f847d

File tree

1 file changed

+88
-20
lines changed

1 file changed

+88
-20
lines changed

README.md

Lines changed: 88 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,113 @@
1-
# TagIt
1+
# TagIt
2+
23
[![Go Report Card](https://goreportcard.com/badge/github.com/ncode/tagit)](https://goreportcard.com/report/github.com/ncode/tagit)
34
[![License](https://img.shields.io/badge/License-Apache_2.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)
45
[![codecov](https://codecov.io/gh/ncode/tagit/graph/badge.svg?token=ISXEH274YD)](https://codecov.io/gh/ncode/tagit)
56

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
610

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)
918

1019
## Why?
1120

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.
1427

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.
2330

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:
2540

2641
```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
3045
```
3146

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)
3272
```mermaid
3373
sequenceDiagram
3474
participant tagit
3575
participant consul
3676
loop execute script on interval
3777
tagit->>consul: Do you have a service with id my-service1?
3878
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
4080
end
4181
```
4282

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
44112

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

Comments
 (0)