Skip to content

Commit 88a5278

Browse files
authored
Merge pull request #15 from ncode/juliano/development_environment
simplify the development flow
2 parents e2832ec + 00ef8ee commit 88a5278

File tree

9 files changed

+89
-13
lines changed

9 files changed

+89
-13
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,6 @@
1414
# Dependency directories (remove the comment below to include it)
1515
# vendor/
1616
.idea/
17+
18+
# .DS_Store
19+
.DS_Store

README.md

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,21 +25,10 @@ A few scenarios where this can be useful:
2525

2626
```bash
2727
$ git clone github.com/ncode/tagit
28-
$ go build
29-
$ consul agent -dev &
30-
$ curl --request PUT --data @examples/consul/my-service1.json http://127.0.0.1:8500/v1/agent/service/register
31-
$ ./tagit run --consul-addr=127.0.0.1:8500 --service-id=my-service1 --script=./examples/tagit/example.sh --interval=5s --tag-prefix=tagit
32-
INFO[0000] running command command=./examples/tagit/example.sh service=my-service1
33-
INFO[0000] updating service tags service=my-service1 tags="[v1 tagit-nice tagit-it tagit-works]"
34-
INFO[0005] running command command=./examples/tagit/example.sh service=my-service1
35-
INFO[0010] running command command=./examples/tagit/example.sh service=my-service1
36-
INFO[0015] running command command=./examples/tagit/example.sh service=my-service1
37-
$ ./tagit cleanup --consul-addr=127.0.0.1:8500 --service-id=my-service1 --tag-prefix=tagit
38-
INFO[0000] current service tags service=my-service1 tags="[v1 tagit-nice tagit-it tagit-works]"
39-
INFO[0000] updating service tags service=my-service1 tags="[v1]"
28+
$ cd configs/development
29+
$ make
4030
```
4131

42-
4332
```mermaid
4433
sequenceDiagram
4534
participant tagit
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Start from scratch for a minimal image
2+
FROM scratch
3+
4+
# Copy the Consul binary
5+
COPY consul /consul
6+
7+
# Set the entrypoint to Consul
8+
ENTRYPOINT ["/consul"]
9+
10+
# Default command
11+
CMD ["-dev -server -bootstrap-expect=1"]
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
FROM oraclelinux:9
2+
3+
# Copy the pre-compiled TagIt binary
4+
COPY tagit /usr/local/bin/tagit
5+
6+
# Set the entrypoint to TagIt
7+
ENTRYPOINT ["/usr/local/bin/tagit"]
8+
9+
# Default command
10+
CMD ["--help"]

configs/development/Makefile

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
.PHONY: build docker-build down up ensure-consul
2+
all: build ensure-consul docker-build down up
3+
4+
CONSUL_VERSION := $(shell curl -sL https://releases.hashicorp.com/consul/ | grep -v -- -rc | grep -Eo 'consul_[0-9]+\.[0-9]+\.[0-9]+' | sort -V | tail -1 | cut -d'_' -f2)
5+
CONSUL_ZIP := consul_$(CONSUL_VERSION)_linux_arm64.zip
6+
7+
build:
8+
GOOS=linux GOARCH=arm64 go build -o tagit -ldflags="-s -w" ../../
9+
10+
ensure-consul:
11+
@if [ ! -f "$(CONSUL_ZIP)" ]; then \
12+
echo "Downloading Consul version $(CONSUL_VERSION)"; \
13+
curl -sLO "https://releases.hashicorp.com/consul/$(CONSUL_VERSION)/$(CONSUL_ZIP)"; \
14+
else \
15+
echo "Consul zip file already exists (version $(CONSUL_VERSION))"; \
16+
fi
17+
@echo "Extracting Consul binary"
18+
@unzip -o "$(CONSUL_ZIP)" consul
19+
@chmod +x consul
20+
21+
docker-build:
22+
docker build -f Dockerfile.tagit -t ncode/tagit:dev .
23+
docker build -f Dockerfile.consul -t ncode/consul:dev .
24+
25+
up:
26+
docker compose up
27+
28+
down:
29+
docker compose down
30+
31+
clean:
32+
rm -f tagit consul $(CONSUL_ZIP)
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
service {
2+
id = "my-service1"
3+
name = "my-service"
4+
tags = ["v1"]
5+
address = "127.0.0.1"
6+
port = 8000
7+
8+
enable_tag_override = true
9+
10+
weights {
11+
passing = 10
12+
warning = 1
13+
}
14+
}

examples/consul/my-service1.json renamed to configs/development/config/tagit/consul/my-service1.json

File renamed without changes.
File renamed without changes.
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
services:
2+
consul:
3+
image: ncode/consul:dev
4+
command: agent -dev -client=0.0.0.0 -config-dir /config
5+
ports:
6+
- "8500:8500"
7+
volumes:
8+
- ./config/consul:/config
9+
10+
tagit:
11+
image: ncode/tagit:dev
12+
depends_on:
13+
- consul
14+
command: run --consul-addr=consul:8500 --service-id=my-service1 --script=/config/example.sh --interval=5s --tag-prefix=tagit
15+
volumes:
16+
- ./config/tagit:/config
17+

0 commit comments

Comments
 (0)