Skip to content

Commit a062c84

Browse files
hai-tianYangyang96
andauthored
feat: add developer portal (#1351)
feat: enable a developer portal to go along kusion server --------- Co-authored-by: Yang Yang <yy449738@antgroup.com>
1 parent d179b4d commit a062c84

File tree

160 files changed

+6379
-12
lines changed

Some content is hidden

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

160 files changed

+6379
-12
lines changed

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,5 +59,10 @@ air.toml
5959
# frontend
6060
frontend/
6161

62+
# ui
63+
ui/build/*
64+
!ui/build/.gitkeep
65+
node_modules/
66+
6267
# Terraform provider binary folder
6368
.terraform/

Dockerfile

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,15 @@
1+
# Build portal
2+
FROM node:18 AS portal-builder
3+
COPY ui /src/ui
4+
WORKDIR /src/ui
5+
RUN npm install
6+
RUN npm run build
7+
18
FROM golang:1.22 AS build
29
COPY / /src
10+
COPY --from=portal-builder /src/ui/build /src/ui/build
311
WORKDIR /src
4-
RUN --mount=type=cache,target=/go/pkg --mount=type=cache,target=/root/.cache/go-build make build-local-linux
12+
RUN --mount=type=cache,target=/go/pkg --mount=type=cache,target=/root/.cache/go-build SKIP_BUILD_PORTAL=true make build-local-linux
513

614
FROM ubuntu:22.04 AS base
715
# Install KCL Dependencies
@@ -18,4 +26,5 @@ RUN /usr/local/bin/kusion
1826

1927
FROM base
2028
COPY --from=build /src/_build/bundles/kusion-linux/bin/kusion /usr/local/bin/kusion
29+
COPY --from=build /src/ui/build /usr/local/bin/ui/build
2130
RUN /usr/local/bin/kusion

Makefile

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,25 @@ KCLVM_URL_BASE_MIRRORS:=
2525
CCRED=\033[0;31m
2626
CCEND=\033[0m
2727

28+
# Check if the SKIP_BUILD_PORTAL flag is set to control the portal building process.
29+
# If the flag is not set, the BUILD_PORTAL variable is assigned the value 'build-portal'.
30+
# If the flag is set, the BUILD_PORTAL variable remains empty.
31+
ifndef SKIP_BUILD_PORTAL
32+
BUILD_PORTAL = build-portal
33+
else
34+
BUILD_PORTAL =
35+
endif
36+
37+
# Show the portal build status
38+
show-portal-status:
39+
@if [ "$(BUILD_PORTAL)" = "build-portal" ]; then \
40+
echo "🚀 Building the portal as SKIP_BUILD_PORTAL is not set."; \
41+
echo ""; \
42+
else \
43+
echo "⏭️ Skipping the portal build as SKIP_BUILD_PORTAL is set."; \
44+
echo ""; \
45+
fi
46+
2847
help: ## This help message :)
2948
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' Makefile | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
3049

@@ -66,7 +85,7 @@ clean: ## Clean build bundles
6685

6786
build-all: build-local-darwin-all build-local-linux-all build-local-darwin-arm64-all build-local-windows-all ## Build all platforms (darwin, linux, windows)
6887

69-
build-local-darwin: ## Build kusion tool chain for macOS
88+
build-local-darwin: show-portal-status $(BUILD_PORTAL) ## Build kusion tool chain for macOS
7089
# Delete old artifacts
7190
-rm -f ./pkg/version/z_update_version.go
7291
-rm -rf ./_build/bundles/kusion-darwin
@@ -87,7 +106,7 @@ build-local-darwin-all: build-local-darwin ## Build kusion for macOS
87106
cd ./_build/bundles/kusion-darwin && tar -zcvf ../kusion-darwin.tgz .
88107
cd ./_build/bundles && go run ../../hack/md5file/main.go kusion-darwin.tgz > kusion-darwin.tgz.md5.txt
89108

90-
build-local-darwin-arm64: ## Build kusion tool chain for macOS arm64
109+
build-local-darwin-arm64: show-portal-status $(BUILD_PORTAL) ## Build kusion tool chain for macOS arm64
91110
# Delete old artifacts
92111
-rm -f ./pkg/version/z_update_version.go
93112
-rm -rf ./_build/bundles/kusion-darwin-arm64
@@ -118,7 +137,7 @@ build-local-linux-in-docker: ## Build kusionctl-linux in docker
118137
build-local-linux-all-in-docker: ## Build kusionctl-linux with kcl and kclopenapi in docker
119138
${RUN_IN_DOCKER} make build-local-linux-all
120139

121-
build-local-linux: ## Build kusion tool chain for linux
140+
build-local-linux: show-portal-status $(BUILD_PORTAL) ## Build kusion tool chain for linux
122141
# Delete old artifacts
123142
-rm -f ./pkg/version/z_update_version.go
124143
-rm -rf ./_build/bundles/kusion-linux
@@ -143,7 +162,7 @@ build-local-linux-all: build-local-linux ## Build kusion for linux
143162
cd ./_build/bundles/kusion-linux && tar -zcvf ../kusion-linux.tgz .
144163
cd ./_build/bundles && go run ../../hack/md5file/main.go kusion-linux.tgz > kusion-linux.tgz.md5.txt
145164

146-
build-local-windows: ## Build kusion tool chain for windows
165+
build-local-windows: show-portal-status $(BUILD_PORTAL) ## Build kusion tool chain for windows
147166
# Delete old artifacts
148167
-rm -f ./pkg/version/z_update_version.go
149168
-rm -rf ./_build/bundles/kusion-windows
@@ -168,9 +187,11 @@ build-local-windows-all: build-local-windows ## Build kusion for windows
168187
cd ./_build/bundles/kusion-windows && zip -r ../kusion-windows.zip .
169188
cd ./_build/bundles && go run ../../hack/md5file/main.go kusion-windows.zip > kusion-windows.zip.md5.txt
170189

190+
build-portal: ## Build kusion portal
191+
cd ui && npm install && npm run build && touch build/.gitkeep
192+
171193
build-image: ## Build kusion image
172-
make build-local-linux-all
173-
docker build -t kusion/kusion .
194+
docker build -t kusionstack/kusion .
174195

175196
sh-in-docker: ## Run a shell in the docker container of kusion
176197
${RUN_IN_DOCKER} bash
@@ -190,4 +211,4 @@ gen-api-doc: ## Generate API Documentation by API Specification
190211
@which swagger > /dev/null || (echo "Installing swagger@v0.30.5 ..."; go install github.com/go-swagger/go-swagger/cmd/swagger@v0.30.5 && echo "Installation complete!\n")
191212
-swagger generate markdown -f ./api/openapispec/swagger.json --output=docs/api.md && echo "🎉 Done!" || (echo "💥 Fail!"; exit 1)
192213

193-
.PHONY: test cover cover-html format lint lint-fix doc build-changelog upload clean build-all build-image build-local-linux build-local-windows build-local-linux-all build-local-windows-all e2e-test gen-api-spec gen-api-doc
214+
.PHONY: test cover cover-html format lint lint-fix doc build-changelog upload clean build-all build-image build-local-linux build-local-windows build-local-linux-all build-local-windows-all e2e-test gen-api-spec gen-api-doc build-portal show-portal-status

pkg/cmd/server/options.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ func NewServerOptions() *ServerOptions {
2020
MaxAsyncConcurrent: constant.MaxAsyncConcurrent,
2121
MaxAsyncBuffer: constant.MaxAsyncBuffer,
2222
LogFilePath: constant.DefaultLogFilePath,
23+
DevPortalEnabled: true,
2324
}
2425
}
2526

@@ -42,6 +43,7 @@ func (o *ServerOptions) Config() (*server.Config, error) {
4243
cfg.MaxAsyncConcurrent = o.MaxAsyncConcurrent
4344
cfg.MaxAsyncBuffer = o.MaxAsyncBuffer
4445
cfg.LogFilePath = o.LogFilePath
46+
cfg.DevPortalEnabled = o.DevPortalEnabled
4547
return cfg, nil
4648
}
4749

pkg/cmd/server/server.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ func (o *ServerOptions) AddServerFlags(cmd *cobra.Command) {
5757
i18n.T("Maximum number of concurrent async executions including generate, preview, apply and destroy. Default to 10."))
5858
cmd.Flags().StringVarP(&o.LogFilePath, "log-file-path", "", constant.DefaultLogFilePath,
5959
i18n.T("File path to write logs to. Default to /home/admin/logs/kusion.log"))
60+
cmd.Flags().BoolVarP(&o.DevPortalEnabled, "dev-portal-enabled", "d", true,
61+
i18n.T("Enable dev portal. Default to true."))
6062
o.Database.AddFlags(cmd.Flags())
6163
o.DefaultBackend.AddFlags(cmd.Flags())
6264
o.DefaultSource.AddFlags(cmd.Flags())

pkg/cmd/server/types.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ type ServerOptions struct {
1717
MaxAsyncConcurrent int
1818
MaxAsyncBuffer int
1919
LogFilePath string
20+
DevPortalEnabled bool
2021
}
2122

2223
type Options interface {

pkg/domain/entity/resource.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ type ResourceInfo struct {
6363
IAMResourceID string `yaml:"iamResourceID" json:"iamResourceID"`
6464
// CloudResourceID is the id of the resource in the cloud.
6565
CloudResourceID string `yaml:"cloudResourceID" json:"cloudResourceID"`
66+
// ResourceURN is the urn of the resource.
67+
ResourceURN string `yaml:"resourceURN" json:"resourceURN"`
6668
// Status is the status of the resource.
6769
Status string `yaml:"status" json:"status"`
6870
}
@@ -138,6 +140,7 @@ func (rg *ResourceGraph) ConstructResourceGraph(resources []*Resource) error {
138140
ResourceName: resource.ResourceName,
139141
IAMResourceID: resource.IAMResourceID,
140142
CloudResourceID: resource.CloudResourceID,
143+
ResourceURN: resource.ResourceURN,
141144
Status: resource.Status,
142145
}
143146
rg.Resources[resource.KusionResourceID] = info

pkg/server/config.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ type Config struct {
1818
MaxAsyncBuffer int
1919
LogFilePath string
2020
AutoMigrate bool
21+
DevPortalEnabled bool
2122
}
2223

2324
func NewConfig() *Config {

pkg/server/handler/module/handler.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ func (h *Handler) DeleteModule() http.HandlerFunc {
9797
// @Failure 429 {object} error "Too Many Requests"
9898
// @Failure 404 {object} error "Not Found"
9999
// @Failure 500 {object} error "Internal Server Error"
100-
// @Router /api/v1/modules/{moduleName} [put]
100+
// @Router /api/v1/modules/{moduleName} [put]
101101
func (h *Handler) UpdateModule() http.HandlerFunc {
102102
return func(w http.ResponseWriter, r *http.Request) {
103103
// Getting stuff from context.
@@ -139,7 +139,7 @@ func (h *Handler) UpdateModule() http.HandlerFunc {
139139
// @Failure 429 {object} error "Too Many Requests"
140140
// @Failure 404 {object} error "Not Found"
141141
// @Failure 500 {object} error "Internal Server Error"
142-
// @Router /api/v1/modules/{moduleName} [get]
142+
// @Router /api/v1/modules/{moduleName} [get]
143143
func (h *Handler) GetModule() http.HandlerFunc {
144144
return func(w http.ResponseWriter, r *http.Request) {
145145
// Getting stuff from context.

pkg/server/handler/workspace/configs.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ func (h *Handler) UpdateWorkspaceConfigs() http.HandlerFunc {
116116
// @Failure 429 {object} error "Too Many Requests"
117117
// @Failure 404 {object} error "Not Found"
118118
// @Failure 500 {object} error "Internal Server Error"
119-
// @Router /api/v1/workspaces/{workspaceID}/configs/mod-deps [post]
119+
// @Router /api/v1/workspaces/{workspaceID}/configs/mod-deps [post]
120120
func (h *Handler) CreateWorkspaceModDeps() http.HandlerFunc {
121121
return func(w http.ResponseWriter, r *http.Request) {
122122
// Getting stuff from context.

0 commit comments

Comments
 (0)