Skip to content

Commit 36c6297

Browse files
committed
refactor: configmanager support [[]] format
Signed-off-by: Meng JiaFeng <jiafeng.meng@merico.dev>
1 parent 3d80a0d commit 36c6297

50 files changed

Lines changed: 2558 additions & 760 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

docs/best-practices/gitlab-jenkins-harbor.zh.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -554,7 +554,7 @@ Harbor 的 admin 用户初始登录密码是 `Harbor12345`,你可以尝试用
554554
user: admin
555555
enableRestart: true
556556
scm:
557-
cloneURL: http://gitlab.example.com:30080/root/spring-demo
557+
url: http://gitlab.example.com:30080/root/spring-demo
558558
branch: master
559559
pipeline:
560560
jobName: test-job
@@ -618,7 +618,7 @@ tools:
618618
user: admin
619619
enableRestart: true
620620
scm:
621-
cloneURL: http://gitlab.example.com:30080/root/spring-demo
621+
url: http://gitlab.example.com:30080/root/spring-demo
622622
branch: master
623623
pipeline:
624624
jobName: test-job

docs/plugins/jenkins-pipeline.zh.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
!!! tip "提示"
1212

13-
GitHub 与 GitLab 的主要区别在于 DevStream tool config 的 options.scm.cloneURL 以及所需要的 token 等不同。
13+
GitHub 与 GitLab 的主要区别在于 DevStream tool config 的 options.scm.url 以及所需要的 token 等不同。
1414

1515
## 1、前置要求
1616

@@ -83,7 +83,7 @@ tools:
8383
user: admin
8484
enableRestart: true
8585
scm:
86-
cloneURL: git@YOUR_REPO_CLONE_ADDRESS/root/spring-demo
86+
url: git@YOUR_REPO_CLONE_ADDRESS/root/spring-demo
8787
branch: master
8888
apiURL: YOUR_JENKINS_ADDR
8989
pipeline:

