Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

merge mvp branch to main #1461

Merged
merged 25 commits into from
Feb 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
5085194
feat: new commands support: start/create
daniel-hutao Feb 1, 2023
e178b4d
Merge pull request #1449 from merico-dev/mvp
daniel-hutao Feb 1, 2023
1a5d253
feat: interfaces definition for dtm create command
daniel-hutao Feb 1, 2023
a7ab937
Merge pull request #1450 from merico-dev/mvp
daniel-hutao Feb 1, 2023
c964d51
feat: read params from interact CLI
aFlyBird0 Feb 1, 2023
37b6527
Merge pull request #1454 from aFlyBird0/feat-param
daniel-hutao Feb 1, 2023
238b4e1
chore: remove log.Panic() in create/start commands
daniel-hutao Feb 1, 2023
3fed88e
feat: add repo and app creation for cli prompt
steinliber Feb 1, 2023
f715e55
Merge pull request #1456 from devstream-io/feat-repo-and-app-create
daniel-hutao Feb 2, 2023
bce200f
fix: command-err-when-exit
steinliber Feb 2, 2023
3681ac1
Merge pull request #1457 from devstream-io/fix-command-err-when-exit
daniel-hutao Feb 2, 2023
e2597ad
feat: docker minikube helm and argocd installation with dtm start com…
daniel-hutao Feb 2, 2023
eb155e9
refactor: make dtm start module more readable
daniel-hutao Feb 2, 2023
e0cb110
feat: add tools start logic to dtm start command
daniel-hutao Feb 2, 2023
3a4be22
fix: handle nil function with tool.Stopped in dtm start module
daniel-hutao Feb 2, 2023
bf41217
chore: steps with tools in dtm start command reorder
daniel-hutao Feb 2, 2023
7d73ba0
fix: check argo helm repo
aFlyBird0 Feb 2, 2023
f53bfb2
chore: more friendly logs to docker installation
daniel-hutao Feb 2, 2023
634aeb5
Merge pull request #1459 from aFlyBird0/check-helm-argo
daniel-hutao Feb 2, 2023
ae8cf0e
fix: devlake helm repo url
aFlyBird0 Feb 2, 2023
ebfeccb
feat: argocd exists function
daniel-hutao Feb 2, 2023
727e6a2
fix: update the way of argocd exists check
daniel-hutao Feb 2, 2023
9a5a78d
chore: use exec to reduce helm log
aFlyBird0 Feb 2, 2023
0a6239c
Merge pull request #1460 from aFlyBird0/chore_reduce-helm-log
daniel-hutao Feb 2, 2023
402f78a
chore: dtm create/start commands logs improvement
daniel-hutao Feb 2, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions cmd/devstream/create.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package main

import (
"fmt"

"github.com/spf13/cobra"

"github.com/devstream-io/devstream/internal/pkg/create"
)

var createCMD = &cobra.Command{
Use: "create",
Short: "create",
Long: `create.`,
Run: createCMDFunc,
}

func createCMDFunc(cmd *cobra.Command, args []string) {
err := create.Create()
if err != nil && err.Error() != "^C" {
fmt.Printf("Failed with error: %s", err)
}
}
3 changes: 3 additions & 0 deletions cmd/devstream/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ func init() {
rootCMD.AddCommand(listCMD)
rootCMD.AddCommand(showCMD)
rootCMD.AddCommand(upgradeCMD)

rootCMD.AddCommand(startCMD)
rootCMD.AddCommand(createCMD)
}

