-
Notifications
You must be signed in to change notification settings - Fork 29
Expand file tree
/
Copy pathtaskfile.yml
More file actions
253 lines (212 loc) · 6.69 KB
/
Copy pathtaskfile.yml
File metadata and controls
253 lines (212 loc) · 6.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
version: '3'
vars:
EXE: cepatkilatteknologi/snmp-olt-zte{{exeExt}}
tasks:
default:
cmds:
- task: dev
dev:
desc: Start local development (Redis in Docker + App with hot reload on host)
cmds:
- docker compose -f docker-compose.local.yaml up -d
- air -c .air.toml
dev-docker:
desc: Start full development environment in Docker (with hot reload)
cmds:
- docker compose up --build
dev-down:
desc: Stop local development environment
cmds:
- docker compose -f docker-compose.local.yaml down
go-install:
cmds:
- go install {{.REPO}}
dl-deps:
desc: Install tools required to run/build this app
cmds:
- task: go-install
vars: { REPO: github.com/cosmtrek/air@latest }
- task: tidy
init:
desc: Initialize the development environment
deps: [dl-deps]
cmds:
- echo "Development environment initialized"
- echo "Next steps:"
- echo " 1. Copy .env.example to .env and configure"
- echo " 2. Run 'task dev' to start development"
tidy:
desc: Clean up dependencies
cmds:
- go mod tidy
# Testing tasks
test:
desc: Run all unit tests
cmds:
- go test ./... -cover
test-verbose:
desc: Run all unit tests with verbose output
cmds:
- go test ./... -v -cover
test-coverage:
desc: Run tests and generate coverage report (text)
cmds:
- go test ./... -coverprofile=coverage.out -covermode=atomic
- go tool cover -func=coverage.out
- echo ""
- echo "Coverage summary:"
- go tool cover -func=coverage.out | grep total
test-html:
desc: Generate HTML coverage report and open in browser
cmds:
- go test ./... -coverprofile=coverage.out -covermode=atomic
- go tool cover -html=coverage.out -o coverage.html
- echo "Coverage report generated: coverage.html"
- echo "Open coverage.html in your browser to view detailed coverage"
test-unit:
desc: Run unit tests for specific package usage
cmds:
- go test {{.PKG}} -v -cover
test-race:
desc: Run tests with race detection
cmds:
- go test ./... -race -v
test-short:
desc: Run short tests (excluding integration tests)
cmds:
- go test ./... -short -v
load-test:
desc: Run k6 load testing
preconditions:
- sh: command -v k6
msg: "k6 is not installed. Install it from https://k6.io/docs/getting-started/installation/"
- sh: test -f k6-load-test.js
msg: "k6-load-test.js not found"
cmds:
- echo "Starting k6 load test..."
- k6 run k6-load-test.js
test-trap:
desc: Test SNMP Trap listener with fake traps
preconditions:
- sh: command -v snmptrap
msg: "snmptrap not installed. Install with: brew install net-snmp"
- sh: curl -s http://localhost:8081/health > /dev/null 2>&1
msg: "App not running. Start with: task dev"
cmds:
- ./scripts/test-trap.sh
test-trap-webhook:
desc: Start webhook receiver only (for manual trap testing)
cmds:
- ./scripts/test-trap.sh webhook
benchmark:
desc: Run benchmarks
cmds:
- go test ./config/... -bench=. -benchmem
app-build:
desc: Build the app binary
cmds:
- CGO_ENABLED=0 go build -o {{.EXE}} ./cmd/api/main.go
sources:
- ./**/*.go
generates:
- ./{{.EXE}}
build-image:
desc: Build the docker image (local)
cmds:
- docker build -t {{.EXE}}:local .
build-image-prod:
desc: Build production docker image (multi-arch)
cmds:
- docker buildx build --platform linux/amd64,linux/arm64 -t {{.EXE}}:latest -f Dockerfile .
push-image:
desc: Build and push docker image with multi-arch support to Docker Hub
cmds:
- 'docker buildx build --push --platform linux/amd64,linux/arm64,linux/arm/v7 -t {{.EXE}}:latest -f Dockerfile .'
- 'echo "Image pushed to Docker Hub: {{.EXE}}:latest"'
pull-image:
desc: Pull docker image from Docker Hub
cmds:
- docker pull {{.EXE}}:latest
# Production deployment tasks
prod-up:
desc: Start production containers (requires examples/docker/.env)
preconditions:
- sh: test -f examples/docker/.env
msg: "examples/docker/.env not found. Copy examples/docker/.env.example to examples/docker/.env and configure it."
cmds:
- docker compose -f examples/docker/docker-compose.yaml --env-file examples/docker/.env up -d
- echo "Production containers started"
- docker compose -f examples/docker/docker-compose.yaml ps
prod-down:
desc: Stop production containers
cmds:
- docker compose -f examples/docker/docker-compose.yaml down
- echo "Production containers stopped"
prod-restart:
desc: Restart production containers
cmds:
- task: prod-down
- task: prod-up
prod-rebuild:
desc: Rebuild and restart production containers
cmds:
- docker compose -f examples/docker/docker-compose.yaml down
- docker compose -f examples/docker/docker-compose.yaml --env-file examples/docker/.env up -d --build
- echo "Production containers rebuilt and started"
prod-logs:
desc: View production container logs
cmds:
- docker compose -f examples/docker/docker-compose.yaml logs -f app
prod-logs-redis:
desc: View production Redis logs
cmds:
- docker compose -f examples/docker/docker-compose.yaml logs -f redis
prod-ps:
desc: Show production containers status
cmds:
- docker compose -f examples/docker/docker-compose.yaml ps
# Development docker commands (docker-compose.yaml)
up:
desc: Start development Docker environment
cmds:
- docker compose up --build
down:
desc: Stop development Docker environment
cmds:
- docker compose down
restart:
desc: Restart development Docker environment
cmds:
- task: down
- task: up
logs:
desc: View development container logs
cmds:
- docker compose logs -f app
logs-redis:
desc: View development Redis logs
cmds:
- docker compose logs -f redis
ps:
desc: Show development containers status
cmds:
- docker compose ps
clean:
desc: Clean up all containers, volumes, and build artifacts
cmds:
- docker compose down -v
- docker compose -f examples/docker/docker-compose.yaml down -v
- docker compose -f docker-compose.local.yaml down -v
- rm -f {{.EXE}}
- rm -f coverage.out coverage.html
- rm -rf tmp/ # Air tmp directory
- echo "Cleanup complete"
clean-cache:
desc: Clean Go module cache and build cache
cmds:
- go clean -cache -modcache -testcache
- echo "Go caches cleaned"
help:
desc: Show available tasks
cmds:
- task --list