go.mod

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@ require (
1515
github.com/cheggaaa/pb v1.0.29
1616
github.com/deckarep/golang-set/v2 v2.1.0
1717
github.com/go-playground/validator/v10 v10.11.0
18+
github.com/goccy/go-yaml v1.9.6
1819
github.com/google/go-cmp v0.5.8
1920
github.com/google/go-github/v42 v42.0.0
2021
github.com/hashicorp/go-cleanhttp v0.5.2
2122
github.com/hashicorp/go-getter v1.6.2
2223
github.com/imdario/mergo v0.3.12
23-
github.com/kr/pretty v0.3.0
2424
github.com/mitchellh/go-homedir v1.1.0
2525
github.com/mitchellh/mapstructure v1.5.0
2626
github.com/mittwald/go-helm-client v0.8.4
@@ -100,7 +100,7 @@ require (
100100
github.com/evanphx/json-patch v4.12.0+incompatible // indirect
101101
github.com/exponent-io/jsonpath v0.0.0-20151013193312-d6023ce2651d // indirect
102102
github.com/fatih/camelcase v1.0.0 // indirect
103-
github.com/fatih/color v1.9.0 // indirect
103+
github.com/fatih/color v1.13.0 // indirect
104104
github.com/fsnotify/fsnotify v1.5.1 // indirect
105105
github.com/fvbommel/sortorder v1.0.1 // indirect
106106
github.com/ghodss/yaml v1.0.0 // indirect
@@ -149,16 +149,15 @@ require (
149149
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 // indirect
150150
github.com/kevinburke/ssh_config v0.0.0-20201106050909-4977a11b4351 // indirect
151151
github.com/klauspost/compress v1.13.6 // indirect
152-
github.com/kr/text v0.2.0 // indirect
153152
github.com/lann/builder v0.0.0-20180802200727-47ae307949d0 // indirect
154153
github.com/lann/ps v0.0.0-20150810152359-62de8c46ede0 // indirect
155154
github.com/leodido/go-urn v1.2.1 // indirect
156155
github.com/lib/pq v1.10.2 // indirect
157156
github.com/liggitt/tabwriter v0.0.0-20181228230101-89fcab3d43de // indirect
158157
github.com/magiconair/properties v1.8.5 // indirect
159158
github.com/mailru/easyjson v0.7.7 // indirect
160-
github.com/mattn/go-colorable v0.1.11 // indirect
161-
github.com/mattn/go-isatty v0.0.14 // indirect
159+
github.com/mattn/go-colorable v0.1.13 // indirect
160+
github.com/mattn/go-isatty v0.0.16 // indirect
162161
github.com/mattn/go-runewidth v0.0.9 // indirect
163162
github.com/matttproud/golang_protobuf_extensions v1.0.2-0.20181231171920-c182affec369 // indirect
164163
github.com/mitchellh/copystructure v1.1.1 // indirect
@@ -209,11 +208,12 @@ require (
209208
golang.org/x/mod v0.6.0 // indirect
210209
golang.org/x/net v0.1.0 // indirect
211210
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c // indirect
212-
golang.org/x/sys v0.1.0 // indirect
211+
golang.org/x/sys v0.2.0 // indirect
213212
golang.org/x/term v0.1.0 // indirect
214213
golang.org/x/text v0.4.0 // indirect
215214
golang.org/x/time v0.0.0-20220722155302-e5dcc9cfc0b9 // indirect
216215
golang.org/x/tools v0.2.0 // indirect
216+
golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 // indirect
217217
google.golang.org/api v0.44.0 // indirect
218218
google.golang.org/appengine v1.6.7 // indirect
219219
google.golang.org/genproto v0.0.0-20220222213610-43724f9ea8cf // indirect

go.sum

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -476,8 +476,10 @@ github.com/exponent-io/jsonpath v0.0.0-20151013193312-d6023ce2651d/go.mod h1:ZZM
476476
github.com/fatih/camelcase v1.0.0 h1:hxNvNX/xYBp0ovncs8WyWZrOrpBNub/JfaMvbURyft8=
477477
github.com/fatih/camelcase v1.0.0/go.mod h1:yN2Sb0lFhZJUdVvtELVWefmrXpuZESvPmqwoZc+/fpc=
478478
github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
479-
github.com/fatih/color v1.9.0 h1:8xPHl4/q1VyqGIPif1F+1V3Y3lSmrq01EabUW3CoW5s=
480479
github.com/fatih/color v1.9.0/go.mod h1:eQcE1qtQxscV5RaZvpXrrb8Drkc3/DdQ+uUYCNjL+zU=
480+
github.com/fatih/color v1.10.0/go.mod h1:ELkj/draVOlAH/xkhN6mQ50Qd0MPOk5AAr3maGEBuJM=
481+
github.com/fatih/color v1.13.0 h1:8LOYc1KYPPmyKMuN8QV2DNRWNbLo6LZ0iLs8+mlH53w=
482+
github.com/fatih/color v1.13.0/go.mod h1:kLAiJbzzSOZDVNGyDpeOxJ47H46qBXwg5ILebYFFOfk=
481483
github.com/felixge/httpsnoop v1.0.1 h1:lvB5Jl89CsZtGIWuTcDM1E/vkVs49/Ml7JJe07l8SPQ=
482484
github.com/felixge/httpsnoop v1.0.1/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U=
483485
github.com/flynn/go-shlex v0.0.0-20150515145356-3f9db97f8568/go.mod h1:xEzjJPgXI435gkrCt3MPfRiAkVrwSbHsst4LCFVfpJc=
@@ -586,10 +588,13 @@ github.com/go-openapi/validate v0.19.2/go.mod h1:1tRCw7m3jtI8eNWEEliiAqUIcBztB2K
586588
github.com/go-ozzo/ozzo-validation v3.5.0+incompatible/go.mod h1:gsEKFIVnabGBt6mXmxK0MoFy+cZoTJY6mu5Ll3LVLBU=
587589
github.com/go-playground/assert/v2 v2.0.1 h1:MsBgLAaY856+nPRTKrp3/OZK38U/wa0CcBYNjji3q3A=
588590
github.com/go-playground/assert/v2 v2.0.1/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4=
591+
github.com/go-playground/locales v0.13.0/go.mod h1:taPMhCMXrRLJO55olJkUXHZBHCxTMfnGwq/HNwmWNS8=
589592
github.com/go-playground/locales v0.14.0 h1:u50s323jtVGugKlcYeyzC0etD1HifMjqmJqb8WugfUU=
590593
github.com/go-playground/locales v0.14.0/go.mod h1:sawfccIbzZTqEDETgFXqTho0QybSa7l++s0DH+LDiLs=
594+
github.com/go-playground/universal-translator v0.17.0/go.mod h1:UkSxE5sNxxRwHyU+Scu5vgOQjsIJAF8j9muTVoKLVtA=
591595
github.com/go-playground/universal-translator v0.18.0 h1:82dyy6p4OuJq4/CByFNOn/jYrnRPArHwAcmLoJZxyho=
592596
github.com/go-playground/universal-translator v0.18.0/go.mod h1:UvRDBj+xPUEGrFYl+lu/H90nyDXpg0fqeB/AQUGNTVA=
597+
github.com/go-playground/validator/v10 v10.4.1/go.mod h1:nlOn6nFhuKACm19sB/8EGNn9GlaMV7XkbRSipzJ0Ii4=
593598
github.com/go-playground/validator/v10 v10.11.0 h1:0W+xRM511GY47Yy3bZUbJVitCNg2BOGlCyvTqsp/xIw=
594599
github.com/go-playground/validator/v10 v10.11.0/go.mod h1:i+3WkQ1FvaUjjxh1kSvIA4dMGDBiPU55YFDl0WbKdWU=
595600
github.com/go-redis/cache/v8 v8.4.2 h1:8YbsmnU1Ws3TKS6T+qALzYE/MlGE+A/lrlx1XTA3p6M=
@@ -610,6 +615,8 @@ github.com/gobuffalo/packr/v2 v2.8.1 h1:tkQpju6i3EtMXJ9uoF5GT6kB+LMTimDWD8Xvbz6z
610615
github.com/gobuffalo/packr/v2 v2.8.1/go.mod h1:c/PLlOuTU+p3SybaJATW3H6lX/iK7xEz5OeMf+NnJpg=
611616
github.com/gobwas/glob v0.2.3 h1:A4xDbljILXROh+kObIiy5kIaPYD8e96x1tgBhUI5J+Y=
612617
github.com/gobwas/glob v0.2.3/go.mod h1:d3Ez4x06l9bZtSvzIay5+Yzi0fmZzPgnTbPcKjJAkT8=
618+
github.com/goccy/go-yaml v1.9.6 h1:KhAu1zf9JXnm3vbG49aDE0E5uEBUsM4uwD31/58ZWyI=
619+
github.com/goccy/go-yaml v1.9.6/go.mod h1:JubOolP3gh0HpiBc4BLRD4YmjEjHAmIIB2aaXKkTfoE=
613620
github.com/godbus/dbus v0.0.0-20151105175453-c7fdd8b5cd55/go.mod h1:/YcGZj5zSblfDWMMoOzV4fas9FZnQYTkDnsGvmh2Grw=
614621
github.com/godbus/dbus v0.0.0-20180201030542-885f9cc04c9c/go.mod h1:/YcGZj5zSblfDWMMoOzV4fas9FZnQYTkDnsGvmh2Grw=
615622
github.com/godbus/dbus v0.0.0-20190422162347-ade71ed3457e/go.mod h1:bBOAhwG1umN6/6ZUMtDFBMQR8jRg9O75tm9K00oMsK4=
@@ -905,6 +912,7 @@ github.com/lann/builder v0.0.0-20180802200727-47ae307949d0 h1:SOEGU9fKiNWd/HOJuq
905912
github.com/lann/builder v0.0.0-20180802200727-47ae307949d0/go.mod h1:dXGbAdH5GtBTC4WfIxhKZfyBF/HBFgRZSWwZ9g/He9o=
906913
github.com/lann/ps v0.0.0-20150810152359-62de8c46ede0 h1:P6pPBnrTSX3DEVR4fDembhRWSsG5rVo6hYhAB/ADZrk=
907914
github.com/lann/ps v0.0.0-20150810152359-62de8c46ede0/go.mod h1:vmVJ0l/dxyfGW6FmdpVm2joNMFikkuWg0EoCKLGUMNw=
915+
github.com/leodido/go-urn v1.2.0/go.mod h1:+8+nEpDfqqsY+g338gtMEUOtuK+4dEMhiQEgxpxOKII=
908916
github.com/leodido/go-urn v1.2.1 h1:BqpAaACuzVSgi/VLzGZIobT2z4v53pjosyNd9Yv6n/w=
909917
github.com/leodido/go-urn v1.2.1/go.mod h1:zt4jvISO2HfUBqxjfIshjdMTYS56ZS/qv49ictyFfxY=
910918
github.com/lib/pq v1.2.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo=
@@ -943,15 +951,18 @@ github.com/matryer/is v1.2.0 h1:92UTHpy8CDwaJ08GqLDzhhuixiBUUD1p3AU6PHddz4A=
943951
github.com/matryer/is v1.2.0/go.mod h1:2fLPjFQM9rhQ15aVEtbuwhJinnOqrmgXPNdZsdwlWXA=
944952
github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU=
945953
github.com/mattn/go-colorable v0.1.4/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE=
946-
github.com/mattn/go-colorable v0.1.11 h1:nQ+aFkoE2TMGc0b68U2OKSexC+eq46+XwZzWXHRmPYs=
947-
github.com/mattn/go-colorable v0.1.11/go.mod h1:u5H1YNBxpqRaxsYJYSkiCWKzEfiAb1Gb520KVy5xxl4=
954+
github.com/mattn/go-colorable v0.1.8/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc=
955+
github.com/mattn/go-colorable v0.1.9/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc=
956+
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
957+
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
948958
github.com/mattn/go-isatty v0.0.3/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4=
949959
github.com/mattn/go-isatty v0.0.4/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4=
950960
github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
951961
github.com/mattn/go-isatty v0.0.11/go.mod h1:PhnuNfih5lzO57/f3n+odYbM4JtupLOxQOAqxQCu2WE=
952962
github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=
953-
github.com/mattn/go-isatty v0.0.14 h1:yVuAays6BHfxijgZPzw+3Zlu5yQgKGP2/hcQbHb7S9Y=
954963
github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94=
964+
github.com/mattn/go-isatty v0.0.16 h1:bq3VjFmv/sOjHtdEhmkEV4x1AJtvUvOJ2PFAZ5+peKQ=
965+
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
955966
github.com/mattn/go-oci8 v0.1.1/go.mod h1:wjDx6Xm9q7dFtHJvIlrI99JytznLw5wQ4R+9mNXJwGI=
956967
github.com/mattn/go-runewidth v0.0.2/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU=
957968
github.com/mattn/go-runewidth v0.0.4/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU=
@@ -1689,11 +1700,12 @@ golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBc
16891700
golang.org/x/sys v0.0.0-20210616094352-59db8d763f22/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
16901701
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
16911702
golang.org/x/sys v0.0.0-20210806184541-e5e7981a1069/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
1692-
golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
16931703
golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
1704+
golang.org/x/sys v0.0.0-20220406163625-3f8b81556e12/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
16941705
golang.org/x/sys v0.0.0-20220517195934-5e4e11fc645e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
1695-
golang.org/x/sys v0.1.0 h1:kunALQeHf1/185U1i0GOB/fy1IPRDDpuoOOqRReG57U=
1696-
golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
1706+
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
1707+
golang.org/x/sys v0.2.0 h1:ljd4t30dBnAvMZaQCevtY0xLLD0A+bRZXbgLMLU1F/A=
1708+
golang.org/x/sys v0.2.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
16971709
golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw=
16981710
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
16991711
golang.org/x/term v0.0.0-20210220032956-6a3ed077a48d/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
@@ -1795,6 +1807,8 @@ golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8T
17951807
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
17961808
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
17971809
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
1810+
golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 h1:H2TDz8ibqkAF6YGhCdN3jS9O0/s90v0rJh3X/OLHEUk=
1811+
golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2/go.mod h1:K8+ghG5WaK9qNqU5K3HdILfMLy1f3aNYFI/wnl100a8=
17981812
gomodules.xyz/jsonpatch/v2 v2.1.0/go.mod h1:IhYNNY4jnS53ZnfE4PAmpKtDpTCj1JFXc+3mwe7XcUU=
17991813
gonum.org/v1/gonum v0.0.0-20180816165407-929014505bf4/go.mod h1:Y+Yx5eoAFn32cQvJDxZx5Dpnq+c3wtXuadVZAcxbbBo=
18001814
gonum.org/v1/gonum v0.0.0-20190331200053-3d26580ed485/go.mod h1:2ltnJ7xHfj0zHS40VVPYEAAMTa3ZGguvHGBSJeRWqE0=

internal/pkg/configmanager/app.go

Lines changed: 95 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,84 +1,118 @@
11
package configmanager
22

3+
import (
4+
"fmt"
5+
6+
"gopkg.in/yaml.v3"
7+
8+
"github.com/devstream-io/devstream/pkg/util/log"
9+
"github.com/devstream-io/devstream/pkg/util/mapz"
10+
"github.com/devstream-io/devstream/pkg/util/scm"
11+
)
12+
13+
const (
14+
repoScaffoldingPluginName = "repo-scaffolding"
15+
)
16+
317
type (
4-
App struct {
5-
Name string `yaml:"name" mapstructure:"name"`
6-
Spec RawOptions `yaml:"spec" mapstructure:"spec"`
7-
Repo *Repo `yaml:"repo" mapstructure:"repo"`
8-
RepoTemplate *RepoTemplate `yaml:"repoTemplate" mapstructure:"repoTemplate"`
9-
CIPipelines []PipelineTemplate `yaml:"ci" mapstructure:"ci"`
10-
CDPipelines []PipelineTemplate `yaml:"cd" mapstructure:"cd"`
18+
appRaw struct {
19+
Name string `yaml:"name" mapstructure:"name"`
20+
Spec map[string]any `yaml:"spec" mapstructure:"spec"`
21+
Repo *scm.SCMInfo `yaml:"repo" mapstructure:"repo"`
22+
RepoTemplate *scm.SCMInfo `yaml:"repoTemplate" mapstructure:"repoTemplate"`
23+
CIRawConfigs []pipelineRaw `yaml:"ci" mapstructure:"ci"`
24+
CDRawConfigs []pipelineRaw `yaml:"cd" mapstructure:"cd"`
1125
}
12-
Apps []App
26+
)
1327

14-
// AppInConfig is the raw structured data in config file.
15-
// The main difference between App and AppInConfig is "CI" and "CD" field.
16-
// The "CIRawConfigs" is the raw data of "CI" field defined in config file,
17-
// which will be rendered to "CIPipelines" field in App with "PipelineTemplates".
18-
// The "CDRawConfigs" is similar to "CIRawConfigs".
19-
AppInConfig struct {
20-
Name string `yaml:"name" mapstructure:"name"`
21-
Spec RawOptions `yaml:"spec" mapstructure:"spec"`
22-
Repo *Repo `yaml:"repo" mapstructure:"repo"`
23-
RepoTemplate *RepoTemplate `yaml:"repoTemplate" mapstructure:"repoTemplate"`
24-
CIRawConfigs []CICD `yaml:"ci" mapstructure:"ci"`
25-
CDRawConfigs []CICD `yaml:"cd" mapstructure:"cd"`
28+
// getAppTools return app tools
29+
func getAppTools(appStr string, globalVars map[string]any, templateMap map[string]string) (Tools, error) {
30+
//1. render appStr with globalVars
31+
appRenderStr, err := renderConfigWithVariables(appStr, globalVars)
32+
if err != nil {
33+
log.Debugf("configmanager/app %s render globalVars %+v failed", appRenderStr, globalVars)
34+
return nil, fmt.Errorf("app render globalVars failed: %w", err)
2635
}
27-
28-
CICD struct {
29-
Type string `yaml:"type" mapstructure:"type"`
30-
TemplateName string `yaml:"templateName" mapstructure:"templateName"`
31-
Options RawOptions `yaml:"options" mapstructure:"options"`
32-
Vars RawOptions `yaml:"vars" mapstructure:"vars"`
36+
// 2. unmarshal appRaw config for render pipelineTemplate
37+
var rawData appRaw
38+
if err := yaml.Unmarshal([]byte(appRenderStr), &rawData); err != nil {
39+
return nil, fmt.Errorf("app parse yaml failed: %w", err)
3340
}
34-
)
41+
rawData.setDefault()
42+
appVars := mapz.MergeMaps(globalVars, rawData.Spec)
43+
// 3. generate app repo and tempalte repo from scmInfo
44+
repoScaffoldingTool, err := rawData.getRepoTemplateTool(appVars)
45+
if err != nil {
46+
return nil, fmt.Errorf("app[%s] get repo failed: %w", rawData.Name, err)
47+
}
48+
// 4. get ci/cd pipelineTemplates
49+
tools, err := rawData.getPipelineTools(templateMap, appVars)
50+
if err != nil {
51+
return nil, fmt.Errorf("app[%s] get pipeline tools failed: %w", rawData.Name, err)
52+
}
53+
if repoScaffoldingTool != nil {
54+
tools = append(tools, *repoScaffoldingTool)
55+
}
56+
return tools, nil
57+
}
3558

36-
func (apps Apps) validate() (errs []error) {
37-
for _, app := range apps {
38-
if err := app.validate(); err != nil {
39-
errs = append(errs, err)
59+
// getAppPipelineTool generate ci/cd tools from app config
60+
func (a *appRaw) getPipelineTools(templateMap map[string]string, appVars map[string]any) (Tools, error) {
61+
allPipelineRaw := append(a.CIRawConfigs, a.CDRawConfigs...)
62+
var tools Tools
63+
for _, p := range allPipelineRaw {
64+
t, err := p.newPipeline(a.Repo, templateMap, appVars)
65+
if err != nil {
66+
return nil, err
4067
}
68+
pipelineTool, err := t.getPipelineTool(a.Name)
69+
if err != nil {
70+
return nil, err
71+
}
72+
pipelineTool.DependsOn = a.getRepoTemplateDepends()
73+
tools = append(tools, *pipelineTool)
4174
}
42-
return errs
75+
return tools, nil
4376
}
4477

45-
func (app *App) validate() error {
46-
if app.Repo.RepoInfo != nil && app.Repo.RepoInfo.Name == "" {
47-
app.Repo.RepoInfo.Name = app.Name
78+
// getRepoTemplateTool will use repo-scaffolding plugin for app
79+
func (a *appRaw) getRepoTemplateTool(appVars map[string]any) (*Tool, error) {
80+
if a.Repo == nil {
81+
return nil, fmt.Errorf("app.repo field can't be empty")
4882
}
49-
50-
err := app.Repo.FillAndValidate()
83+
appRepo, err := a.Repo.BuildRepoInfo()
5184
if err != nil {
52-
return err
85+
return nil, fmt.Errorf("configmanager[app] parse repo failed: %w", err)
5386
}
54-
55-
if app.RepoTemplate != nil {
56-
err = app.RepoTemplate.FillAndValidate()
87+
if a.RepoTemplate != nil {
88+
templateRepo, err := a.RepoTemplate.BuildRepoInfo()
5789
if err != nil {
58-
return err
90+
return nil, fmt.Errorf("configmanager[app] parse repoTemplate failed: %w", err)
5991
}
92+
return newTool(
93+
repoScaffoldingPluginName, a.Name, RawOptions{
94+
"destinationRepo": RawOptions(appRepo.Encode()),
95+
"sourceRepo": RawOptions(templateRepo.Encode()),
96+
"vars": RawOptions(appVars),
97+
},
98+
), nil
6099
}
61-
62-
return nil
100+
return nil, nil
63101
}
64102

65-
func (config *ConfigRaw) constructApps(ciPipelines, cdPipelines [][]PipelineTemplate) *Config {
66-
configFinal := &Config{}
67-
configFinal.PluginDir = config.PluginDir
68-
configFinal.State = config.State
69-
configFinal.Tools = config.Tools
70-
71-
for i, app := range config.AppsInConfig {
72-
appFinal := App{
73-
Name: app.Name,
74-
Spec: app.Spec,
75-
Repo: app.Repo,
76-
RepoTemplate: app.RepoTemplate,
77-
}
78-
appFinal.CIPipelines = ciPipelines[i]
79-
appFinal.CDPipelines = cdPipelines[i]
80-
configFinal.Apps = append(configFinal.Apps, appFinal)
103+
// setDefault will set repoName to appName if repo.name field is empty
104+
func (a *appRaw) setDefault() {
105+
if a.Repo != nil && a.Repo.Name == "" {
106+
a.Repo.Name = a.Name
81107
}
108+
}
82109

83-
return configFinal
110+
// since all plugin depends on code is deployed, get dependsOn for repoTemplate
111+
func (a *appRaw) getRepoTemplateDepends() []string {
112+
var dependsOn []string
113+
// if a.RepoTemplate is configured, pipeline need to wait reposcaffolding finished
114+
if a.RepoTemplate != nil {
115+
dependsOn = []string{fmt.Sprintf("%s.%s", repoScaffoldingPluginName, a.Name)}
116+
}
117+
return dependsOn
84118
}

0 commit comments

Comments
 (0)