func initConfig() {
Expand Down
23 changes: 23 additions & 0 deletions cmd/devstream/start.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package main

import (
"fmt"

"github.com/spf13/cobra"

"github.com/devstream-io/devstream/internal/pkg/start"
)

var startCMD = &cobra.Command{
Use: "start",
Short: "start",
Long: `start.`,
Run: startCMDFunc,
}

func startCMDFunc(_ *cobra.Command, _ []string) {
err := start.Start()
if err != nil && err.Error() != "^C" {
fmt.Printf("Failed with error: %s", err)
}
}
2 changes: 1 addition & 1 deletion docs/plugins/helm-installer/devlake.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@ tools:
| chart.releaseName | devlake | helm release name |
| chart.namespace | devlake | namespace where helm to deploy |
| chart.wait | true | whether to wait until installation is complete |
| repo.url | https://merico-dev.github.io/devlake-helm-chart | helm official repo address |
| repo.url | https://apache.github.io/incubator-devlake-helm-chart | helm official repo address |
| repo.name | devlake | helm repo name |
2 changes: 1 addition & 1 deletion docs/plugins/helm-installer/devlake.zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@ tools:
| chart.releaseName | devlake | helm 发布名称 |
| chart.namespace | devlake | 部署的命名空间 |
| chart.wait | true | 是否等待部署完成 |
| repo.url | https://merico-dev.github.io/devlake-helm-chart | helm 仓库地址 |
| repo.url | https://apache.github.io/incubator-devlake-helm-chart | helm 仓库地址 |
| repo.name | devlake | helm 仓库名 |
7 changes: 4 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ require (
github.com/aws/aws-sdk-go-v2/config v1.15.5
github.com/aws/aws-sdk-go-v2/service/s3 v1.26.9
github.com/bndr/gojenkins v1.1.0
github.com/briandowns/spinner v1.20.0
github.com/cenkalti/backoff v2.2.1+incompatible
github.com/cheggaaa/pb v1.0.29
github.com/deckarep/golang-set/v2 v2.1.0
Expand All @@ -21,6 +22,7 @@ require (
github.com/hashicorp/go-cleanhttp v0.5.2
github.com/hashicorp/go-getter v1.6.2
github.com/imdario/mergo v0.3.12
github.com/manifoldco/promptui v0.9.0
github.com/mitchellh/mapstructure v1.5.0
github.com/mittwald/go-helm-client v0.8.4
github.com/onsi/ginkgo/v2 v2.1.4
Expand All @@ -35,7 +37,7 @@ require (
github.com/xanzy/go-gitlab v0.74.0
go.uber.org/multierr v1.6.0
golang.org/x/crypto v0.1.0
golang.org/x/exp v0.0.0-20221114191408-850992195362
golang.org/x/exp v0.0.0-20230131160201-f062dba9d201
golang.org/x/oauth2 v0.0.0-20220722155238-128564f6959c
gopkg.in/gookit/color.v1 v1.1.6
gopkg.in/yaml.v3 v3.0.1
Expand Down Expand Up @@ -83,6 +85,7 @@ require (
github.com/bradleyfalzon/ghinstallation/v2 v2.0.3 // indirect
github.com/cespare/xxhash/v2 v2.1.2 // indirect
github.com/chai2010/gettext-go v0.0.0-20170215093142-bf70f2a70fb1 // indirect
github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e // indirect
github.com/containerd/containerd v1.5.7 // indirect
github.com/cyphar/filepath-securejoin v0.2.2 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
Expand Down Expand Up @@ -171,7 +174,6 @@ require (
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/monochromegane/go-gitignore v0.0.0-20200626010858-205db1a8cc00 // indirect
github.com/morikuni/aec v1.0.0 // indirect
github.com/nxadm/tail v1.4.8 // indirect
github.com/opencontainers/go-digest v1.0.0 // indirect
github.com/opencontainers/image-spec v1.0.1 // indirect
github.com/patrickmn/go-cache v2.1.0+incompatible // indirect
Expand Down Expand Up @@ -223,7 +225,6 @@ require (
gopkg.in/gorp.v1 v1.7.2 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/ini.v1 v1.62.0 // indirect
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 // indirect
gopkg.in/warnings.v0 v0.1.2 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
k8s.io/apiextensions-apiserver v0.22.4 // indirect
Expand Down
12 changes: 10 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,8 @@ github.com/bombsimon/logrusr v1.0.0/go.mod h1:Jq0nHtvxabKE5EMwAAdgTaz7dfWE8C4i11
github.com/bradleyfalzon/ghinstallation/v2 v2.0.2/go.mod h1:GhRUp70E+QFvNemlFd4unyHZ8ryBiMQkJm6KgdilpUo=
github.com/bradleyfalzon/ghinstallation/v2 v2.0.3 h1:ywF/8q+GVpvlsEuvRb1SGSDQDUxntW1d4kFu/9q/YAE=
github.com/bradleyfalzon/ghinstallation/v2 v2.0.3/go.mod h1:tlgi+JWCXnKFx/Y4WtnDbZEINo31N5bcvnCoqieefmk=
github.com/briandowns/spinner v1.20.0 h1:GQq1Yf1KyzYT8CY19GzWrDKP6hYOFB6J72Ks7d8aO1U=
github.com/briandowns/spinner v1.20.0/go.mod h1:TcwZHb7Wb6vn/+bcVv1UXEzaA4pLS7yznHlkY/HzH44=
github.com/bshuster-repo/logrus-logstash-hook v0.4.1/go.mod h1:zsTqEiSzDgAa/8GZR7E1qaXrhYNDKBYy5/dWPTIflbk=
github.com/bshuster-repo/logrus-logstash-hook v1.0.0 h1:e+C0SB5R1pu//O4MQ3f9cFuPGoOVeF2fE4Og9otCc70=
github.com/bshuster-repo/logrus-logstash-hook v1.0.0/go.mod h1:zsTqEiSzDgAa/8GZR7E1qaXrhYNDKBYy5/dWPTIflbk=
Expand Down Expand Up @@ -258,8 +260,11 @@ github.com/checkpoint-restore/go-criu/v5 v5.0.0/go.mod h1:cfwC0EG7HMUenopBsUf9d8
github.com/cheggaaa/pb v1.0.27/go.mod h1:pQciLPpbU0oxA0h+VJYYLxO+XeDQb5pZijXscXHm81s=
github.com/cheggaaa/pb v1.0.29 h1:FckUN5ngEk2LpvuG0fw1GEFx6LtyY2pWI/Z2QgCnEYo=
github.com/cheggaaa/pb v1.0.29/go.mod h1:W40334L7FMC5JKWldsTWbdGjLo0RxUKK73K+TuPxX30=
github.com/chzyer/logex v1.1.10 h1:Swpa1K6QvQznwJRcfTfQJmTE72DqScAa40E+fbHEXEE=
github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI=
github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e h1:fY5BOSpyZCqRo5OhCuC+XN+r/bBCmeuuJtjz+bCNIf8=
github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI=
github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1 h1:q763qf9huN11kDQavWsoZXJNW3xEE4JJyHa5Q25/sd8=
github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU=
github.com/cilium/ebpf v0.0.0-20200110133405-4032b1d8aae3/go.mod h1:MA5e5Lr8slmEg9bt0VpxxWqJlO4iwu3FBdHUzV7wQVg=
github.com/cilium/ebpf v0.0.0-20200702112145-1c8d4c9ef775/go.mod h1:7cR51M8ViRLIdUjrmSXlK9pkrsDlLHbO8jiB8X8JnOc=
Expand Down Expand Up @@ -940,6 +945,8 @@ github.com/mailru/easyjson v0.7.6/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJ
github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0=
github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc=
github.com/malexdev/utfutil v0.0.0-20180510171754-00c8d4a8e7a8/go.mod h1:UtpLyb/EupVKXF/N0b4NRe1DNg+QYJsnsHQ038romhM=
github.com/manifoldco/promptui v0.9.0 h1:3V4HzJk1TtXW1MTZMP7mdlwbBpIinw3HztaIlYthEiA=
github.com/manifoldco/promptui v0.9.0/go.mod h1:ka04sppxSGFAtxX0qhlYQjISsg9mR4GWtQEhdbn6Pgg=
github.com/markbates/errx v1.1.0 h1:QDFeR+UP95dO12JgW+tgi2UVfo0V8YBHiUIOaeBPiEI=
github.com/markbates/errx v1.1.0/go.mod h1:PLa46Oex9KNbVDZhKel8v1OT7hD5JZ2eI7AHhA0wswc=
github.com/markbates/oncer v1.0.0 h1:E83IaVAHygyndzPimgUYJjbshhDTALZyXxvk9FOlQRY=
Expand All @@ -950,6 +957,7 @@ github.com/marstr/guid v1.1.0/go.mod h1:74gB1z2wpxxInTG6yaqA7KrtM0NZ+RbrcqDvYHef
github.com/matryer/is v1.2.0 h1:92UTHpy8CDwaJ08GqLDzhhuixiBUUD1p3AU6PHddz4A=
github.com/matryer/is v1.2.0/go.mod h1:2fLPjFQM9rhQ15aVEtbuwhJinnOqrmgXPNdZsdwlWXA=
github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU=
github.com/mattn/go-colorable v0.1.2/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE=
github.com/mattn/go-colorable v0.1.4/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE=
github.com/mattn/go-colorable v0.1.8/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc=
github.com/mattn/go-colorable v0.1.9/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc=
Expand Down Expand Up @@ -1477,8 +1485,8 @@ golang.org/x/exp v0.0.0-20200207192155-f17229e696bd/go.mod h1:J/WKrq2StrnmMY6+EH
golang.org/x/exp v0.0.0-20200224162631-6cc2880d07d6/go.mod h1:3jZMyOhIsHpP37uCMkUooju7aAi5cS1Q23tOzKc+0MU=
golang.org/x/exp v0.0.0-20210220032938-85be41e4509f/go.mod h1:I6l2HNBLBZEcrOoCpyKLdY2lHoRZ8lI4x60KMCQDft4=
golang.org/x/exp v0.0.0-20210901193431-a062eea981d2/go.mod h1:a3o/VtDNHN+dCVLEpzjjUHOzR+Ln3DHX056ZPzoZGGA=
golang.org/x/exp v0.0.0-20221114191408-850992195362 h1:NoHlPRbyl1VFI6FjwHtPQCN7wAMXI6cKcqrmXhOOfBQ=
golang.org/x/exp v0.0.0-20221114191408-850992195362/go.mod h1:CxIveKay+FTh1D0yPZemJVgC/95VzuuOLq5Qi4xnoYc=
golang.org/x/exp v0.0.0-20230131160201-f062dba9d201 h1:BEABXpNXLEz0WxtA+6CQIz2xkg80e+1zrhWyMcq8VzE=
golang.org/x/exp v0.0.0-20230131160201-f062dba9d201/go.mod h1:CxIveKay+FTh1D0yPZemJVgC/95VzuuOLq5Qi4xnoYc=
golang.org/x/image v0.0.0-20180708004352-c73c2afc3b81/go.mod h1:ux5Hcp/YLpHSI86hEcLt0YII63i6oz57MZXIpbrjZUs=
golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js=
golang.org/x/image v0.0.0-20190802002840-cff245a6509b/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
Expand Down
138 changes: 138 additions & 0 deletions internal/pkg/create/create.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
package create

import (
"fmt"
"time"

"github.com/devstream-io/devstream/internal/pkg/configmanager"
"github.com/devstream-io/devstream/internal/pkg/create/param"
"github.com/devstream-io/devstream/internal/pkg/plugin/argocdapp"
general "github.com/devstream-io/devstream/internal/pkg/plugin/githubactions"
"github.com/devstream-io/devstream/internal/pkg/plugin/reposcaffolding"
"github.com/devstream-io/devstream/pkg/util/cli"
)

func Create() error {
params, err := param.GetParams()
if err != nil {
return err
}
fmt.Printf("Start create app %s's stream...\n", params.GitHubRepo)
return create(params)
}

// create will do following three things:
// 1. create repo by repoScaffolding
// 2. config GitHub actions for this repo
// 3. create Argo CD application for this repo
func create(params *param.Param) error {
if err := createRepo(params); err != nil {
return err
}

if err := createApp(params); err != nil {
return err
}

// finalMessage is used to help user to vist this app
finalMessage := `You can now connect to you app with:

kubectl port-forward service/%s 8080:8080 -n default

Then you can visit this app by http://127.0.0.1:8080 in your browser.

Happy Hacking! 😊
`
fmt.Printf(finalMessage, params.GitHubRepo)
return nil
}

func createRepo(params *param.Param) error {
repoOptions := configmanager.RawOptions{
"owner": params.GithubUsername,
"name": params.GitHubRepo,
"scmType": "github",
"token": params.GithubToken,
}

// 1.create repo
status := cli.StatusForPlugin()
repoScaffoldingOptions := configmanager.RawOptions{
"destinationRepo": repoOptions,
"sourceRepo": configmanager.RawOptions{
"url": params.RepoScaffoldingURL,
},
}
status.Start("Creating repo from scaffolding 🖼")
_, err := reposcaffolding.Create(repoScaffoldingOptions)
status.End(err)
if err != nil {
return err
}

// 2.config ci
ciOptions := configmanager.RawOptions{
"scm": repoOptions,
"pipeline": configmanager.RawOptions{
"language": configmanager.RawOptions{
"name": params.Language,
"framework": params.Framework,
},
"imageRepo": configmanager.RawOptions{
"user": params.DockerhubUsername,
"password": params.DockerhubToken,
},
},
}
status.Start("Writing github action configuration ✍️ ")
_, err = general.Create(ciOptions)
status.End(err)
status.Start("Waiting for github action finished 🐎")

// 3.wait repo ci finished
waitCIFinished()
status.End(err)
return err
}

func createApp(params *param.Param) error {
status := cli.StatusForPlugin()
argocdAppOption := configmanager.RawOptions{
"app": configmanager.RawOptions{
"name": params.GitHubRepo,
"namespace": "argocd",
},
"destination": configmanager.RawOptions{
"server": "https://kubernetes.default.svc",
"namespace": "default",
},
"source": configmanager.RawOptions{
"valuefile": "values.yaml",
"path": fmt.Sprintf("helm/%s", params.GitHubRepo),
"repoURL": fmt.Sprintf("https://github.com/%s/%s", params.GithubUsername, params.GitHubRepo),
"repoBranch": "main",
"token": params.GithubToken,
},
"imageRepo": configmanager.RawOptions{
"user": params.DockerhubUsername,
},
}
status.Start("Creating argocd app 🕹️")
_, err := argocdapp.Create(argocdAppOption)
status.End(err)
status.Start("Waiting for app to running 🚀")
// wait argocd app status to running
waitAppUp()
status.End(nil)
return err
}

// TODO(steinliber): add logic to wait for ci finished
func waitCIFinished() {
time.Sleep(70 * time.Second) // current github actions takes 62 seconds for finished
}

// TODO(steinliber): add logic to wait for pod start running
func waitAppUp() {
time.Sleep(30 * time.Second)
}
40 changes: 40 additions & 0 deletions internal/pkg/create/param/dockerhub.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package param

import (
"fmt"

"github.com/manifoldco/promptui"
)

func getDockerHubUsername() (string, error) {
prompt := promptui.Prompt{
Label: "What is your DockerHub username",
Validate: validate,
}

result, err := prompt.Run()

if err != nil {
fmt.Printf("Failed to get DockerHub username %v\n", err)
return "", err
}

return result, nil
}

func getDockerHubToken() (string, error) {
prompt := promptui.Prompt{
Label: "Please input your DockerHub Personal Access Token",
Mask: '*',
Validate: validate,
}

result, err := prompt.Run()

if err != nil {
fmt.Printf("Failed to get DockerHub token %v\n", err)
return "", err
}

return result, nil
}
Loading