Skip to content

Commit 039518f

Browse files
feat: Convert TUI server to static site generator (#437)
* feat: Convert TUI server to static site generator * fix: ensure TUI static generator is backward compatible - Stop skipping empty fields in .gho output - Generate field-specific .gho and .json files using both json tag and struct field name * fix: return error on invalid config in loadAllVariations * fix: ignore empty json tags in writeGHO and update prod-variations config --------- Co-authored-by: Leonid Bugaev <leonsbox@gmail.com>
1 parent 572997f commit 039518f

12 files changed

Lines changed: 427 additions & 614 deletions

File tree

.github/workflows/pages.yml

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
name: Deploy TUI Static Site to Pages
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
- main
8+
paths:
9+
- 'config/tui/**'
10+
workflow_dispatch:
11+
12+
permissions:
13+
contents: read
14+
pages: write
15+
id-token: write
16+
17+
concurrency:
18+
group: "pages"
19+
cancel-in-progress: false
20+
21+
jobs:
22+
deploy:
23+
environment:
24+
name: github-pages
25+
url: ${{ steps.deployment.outputs.page_url }}
26+
runs-on: ubuntu-latest
27+
steps:
28+
- name: Checkout
29+
uses: actions/checkout@v4
30+
31+
- name: Setup Go
32+
uses: actions/setup-go@v5
33+
with:
34+
go-version: '1.22'
35+
36+
- name: Generate Static Site
37+
run: go run main.go policy generate-tui --config-dir config/tui --out-dir public
38+
39+
- name: Setup Pages
40+
uses: actions/configure-pages@v5
41+
42+
- name: Upload artifact
43+
uses: actions/upload-pages-artifact@v3
44+
with:
45+
path: './public'
46+
47+
- name: Deploy to GitHub Pages
48+
id: deployment
49+
uses: actions/deploy-pages@v4

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,5 @@ __pycache__
4242
/tyk-pro/
4343
/backup
4444

45-
.idea/
45+
.idea/
46+
public/

Makefile

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,6 @@ gromit: go.mod go.sum *.go $(SRC) $(TEMPLATES) update-variation
2020
go build -v -trimpath -ldflags "-X github.com/TykTechnologies/gromit/util.version=$(VERSION) -X github.com/TykTechnologies/gromit/util.commit=$(COMMIT) -X github.com/TykTechnologies/gromit/util.buildDate=$(BUILD_DATE)"
2121
go mod tidy
2222

23-
serve:
24-
command -v entr
25-
find policy -type f | entr -rs 'make gromit && CREDENTIALS='\''{"user":"pass"}'\'' ./gromit policy serve'
26-
2723
test:
2824
go test -coverprofile cp.out ./... # dlv test ./cmd #
2925

@@ -48,10 +44,6 @@ push: dist/gromit_linux_amd64_v1/gromit
4844
goreleaser --clean --snapshot
4945
docker push tykio/gromit:latest
5046

51-
deploy: push
52-
aws --no-cli-pager ecs update-service --service tui --cluster internal --force-new-deployment
53-
aws ecs wait services-stable --service tui --cluster internal
54-
./gromit env expose --env=internal
5547

5648
clean:
5749
find . -name rice-box.go -o -name error.yaml | xargs rm -fv
@@ -83,4 +75,4 @@ opr: gromit
8375
loc: clean
8476
gocloc --skip-duplicated --not-match-d=\.terraform --output-type=json ~gromit ~ci | jq -r '.languages | map([.name, .code]) | transpose[] | @csv'
8577

86-
.PHONY: clean update-test-cases test loc cpr upr opr deploy push
78+
.PHONY: clean update-test-cases test loc cpr upr opr push

cmd/policy.go

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -246,18 +246,13 @@ var matchSubCmd = &cobra.Command{
246246
},
247247
}
248248

