From d65686e7a48ed623ba2ad4acc27496c91aa86d5f Mon Sep 17 00:00:00 2001 From: markliby Date: Thu, 8 Dec 2022 16:09:11 +0800 Subject: [PATCH 1/4] add aliyun deploy --- Dockerfile | 22 ++++++++++++++++++++++ main.go | 44 ++++++++++++++++++++------------------------ 2 files changed, 42 insertions(+), 24 deletions(-) create mode 100644 Dockerfile diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..14a7bc7 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,22 @@ +FROM golang:1.17 as builder + +ENV GO111MODULE=on \ + GOPROXY=https://goproxy.cn,direct + +WORKDIR /app + +COPY . . + +RUN GOOS=linux GOARCH=amd64 go build -o kcl-playground + + +FROM kusionstack/kusion:v0.7.2 + +WORKDIR /app + +COPY --from=builder /app/kcl-playground . + +EXPOSE 80 + + +CMD ["./kcl-playground"] \ No newline at end of file diff --git a/main.go b/main.go index 96d5f7c..753512c 100644 --- a/main.go +++ b/main.go @@ -5,40 +5,36 @@ package main import ( "fmt" - "os/exec" - "runtime" - "strings" - "time" "kusionstack.io/kcl-playground/pkg/play" ) func main() { - addr := "localhost:2022" + addr := ":80" fmt.Printf("listen at http://%s\n", addr) - go func() { - time.Sleep(time.Second * 2) - openBrowser(addr) - }() + // go func() { + // time.Sleep(time.Second * 2) + // openBrowser(addr) + // }() play.Run(addr, &play.Option{ PlayMode: true, }) } -func openBrowser(url string) error { - if !strings.HasPrefix(url, "http") { - url = "http://" + url - } - switch runtime.GOOS { - case "linux": - return exec.Command("xdg-open", url).Start() - case "windows": - return exec.Command("rundll32", "url.dll,FileProtocolHandler", url).Start() - case "darwin": - return exec.Command("open", url).Start() - default: - return fmt.Errorf("unsupported platform") - } -} +// func openBrowser(url string) error { +// if !strings.HasPrefix(url, "http") { +// url = "http://" + url +// } +// switch runtime.GOOS { +// case "linux": +// return exec.Command("xdg-open", url).Start() +// case "windows": +// return exec.Command("rundll32", "url.dll,FileProtocolHandler", url).Start() +// case "darwin": +// return exec.Command("open", url).Start() +// default: +// return fmt.Errorf("unsupported platform") +// } +// } From a4b9ba0e1ef86800301f0049bd595e5bdd95e867 Mon Sep 17 00:00:00 2001 From: markliby Date: Fri, 30 Dec 2022 15:40:50 +0800 Subject: [PATCH 2/4] update kcl playgroud port --- Dockerfile | 2 +- main.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index 14a7bc7..6724b4a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -16,7 +16,7 @@ WORKDIR /app COPY --from=builder /app/kcl-playground . -EXPOSE 80 +EXPOSE 2022 CMD ["./kcl-playground"] \ No newline at end of file diff --git a/main.go b/main.go index 753512c..81fdf7b 100644 --- a/main.go +++ b/main.go @@ -10,7 +10,7 @@ import ( ) func main() { - addr := ":80" + addr := ":2022" fmt.Printf("listen at http://%s\n", addr) // go func() { From a367d2510d5b8cc28e71d8d44f74ed9a87dcfdfe Mon Sep 17 00:00:00 2001 From: Peefy Date: Thu, 9 Feb 2023 19:33:55 +0800 Subject: [PATCH 3/4] refactor: deploy code --- main.go | 21 --------------------- 1 file changed, 21 deletions(-) diff --git a/main.go b/main.go index 81fdf7b..98b15b3 100644 --- a/main.go +++ b/main.go @@ -13,28 +13,7 @@ func main() { addr := ":2022" fmt.Printf("listen at http://%s\n", addr) - // go func() { - // time.Sleep(time.Second * 2) - // openBrowser(addr) - // }() - play.Run(addr, &play.Option{ PlayMode: true, }) } - -// func openBrowser(url string) error { -// if !strings.HasPrefix(url, "http") { -// url = "http://" + url -// } -// switch runtime.GOOS { -// case "linux": -// return exec.Command("xdg-open", url).Start() -// case "windows": -// return exec.Command("rundll32", "url.dll,FileProtocolHandler", url).Start() -// case "darwin": -// return exec.Command("open", url).Start() -// default: -// return fmt.Errorf("unsupported platform") -// } -// } From fa1b586ff6cd8bee41b22fbda38d46e82a387e73 Mon Sep 17 00:00:00 2001 From: Peefy Date: Thu, 9 Feb 2023 19:43:50 +0800 Subject: [PATCH 4/4] refactor: deploy mode. --- Dockerfile | 2 +- main.go | 41 ++++++++++++++++++++++++++++++++++++----- 2 files changed, 37 insertions(+), 6 deletions(-) diff --git a/Dockerfile b/Dockerfile index 6724b4a..f5e3022 100644 --- a/Dockerfile +++ b/Dockerfile @@ -19,4 +19,4 @@ COPY --from=builder /app/kcl-playground . EXPOSE 2022 -CMD ["./kcl-playground"] \ No newline at end of file +CMD ["./kcl-playground -deploy"] diff --git a/main.go b/main.go index 98b15b3..b499332 100644 --- a/main.go +++ b/main.go @@ -4,16 +4,47 @@ package main import ( + "flag" "fmt" + "os/exec" + "runtime" + "strings" + "time" "kusionstack.io/kcl-playground/pkg/play" ) func main() { - addr := ":2022" - fmt.Printf("listen at http://%s\n", addr) - - play.Run(addr, &play.Option{ + deploy_mode := flag.Bool("deploy", false, "Whether is deploy mode") + flag.Parse() + opt := play.Option{ PlayMode: true, - }) + } + if *deploy_mode { + play.Run(":80", &opt) + } else { + addr := "localhost:2023" + fmt.Printf("listen at http://%s\n", addr) + go func() { + time.Sleep(time.Second * 2) + openBrowser(addr) + }() + play.Run(addr, &opt) + } +} + +func openBrowser(url string) error { + if !strings.HasPrefix(url, "http") { + url = "http://" + url + } + switch runtime.GOOS { + case "linux": + return exec.Command("xdg-open", url).Start() + case "windows": + return exec.Command("rundll32", "url.dll,FileProtocolHandler", url).Start() + case "darwin": + return exec.Command("open", url).Start() + default: + return fmt.Errorf("unsupported platform") + } }