Skip to content
This repository was archived by the owner on Mar 9, 2025. It is now read-only.

Commit 1fc3f9b

Browse files
authoredMar 29, 2023
Simplifying the installer (#473)
1 parent d4dfa3c commit 1fc3f9b

File tree

4 files changed

+33
-238
lines changed

4 files changed

+33
-238
lines changed
 

‎cmd/installer/main.go

+20-76
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ import (
2525
"github.com/gimlet-io/gimlet-cli/pkg/git/customScm/customGitlab"
2626
"github.com/gimlet-io/gimlet-cli/pkg/git/genericScm"
2727
"github.com/gimlet-io/gimlet-cli/pkg/git/nativeGit"
28-
"github.com/gimlet-io/gimlet-cli/pkg/gitops"
2928
"github.com/gimlet-io/gimlet-cli/pkg/server/token"
3029
"github.com/gimlet-io/gimlet-cli/pkg/stack"
3130
"github.com/go-chi/chi/v5"
@@ -89,23 +88,7 @@ func main() {
8988
Stack: dx.StackRef{
9089
Repository: stackUrl,
9190
},
92-
Config: map[string]interface{}{
93-
"k3s": map[string]interface{}{
94-
"host": os.Getenv("HOST"),
95-
},
96-
"civo": map[string]interface{}{
97-
"host": os.Getenv("HOST"),
98-
},
99-
"nginx": map[string]interface{}{
100-
"enabled": true,
101-
"host": os.Getenv("HOST"),
102-
},
103-
"gimletd": map[string]interface{}{
104-
"environments": []map[string]interface{}{
105-
{},
106-
},
107-
},
108-
},
91+
Config: map[string]interface{}{},
10992
}
11093

11194
stackDefinition, err := loadStackDefinition(stackConfig)
@@ -170,21 +153,15 @@ func main() {
170153
srv.Shutdown(context.TODO())
171154
}
172155

173-
func initStackConfig(data *data) string {
156+
func initStackConfig(data *data) {
174157
jwtSecret, _ := randomHex(32)
175158
agentAuth := jwtauth.New("HS256", []byte(jwtSecret), nil)
176159
_, agentToken, _ := agentAuth.Encode(map[string]interface{}{"user_id": "gimlet-agent"})
177160

178161
webhookSecret, _ := randomHex(32)
179-
privateKeyBytes, publicKeyBytes, err := gitops.GenerateEd25519()
180-
if err != nil {
181-
panic(err)
182-
}
183-
gimletdPublicKey := string(publicKeyBytes)
184162

185163
postgresPassword := base32.StdEncoding.EncodeToString(securecookie.GenerateRandomKey(32))
186164
dashboardPassword := base32.StdEncoding.EncodeToString(securecookie.GenerateRandomKey(32))
187-
gimletdPassword := base32.StdEncoding.EncodeToString(securecookie.GenerateRandomKey(32))
188165

189166
gimletdAdminToken := base32.StdEncoding.EncodeToString(securecookie.GenerateRandomKey(32))
190167
token := token.New(token.UserToken, "admin")
@@ -197,40 +174,19 @@ func initStackConfig(data *data) string {
197174
"install": true,
198175
"hostAndPort": "postgresql:5432",
199176
"postgresPassword": postgresPassword,
200-
"db": "gimlet_dashboard",
201-
"user": "gimlet_dashboard",
177+
"db": "gimlet",
178+
"user": "gimlet",
202179
"password": dashboardPassword,
203180
}
204-
gimletdPostgresConfig := map[string]interface{}{
205-
"install": true,
206-
"hostAndPort": "postgresql:5432",
207-
"postgresPassword": postgresPassword,
208-
"db": "gimletd",
209-
"user": "gimletd",
210-
"password": gimletdPassword,
211-
}
212-
213-
data.stackConfig.Config["gimletd"] = map[string]interface{}{
214-
"enabled": true,
215-
"environments": []map[string]interface{}{{
216-
"name": "will be set from user input on the ui",
217-
"repoPerEnv": "will be set from user input on the ui",
218-
"gitopsRepo": "will be set from user input on the ui",
219-
"deployKey": string(privateKeyBytes),
220-
},
221-
},
222-
"adminToken": gimletdAdminToken,
223-
"postgresql": gimletdPostgresConfig,
224-
}
225181

226182
data.stackConfig.Config["gimletAgent"] = map[string]interface{}{
227183
"enabled": true,
228184
"environment": "will be set from user input on the ui",
229-
"dashboardAddress": "http://gimlet-dashboard:9000",
185+
"dashboardAddress": "http://gimlet:9000",
230186
"agentKey": agentToken,
231187
}
232188

233-
data.stackConfig.Config["gimletDashboard"] = map[string]interface{}{
189+
data.stackConfig.Config["gimlet"] = map[string]interface{}{
234190
"enabled": true,
235191
"jwtSecret": jwtSecret,
236192
"gimletdToken": gimletdSignedAdminToken,
@@ -239,14 +195,13 @@ func initStackConfig(data *data) string {
239195
"postgresql": dashboardPostgresConfig,
240196
"gimletdURL": "http://gimletd:8888",
241197
"host": fmt.Sprintf("http://gimlet.%s:%s", os.Getenv("HOST"), "9000"),
198+
"adminToken": gimletdAdminToken,
242199
}
243-
244-
return gimletdPublicKey
245200
}
246201

247202
func setGithubStackConfig(data *data) {
248203
data.github = true
249-
gimletDashboardConfig := data.stackConfig.Config["gimletDashboard"].(map[string]interface{})
204+
gimletDashboardConfig := data.stackConfig.Config["gimlet"].(map[string]interface{})
250205

251206
gimletDashboardConfig["githubOrg"] = data.appOwner
252207
gimletDashboardConfig["githubAppId"] = data.id
@@ -258,17 +213,16 @@ func setGithubStackConfig(data *data) {
258213

259214
func setGitlabStackConfig(data *data, token string) {
260215
data.gitlab = true
261-
gimletDashboardConfig := data.stackConfig.Config["gimletDashboard"].(map[string]interface{})
216+
gimletDashboardConfig := data.stackConfig.Config["gimlet"].(map[string]interface{})
262217

263218
gimletDashboardConfig["gitlabOrg"] = data.appOwner
264219
gimletDashboardConfig["gitlabClientId"] = data.clientId
265220
gimletDashboardConfig["gitlabClientSecret"] = data.clientSecret
266221
gimletDashboardConfig["gitlabAdminToken"] = token
267222
gimletDashboardConfig["gitlabUrl"] = data.scmURL
268223

269-
gimletdConfig := data.stackConfig.Config["gimletd"].(map[string]interface{})
270224
scmHost := strings.Split(data.scmURL, "://")[1]
271-
gimletdConfig["gitSSHAddressFormat"] = "git@" + scmHost + ":%s.git"
225+
gimletDashboardConfig["gitSSHAddressFormat"] = "git@" + scmHost + ":%s.git"
272226
}
273227

274228
func getContext(w http.ResponseWriter, r *http.Request) {
@@ -289,7 +243,6 @@ func getContext(w http.ResponseWriter, r *http.Request) {
289243
"clientSecret": data.clientSecret,
290244
"pem": data.pem,
291245
"org": data.appOwner,
292-
"gimletdPublicKey": data.gimletdPublicKey,
293246
"infraGitopsRepoFileName": data.infraGitopsRepoFileName,
294247
"infraPublicKey": data.infraPublicKey,
295248
"infraSecretFileName": data.infraSecretFileName,
@@ -451,8 +404,7 @@ func auth(w http.ResponseWriter, r *http.Request) {
451404
}
452405
data.loggedInUser = scmUser.Login
453406

454-
gimletdPublicKey := initStackConfig(data)
455-
data.gimletdPublicKey = gimletdPublicKey
407+
initStackConfig(data)
456408

457409
data.scmURL = "https://github.com"
458410
setGithubStackConfig(data)
@@ -508,26 +460,16 @@ func bootstrap(w http.ResponseWriter, r *http.Request) {
508460
infraRepo := formValues.Get("infra")
509461
appsRepo := formValues.Get("apps")
510462
envName := formValues.Get("env")
511-
stackConfigString := formValues.Get("stackConfig")
512-
err = json.Unmarshal([]byte(stackConfigString), &data.stackConfig.Config)
513-
if err != nil {
514-
panic(err)
515-
}
516463
repoPerEnv, err := strconv.ParseBool(formValues.Get("repoPerEnv"))
517464
if err != nil {
518465
panic(err)
519466
}
520467

521-
gimletdConfig := data.stackConfig.Config["gimletd"].(map[string]interface{})
522-
environments := gimletdConfig["environments"].([]interface{})
523-
envConfig := environments[0].(map[string]interface{})
524-
525468
if !strings.Contains(infraRepo, "/") {
526469
infraRepo = filepath.Join(data.appOwner, infraRepo)
527470
}
528471
if !strings.Contains(appsRepo, "/") {
529472
appsRepo = filepath.Join(data.appOwner, appsRepo)
530-
envConfig["gitopsRepo"] = appsRepo
531473
}
532474

533475
data.infraRepo = infraRepo
@@ -619,14 +561,14 @@ func bootstrap(w http.ResponseWriter, r *http.Request) {
619561
panic(err)
620562
}
621563

622-
gimletDashboardConfig := data.stackConfig.Config["gimletDashboard"].(map[string]interface{})
623-
gimletdURL := "http://gimletd.infrastructure.svc.cluster.local:8888"
624-
gimletdSignedAdminToken := gimletDashboardConfig["gimletdToken"].(string)
564+
gimletDashboardConfig := data.stackConfig.Config["gimlet"].(map[string]interface{})
565+
gimletURL := "http://gimlet.infrastructure.svc.cluster.local:8888"
566+
gimletSignedAdminToken := gimletDashboardConfig["gimletdToken"].(string)
625567

626568
notificationsFileName, err := server.BootstrapNotifications(
627569
gitRepoCache,
628-
gimletdURL,
629-
gimletdSignedAdminToken,
570+
gimletURL,
571+
gimletSignedAdminToken,
630572
envName,
631573
appsRepo,
632574
repoPerEnv,
@@ -640,6 +582,9 @@ func bootstrap(w http.ResponseWriter, r *http.Request) {
640582

641583
gimletDashboardConfig["bootstrapEnv"] = fmt.Sprintf("name=%s&repoPerEnv=%t&infraRepo=%s&appsRepo=%s", envName, repoPerEnv, infraRepo, appsRepo)
642584

585+
gimletAgentConfig := data.stackConfig.Config["gimletAgent"].(map[string]interface{})
586+
gimletAgentConfig["environment"] = envName
587+
643588
data.infraGitopsRepoFileName = infraGitopsRepoFileName
644589
data.infraSecretFileName = infraSecretFileName
645590

@@ -775,8 +720,7 @@ func gitlabInit(w http.ResponseWriter, r *http.Request) {
775720

776721
data.loggedInUser = user.Username
777722

778-
gimletdPublicKey := initStackConfig(data)
779-
data.gimletdPublicKey = gimletdPublicKey
723+
initStackConfig(data)
780724

781725
data.scmURL = gitlabUrl
782726
setGitlabStackConfig(data, token)

‎web/installer/package-lock.json

+12-9
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎web/installer/src/stepThree.jsx

-6
Original file line numberDiff line numberDiff line change
@@ -153,12 +153,6 @@ const StepThree = ({ getContext }) => {
153153
scmUrl={context.scmUrl}
154154
/>
155155
<GitopsAutomationGuide />
156-
<div className="rounded-md bg-blue-50 p-4 mb-4 overflow-hidden">
157-
<ul className="break-all text-sm text-blue-700 space-y-2">
158-
<li>👉 Add the following deploy key to your Git provider to the <a href={`${context.scmUrl}/${context.appsRepo}` + (context.scmUrl === "https://github.com" ? "/settings/keys" : "/-/settings/repository#js-deploy-keys-settings")} rel="noreferrer" target="_blank" className="font-medium hover:text-blue-900">{context.appsRepo}</a> repository <span className="font-bold">with write access</span>.</li>
159-
<li className="text-xs font-mono bg-blue-100 font-medium text-blue-500 px-1 py-1 rounded">{context.gimletdPublicKey}</li>
160-
</ul>
161-
</div>
162156
<div className='text-gray-900 mt-16 mb-32'>
163157
<h2 className=''>Happy Gitopsing🎊</h2>
164158
<h2 className='mt-16 font-bold'>Now you can close this browser tab, and return to the Terminal to finalize the install.</h2>

‎web/installer/src/stepTwo.jsx

+1-147
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,12 @@
11
import { useEffect, useState } from 'react';
2-
import StackUI from './stack-ui';
32
import SeparateEnvironments from './separateEnvironments';
43

5-
const StepTwo = ({ getContext }) => {
6-
const [context, setContext] = useState({
7-
stackConfig: {
8-
config: {
9-
gimletd: {
10-
environments: [{}]
11-
},
12-
gimletAgent: {},
13-
}
14-
}
15-
});
16-
4+
const StepTwo = () => {
175
const [env, setEnv] = useState('test');
186
const [repoPerEnv, setRepoPerEnv] = useState(true);
197
const [infra, setInfra] = useState('gitops-test-infra');
208
const [apps, setApps] = useState('gitops-test-apps');
219

22-
useEffect(() => {
23-
getContext().then(data => {
24-
let environment = data.stackConfig.config.gimletd.environments[0]
25-
environment.name = env
26-
environment.repoPerEnv = repoPerEnv
27-
environment.gitopsRepo = apps
28-
29-
setContext({
30-
...data,
31-
stackConfig: {
32-
...data.stackConfig,
33-
config: {
34-
...data.stackConfig.config,
35-
gimletAgent: {
36-
...data.stackConfig.config.gimletAgent,
37-
environment: env
38-
},
39-
gimletd: {
40-
...data.stackConfig.config.gimletd,
41-
environments: [environment]
42-
}
43-
}
44-
}
45-
})
46-
}).catch(err => {
47-
console.error(`Error: ${err}`);
48-
});
49-
}, [getContext, apps, env, repoPerEnv]);
50-
5110
useEffect(() => {
5211
if (repoPerEnv) {
5312
setInfra(`gitops-${env}-infra`);
@@ -58,77 +17,6 @@ const StepTwo = ({ getContext }) => {
5817
}
5918
}, [repoPerEnv, env]);
6019

61-
useEffect(() => {
62-
setContext(oldContext => {
63-
if (!oldContext) {
64-
return null;
65-
}
66-
67-
let environment = oldContext.stackConfig.config.gimletd.environments[0]
68-
environment.name = env
69-
environment.repoPerEnv = repoPerEnv
70-
environment.gitopsRepo = repoPerEnv ? `gitops-${env}-apps` : `gitops-apps`
71-
72-
return {
73-
...oldContext,
74-
stackConfig: {
75-
...oldContext.stackConfig,
76-
config: {
77-
...oldContext.stackConfig.config,
78-
gimletAgent: {
79-
...oldContext.stackConfig.config.gimletAgent,
80-
environment: env
81-
},
82-
gimletd: {
83-
...oldContext.stackConfig.config.gimletd,
84-
environments: [environment]
85-
}
86-
}
87-
}
88-
}
89-
})
90-
}, [repoPerEnv, env]);
91-
92-
if (!context) {
93-
return null;
94-
}
95-
96-
const disableNginxIfK3s = (variable, values, nonDefaultValues) => {
97-
if (variable === 'nginx') {
98-
return nonDefaultValues
99-
} else if (variable === 'k3s' && values.enabled) {
100-
return {
101-
...context.stackConfig.config.nginx,
102-
enabled: false
103-
}
104-
} else {
105-
return context.stackConfig.config.nginx
106-
}
107-
}
108-
109-
const setValues = (variable, values, nonDefaultValues) => {
110-
const nginx = disableNginxIfK3s(variable, values, nonDefaultValues)
111-
112-
setContext({
113-
...context,
114-
stackConfig: {
115-
...context.stackConfig,
116-
config: {
117-
...context.stackConfig.config,
118-
[variable]: nonDefaultValues,
119-
nginx: nginx
120-
}
121-
}
122-
})
123-
}
124-
125-
const validationCallback = (variable, validationErrors) => {
126-
if (validationErrors !== null) {
127-
console.log(validationErrors)
128-
alert(validationErrors)
129-
}
130-
}
131-
13220
return (
13321
<div className="mt-32 max-w-7xl mx-auto px-4 sm:px-6 lg:px-8">
13422
<div className="max-w-4xl mx-auto">
@@ -199,25 +87,6 @@ const StepTwo = ({ getContext }) => {
19987
</ol>
20088
</nav>
20189

202-
{context.appId === "" &&
203-
<div className="rounded-md bg-red-50 p-4 my-8">
204-
<div className="flex">
205-
<div className="flex-shrink-0">
206-
{/* <!-- Heroicon name: solid/x-circle --> */}
207-
<svg className="h-5 w-5 text-red-400" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor"
208-
aria-hidden="true">
209-
<path fillRule="evenodd"
210-
d="M10 18a8 8 0 100-16 8 8 0 000 16zM8.707 7.293a1 1 0 00-1.414 1.414L8.586 10l-1.293 1.293a1 1 0 101.414 1.414L10 11.414l1.293 1.293a1 1 0 001.414-1.414L11.414 10l1.293-1.293a1 1 0 00-1.414-1.414L10 8.586 8.707 7.293z"
211-
clipRule="evenodd" />
212-
</svg>
213-
</div>
214-
<div className="ml-3">
215-
<h3 className="text-sm font-medium text-red-800">A Github Application was not yet created by the installer. Go
216-
to <a href="/" className="font-bold">Step One</a> to create it.</h3>
217-
</div>
218-
</div>
219-
</div>
220-
}
22190
<form action="/bootstrap" method="post">
22291
<div className="mt-8 text-sm">
22392

@@ -247,21 +116,6 @@ const StepTwo = ({ getContext }) => {
247116
/>
248117
<input type="hidden" name="repoPerEnv" value={repoPerEnv} />
249118

250-
<div className='mt-8 mb-16'>
251-
{context.stackDefinition && context.stackConfig &&
252-
<StackUI
253-
stack={context.stackConfig.config}
254-
stackDefinition={context.stackDefinition}
255-
setValues={setValues}
256-
validationCallback={validationCallback}
257-
categoriesToRender={['cloud', 'ingress', 'gimlet']}
258-
componentsToRender={['civo', 'k3s', 'nginx', 'gimletd', 'gimletAgent', 'gimletDashboard']}
259-
hideTitle={true}
260-
/>
261-
}
262-
</div>
263-
<input type="hidden" name="stackConfig" value={JSON.stringify(context.stackConfig.config)} />
264-
265119
<div className="p-0 flow-root my-8">
266120
<span className="inline-flex rounded-md shadow-sm gap-x-3 float-right">
267121
<button

0 commit comments

Comments
 (0)
This repository has been archived.