249-
var serveSubCmd = &cobra.Command{
250-
Use: "serve",
251-
Short: "Start the test controller backend",
252-
Long: `The test controller backend stores the test that are to be run for a specific combination of,
253-
- trigger
254-
- repo
255-
- branch.
256-
This an laternate implementation to the controller which does not embed a server.`,
249+
var generateTuiCmd = &cobra.Command{
250+
Use: "generate-tui",
251+
Short: "Generate static TUI files",
257252
RunE: func(cmd *cobra.Command, args []string) error {
258-
tvDir, _ := cmd.Flags().GetString("save")
259-
port, _ := cmd.Flags().GetString("port")
260-
return policy.Serve(port, tvDir)
253+
configDir, _ := cmd.Flags().GetString("config-dir")
254+
outDir, _ := cmd.Flags().GetString("out-dir")
255+
return policy.GenerateStatic(configDir, outDir)
261256
},
262257
}
263258

@@ -273,8 +268,8 @@ func init() {
273268

274269
genSubCmd.Flags().String("repo", "", "Repository name to use from config file")
275270

276-
serveSubCmd.Flags().String("port", ":3000", "Port that the backend will bind to")
277-
serveSubCmd.Flags().String("save", "testdata/tui", "Test variations are loaded from and saved to this directory")
271+
generateTuiCmd.Flags().String("config-dir", "config/tui", "Directory containing TUI configuration files")
272+
generateTuiCmd.Flags().String("out-dir", "public", "Output directory for static files")
278273

279274
matchSubCmd.Flags().String("config", "$HOME/.docker/config.json", "Config file to read authentication token from")
280275
matchSubCmd.Flags().String("repos", "tyk-ee,tyk-analytics,tyk-pump,tyk-sink", "Config file to read authentication token from")
@@ -284,7 +279,7 @@ func init() {
284279
policyCmd.AddCommand(controllerSubCmd)
285280
policyCmd.AddCommand(diffSubCmd)
286281
policyCmd.AddCommand(genSubCmd)
287-
policyCmd.AddCommand(serveSubCmd)
282+
policyCmd.AddCommand(generateTuiCmd)
288283

289284
policyCmd.PersistentFlags().StringVar(&polBranch, "branch", "", "Restrict operations to this branch, if not set all branches defined int he config will be processed.")
290285
policyCmd.PersistentFlags().Bool("auto", true, "Will automerge if all requirements are meet")

config/tui/prod-variations.yml

Lines changed: 248 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,248 @@
1+
envfiles:
2+
- cache: "redis7"
3+
config: "sha256"
4+
db: "mongo7"
5+
apimarkers: "not local and not dind and not nightly"
6+
gwdash: master
7+
distros:
8+
rpm:
9+
- "amazonlinux:2"
10+
- "registry.access.redhat.com/ubi8/ubi"
11+
- "amazonlinux:2023"
12+
- "registry.access.redhat.com/ubi9/ubi"
13+
deb:
14+
- "ubuntu:xenial"
15+
- "debian:bullseye"
16+
- "ubuntu:bionic"
17+
- "ubuntu:focal"
18+
- "ubuntu:jammy"
19+
- "debian:bookworm"
20+
pump:
21+
- "$ECR/tyk-pump:master"
22+
sink:
23+
- "$ECR/tyk-sink:master"
24+
level: # testsuites
25+
api:
26+
envfiles:
27+
- cache: "redis6"
28+
config: "murmur128"
29+
db: "postgres15"
30+
apimarkers: "not local and not dind and not sql and not nightly"
31+
gwdash: master
32+
level: # branches
33+
master:
34+
level: # trigger
35+
schedule:
36+
level: # repo
37+
tyk-analytics:
38+
envfiles:
39+
- cache: "valkey8"
40+
config: "sha256"
41+
db: "postgres15"
42+
apimarkers: "not local and not dind and not sql"
43+
gwdash: master
44+
- cache: "valkey8"
45+
config: "murmur128"
46+
db: "mongo8"
47+
apimarkers: "not local and not dind"
48+
gwdash: master
49+
- cache: "redis7"
50+
config: "murmur128"
51+
db: "mongo8"
52+
apimarkers: "not local and not dind"
53+
gwdash: release-5.12.0
54+
sink: "$ECR/tyk-sink:release-2.8"
55+
- cache: "redis7"
56+
config: "murmur128"
57+
db: "mongo8"
58+
apimarkers: "not local and not dind"
59+
gwdash: release-5.8
60+
sink: "$ECR/tyk-sink:release-2.8.6"
61+
tyk:
62+
workflow_dispatch:
63+
level: # repo
64+
tyk-analytics:
65+
envfiles:
66+
- cache: "valkey8"
67+
config: "sha256"
68+
db: "postgres15"
69+
apimarkers: "not local and not dind and not sql"
70+
gwdash: master
71+
- cache: "valkey8"
72+
config: "murmur128"
73+
db: "mongo8"
74+
apimarkers: "not local and not dind"
75+
gwdash: master
76+
pull_request:
77+
level: # repo
78+
tyk:
79+
tyk-analytics:
80+
tyk-pump:
81+
tyk-sink:
82+
tyk-pro:
83+
envfiles:
84+
- cache: "valkey8"
85+
config: "sha256"
86+
db: "mongo8"
87+
apimarkers: "not local and not dind"
88+
- cache: "redis7"
89+
config: "murmur128"
90+
db: "postgres15"
91+
apimarkers: "not local and not dind and not sql"
92+
push:
93+
pump:
94+
- "tykio/tyk-pump-docker-pub:v1.14"
95+
level: # repos
96+
tyk:
97+
tyk-analytics:
98+
tyk-pump:
99+
tyk-sink:
100+
tyk-pro:
101+
release-5.3:
102+
pump:
103+
- "tykio/tyk-pump-docker-pub:v1.14"
104+
level: # trigger
105+
pull_request:
106+
level: # testsuite
107+
tyk:
108+
tyk-analytics:
109+
push:
110+
level: # testsuite
111+
tyk:
112+
tyk-analytics:
113+
release-5.6:
114+
level: # trigger
115+
pull_request:
116+
level: # testsuite
117+
tyk:
118+
tyk-analytics:
119+
release-5.12.0:
120+
level: # trigger
121+
pull_request:
122+
level: # testsuite
123+
tyk:
124+
tyk-analytics:
125+
envfiles:
126+
- cache: "valkey8"
127+
config: "murmur128"
128+
db: "mongo8"
129+
apimarkers: "not local and not dind"
130+
sink: "$ECR/tyk-sink:master"
131+
release-5.13:
132+
level: # trigger
133+
pull_request:
134+
level: # testsuite
135+
tyk:
136+
tyk-analytics:
137+
envfiles:
138+
- cache: "valkey8"
139+
config: "murmur128"
140+
db: "mongo8"
141+
apimarkers: "not local and not dind"
142+
sink: "$ECR/tyk-sink:master"
143+
release-6.0:
144+
level: # trigger
145+
pull_request:
146+
level: # testsuite
147+
tyk:
148+
tyk-analytics:
149+
envfiles:
150+
- cache: "valkey8"
151+
config: "murmur128"
152+
db: "mongo8"
153+
apimarkers: "not local and not dind"
154+
sink: "$ECR/tyk-sink:master"
155+
push:
156+
level: # testsuite
157+
tyk:
158+
tyk-analytics:
159+
release-5-lts:
160+
pump:
161+
- "tykio/tyk-pump-docker-pub:v1.14"
162+
level: # trigger
163+
pull_request:
164+
level: # testsuite
165+
tyk:
166+
tyk-analytics:
167+
push:
168+
level: # testsuite
169+
tyk:
170+
tyk-analytics:
171+
ui:
172+
level: # branches
173+
master:
174+
level: # trigger
175+
schedule:
176+
level: # repo
177+
tyk-analytics:
178+
envfiles:
179+
- cache: "valkey8"
180+
config: "sha256"
181+
db: "mongo8"
182+
apimarkers: "not local and not dind"
183+
gwdash: master
184+
- cache: "redis7"
185+
config: "murmur128"
186+
db: "mongo8"
187+
apimarkers: "not local and not dind"
188+
gwdash: release-5.12.0
189+
- cache: "redis7"
190+
config: "murmur128"
191+
db: "mongo8"
192+
apimarkers: "not local and not dind"
193+
gwdash: release-5.8
194+
workflow_dispatch:
195+
level: # repo
196+
tyk-analytics:
197+
envfiles:
198+
- cache: "valkey8"
199+
config: "sha256"
200+
db: "mongo8"
201+
apimarkers: "not local and not dind"
202+
pull_request:
203+
level: # repo
204+
tyk-analytics:
205+
tyk-pro:
206+
envfiles:
207+
- cache: "redis7"
208+
config: "sha256"
209+
db: "mongo7"
210+
apimarkers: "not local and not dind"
211+
- cache: "redis7"
212+
config: "murmur128"
213+
db: "postgres15"
214+
apimarkers: "not local and not dind and not sql"
215+
push:
216+
pump:
217+
- "tykio/tyk-pump-docker-pub:v1.14"
218+
level: # repos
219+
tyk-analytics:
220+
tyk-pro:
221+
release-5.3:
222+
pump:
223+
- "tykio/tyk-pump-docker-pub:v1.14"
224+
level: # trigger
225+
pull_request:
226+
level: # testsuite
227+
tyk-analytics:
228+
push:
229+
level: # testsuite
230+
tyk-analytics:
231+
release-5.6:
232+
level: # trigger
233+
pull_request:
234+
level: # testsuite
235+
tyk-analytics:
236+
push:
237+
level: # testsuite
238+
tyk-analytics:
239+
release-5-lts:
240+
pump:
241+
- "tykio/tyk-pump-docker-pub:v1.14"
242+
level: # trigger
243+
pull_request:
244+
level: # testsuite
245+
tyk-analytics:
246+
push:
247+
level: # testsuite
248+
tyk-analytics:

0 commit comments

Comments
 (0)