@@ -4,44 +4,131 @@ import (
44 "fmt"
55 "time"
66
7+ "github.com/devstream-io/devstream/internal/pkg/configmanager"
78 "github.com/devstream-io/devstream/internal/pkg/create/param"
9+ "github.com/devstream-io/devstream/internal/pkg/plugin/argocdapp"
10+ general "github.com/devstream-io/devstream/internal/pkg/plugin/githubactions"
11+ "github.com/devstream-io/devstream/internal/pkg/plugin/reposcaffolding"
12+ "github.com/devstream-io/devstream/pkg/util/cli"
813)
914
1015func Create () error {
11- helloMsg := func () {
12- fmt .Println ("I'll scaffold a new repository for you." )
13- time .Sleep (time .Second )
14- fmt .Println ("Are you ready?" )
15- time .Sleep (time .Second )
16- fmt .Println ("Let's get started." )
17- time .Sleep (time .Second )
18- }
19- helloMsg ()
20-
2116 params , err := param .GetParams ()
2217 if err != nil {
2318 return err
2419 }
25-
20+ fmt . Printf ( "Start create app %s's stream... \n " , params . GitHubRepo )
2621 return create (params )
2722}
2823
29- // TODO: @jf
24+ // create will do folling three things:
25+ // 1. create repo by repoScaffolding
26+ // 2. config github actions for this repo
27+ // 3. create argocd application for this repo
3028func create (params * param.Param ) error {
31- err := createRepo (params )
32- if err != nil {
29+ if err := createRepo (params ); err != nil {
3330 return err
3431 }
3532
36- return createApp (params )
37- }
33+ if err := createApp (params ); err != nil {
34+ return err
35+ }
3836
39- // TODO(daniel-hutao): support python/flask first
40- func createRepo (params * param.Param ) error {
41- fmt .Printf ("Lang: %s, Fram: %s\n " , params .Language , params .Framework )
37+ // finalMessage is used to help user to vist this app
38+ finalMessage := `You can now connect to you app with:
39+
40+ kubectl port-forward service/%s 8080:8080 -n default
41+
42+ Then you can visit this app by http://127.0.0.1:8080 in browser
43+ Thanks for using DevStream! 😊
44+ `
45+ fmt .Printf (finalMessage , params .GitHubRepo )
4246 return nil
4347}
4448
49+ func createRepo (params * param.Param ) error {
50+ repoOptions := configmanager.RawOptions {
51+ "owner" : params .GithubUsername ,
52+ "name" : params .GitHubRepo ,
53+ "scmType" : "github" ,
54+ "token" : params .GithubToken ,
55+ }
56+ // 1.create repo
57+ status := cli .StatusForPlugin ()
58+ repoScaffoldingOptions := configmanager.RawOptions {
59+ "destinationRepo" : repoOptions ,
60+ "sourceRepo" : configmanager.RawOptions {
61+ "url" : params .RepoScaffoldingURL ,
62+ },
63+ }
64+ status .Start ("Creating repo from scaffolding 🖼" )
65+ _ , err := reposcaffolding .Create (repoScaffoldingOptions )
66+ status .End (err )
67+ if err != nil {
68+ return err
69+ }
70+ // 2.config ci
71+ ciOptions := configmanager.RawOptions {
72+ "scm" : repoOptions ,
73+ "pipeline" : configmanager.RawOptions {
74+ "language" : configmanager.RawOptions {
75+ "name" : params .Language ,
76+ "framework" : params .Framework ,
77+ },
78+ "imageRepo" : configmanager.RawOptions {
79+ "user" : params .DockerhubUsername ,
80+ "password" : params .DockerhubToken ,
81+ },
82+ },
83+ }
84+ status .Start ("Writing github action configuration ✍️ " )
85+ _ , err = general .Create (ciOptions )
86+ status .End (err )
87+ status .Start ("Waiting for github action finished 🐎" )
88+ // 3.wait repo ci finished
89+ waitCIFinished ()
90+ status .End (err )
91+ return err
92+
93+ }
4594func createApp (params * param.Param ) error {
46- return nil
95+ status := cli .StatusForPlugin ()
96+ argocdAppOption := configmanager.RawOptions {
97+ "app" : configmanager.RawOptions {
98+ "name" : params .GitHubRepo ,
99+ "namespace" : "argocd" ,
100+ },
101+ "destination" : configmanager.RawOptions {
102+ "server" : "https://kubernetes.default.svc" ,
103+ "namespace" : "default" ,
104+ },
105+ "source" : configmanager.RawOptions {
106+ "valuefile" : "values.yaml" ,
107+ "path" : fmt .Sprintf ("helm/%s" , params .GitHubRepo ),
108+ "repoURL" : fmt .Sprintf ("https://github.com/%s/%s" , params .GithubUsername , params .GitHubRepo ),
109+ "repoBranch" : "main" ,
110+ "token" : params .GithubToken ,
111+ },
112+ "imageRepo" : configmanager.RawOptions {
113+ "user" : params .DockerhubUsername ,
114+ },
115+ }
116+ status .Start ("Creating argocd app 🕹️" )
117+ _ , err := argocdapp .Create (argocdAppOption )
118+ status .End (err )
119+ status .Start ("Waiting for app to running 🚀" )
120+ // wait argocd app status to running
121+ waitAppUp ()
122+ status .End (nil )
123+ return err
124+ }
125+
126+ // TODO(steinliber): add logic to wait for ci finished
127+ func waitCIFinished () {
128+ time .Sleep (70 * time .Second ) // current github actions takes 62 seconds for finished
129+ }
130+
131+ // TODO(steinliber): add logic to wait for pod start running
132+ func waitAppUp () {
133+ time .Sleep (30 * time .Second )
47134}
0 commit comments