Skip to content

Commit

Permalink
Installer in Dashboard (#520)
Browse files Browse the repository at this point in the history
  • Loading branch information
dzsak authored Jun 27, 2023
1 parent 3d0b01a commit c624b99
Show file tree
Hide file tree
Showing 68 changed files with 1,198 additions and 2,965 deletions.
20 changes: 0 additions & 20 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -173,26 +173,6 @@ jobs:
- name: 🏗️ Build dashboard frontend
run: make build-dashboard-frontend

installer:
name: 🏗️ Build Installer
runs-on: ubuntu-latest
needs: test
steps:
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: 1.20.0
- name: ⬇️ Check out code into the Go module directory
uses: actions/checkout@v1
with:
fetch-depth: 5
- name: 🏗️ Build installer frontend
run: make build-installer-frontend
- name: 🏗️ Build Installer
run: make build-installer
env:
VERSION: "ci-build"

image-builder:
name: 🏗️ Build Image builder
runs-on: ubuntu-latest
Expand Down
72 changes: 0 additions & 72 deletions .github/workflows/publish-installer.yml

This file was deleted.

8 changes: 0 additions & 8 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,6 @@
"mode": "auto",
"program": "cmd/image-builder",
},
{
"name": "Installer",
"type": "go",
"request": "launch",
"mode": "auto",
"program": "cmd/installer",
"envFile": "${workspaceFolder}/.env"
},
{
"name": "bootstrap",
"type": "go",
Expand Down
20 changes: 0 additions & 20 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ LDFLAGS = '-s -w -extldflags "-static" -X github.com/gimlet-io/gimlet-cli/pkg/ve

.PHONY: format test
.PHONY: build-cli dist-cli build-cli-frontend build-stack-frontend fast-dist-cli
.PHONY: build-installer dist-installer

format:
@gofmt -w ${GOFILES}
Expand All @@ -15,11 +14,6 @@ test-prep:
touch pkg/commands/chart/bundle.js
touch pkg/commands/chart/bundle.js.LICENSE.txt
touch pkg/commands/chart/index.html
touch cmd/installer/web/main.js
touch cmd/installer/web/1.chunk.js
touch cmd/installer/web/main.css
touch cmd/installer/web/index.html
touch cmd/installer/web/favicon.ico

test: test-prep
go test -timeout 60s $(shell go list ./...)
Expand Down Expand Up @@ -52,8 +46,6 @@ build-dashboard:
CGO_ENABLED=0 go build -ldflags $(LDFLAGS) -o build/gimlet-dashboard github.com/gimlet-io/gimlet-cli/cmd/dashboard
build-image-builder:
CGO_ENABLED=0 go build -ldflags $(LDFLAGS) -o build/image-builder github.com/gimlet-io/gimlet-cli/cmd/image-builder
build-installer:
CGO_ENABLED=0 go build -ldflags $(LDFLAGS) -o build/gimlet-installer github.com/gimlet-io/gimlet-cli/cmd/installer

dist-dashboard:
mkdir -p bin
Expand All @@ -74,11 +66,6 @@ fast-dist-cli:
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags $(LDFLAGS) -a -installsuffix cgo -o bin/gimlet-linux-x86_64 github.com/gimlet-io/gimlet-cli/cmd/cli
CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build -ldflags $(LDFLAGS) -a -installsuffix cgo -o bin/gimlet-darwin-x86_64 github.com/gimlet-io/gimlet-cli/cmd/cli
CGO_ENABLED=0 GOOS=darwin GOARCH=arm64 go build -ldflags $(LDFLAGS) -a -installsuffix cgo -o bin/gimlet-darwin-arm64 github.com/gimlet-io/gimlet-cli/cmd/cli
dist-installer:
mkdir -p bin
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags $(LDFLAGS) -a -installsuffix cgo -o bin/gimlet-installer-linux-x86_64 github.com/gimlet-io/gimlet-cli/cmd/installer
CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build -ldflags $(LDFLAGS) -a -installsuffix cgo -o bin/gimlet-installer-darwin-x86_64 github.com/gimlet-io/gimlet-cli/cmd/installer
CGO_ENABLED=0 GOOS=darwin GOARCH=arm64 go build -ldflags $(LDFLAGS) -a -installsuffix cgo -o bin/gimlet-installer-darwin-arm64 github.com/gimlet-io/gimlet-cli/cmd/installer
dist-image-builder:
mkdir -p bin
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags $(LDFLAGS) -a -installsuffix cgo -o bin/image-builder-linux-x86_64 github.com/gimlet-io/gimlet-cli/cmd/image-builder
Expand All @@ -99,13 +86,6 @@ build-dashboard-frontend:
rm -rf cmd/dashboard/web/build
mkdir -p cmd/dashboard/web/build
@cp -r web/dashboard/build/* cmd/dashboard/web/build
build-installer-frontend:
(cd web/installer; npm install; npm run build)
@cp web/installer/build/main.js cmd/installer/web/
@cp web/installer/build/1.chunk.js cmd/installer/web/
@cp web/installer/build/main.css cmd/installer/web/
@cp web/installer/build/index.html cmd/installer/web/
@cp web/installer/public/favicon.ico cmd/installer/web/

start-local-env:
docker-compose -f fixtures/k3s/docker-compose.yml up -d
Expand Down
31 changes: 0 additions & 31 deletions cmd/dashboard/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,37 +144,6 @@ type GitopsRepoConfig struct {
DeployKeyPath string
}

func (c *Config) IsGithub() bool {
return c.Github.AppID != ""
}

func (c *Config) IsGitlab() bool {
return c.Gitlab.ClientID != ""
}

func (c *Config) Org() string {
if c.IsGithub() {
return c.Github.Org
} else if c.IsGitlab() {
return c.Gitlab.Org
}

return ""
}

func (c *Config) ScmURL() string {
if c.IsGithub() {
return "https://github.com"
} else if c.IsGitlab() {
if c.Gitlab.URL != "" {
return c.Gitlab.URL
}
return "https://gitlab.com"
}

return ""
}

type Multiline string

func (m *Multiline) Decode(value string) error {
Expand Down
25 changes: 15 additions & 10 deletions cmd/dashboard/dashboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"github.com/gimlet-io/gimlet-cli/pkg/dashboard/server/streaming"
"github.com/gimlet-io/gimlet-cli/pkg/dashboard/store"
"github.com/gimlet-io/gimlet-cli/pkg/dashboard/worker"
"github.com/gimlet-io/gimlet-cli/pkg/git/customScm"
"github.com/gimlet-io/gimlet-cli/pkg/git/nativeGit"
"github.com/go-chi/chi"
"github.com/joho/godotenv"
Expand Down Expand Up @@ -52,12 +53,14 @@ func main() {
panic(err)
}

log.Infof("Admin auth key: %s", adminKey(dynamicConfig))

if config.Host == "" {
panic(fmt.Errorf("please provide the HOST variable"))
}

if config.JWTSecret == "" {
panic(fmt.Errorf("please provide the JWT_SECRET variable"))
if dynamicConfig.JWTSecret == "" {
generateAndPersistJwtSecret(dynamicConfig)
}

agentHub := streaming.NewAgentHub()
Expand All @@ -84,8 +87,8 @@ func main() {
panic(err)
}

tokenManager := initTokenManager(config)
notificationsManager := initNotifications(config, tokenManager)
tokenManager := customScm.NewTokenManager(dynamicConfig)
notificationsManager := initNotifications(config, dynamicConfig, tokenManager)

alertStateManager := alert.NewAlertStateManager(notificationsManager, *store, 2)
// go alertStateManager.Run()
Expand Down Expand Up @@ -125,6 +128,7 @@ func main() {
tokenManager,
stopCh,
config,
dynamicConfig,
clientHub,
gitUser,
)
Expand All @@ -138,6 +142,7 @@ func main() {
if config.ChartVersionUpdaterFeatureFlag {
chartVersionUpdater := worker.NewChartVersionUpdater(
config,
dynamicConfig,
tokenManager,
repoCache,
&chartUpdatePullRequests,
Expand All @@ -163,11 +168,11 @@ func main() {

if config.ReleaseStats == "enabled" {
releaseStateWorker := &worker.ReleaseStateWorker{
RepoCache: repoCache,
Releases: releases,
Perf: perf,
Store: store,
Config: config,
RepoCache: repoCache,
Releases: releases,
Perf: perf,
Store: store,
DynamicConfig: dynamicConfig,
}
go releaseStateWorker.Run()
}
Expand Down Expand Up @@ -220,7 +225,7 @@ func main() {

if config.BuiltinEnvFeatureFlag {
time.Sleep(time.Millisecond * 100) // wait til the router is up
err = bootstrapBuiltInEnv(store, repoCache, gitUser, config)
err = bootstrapBuiltInEnv(store, repoCache, gitUser, config, dynamicConfig)
if err != nil {
panic(err)
}
Expand Down
41 changes: 35 additions & 6 deletions cmd/dashboard/dynamicconfig/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,11 @@ func LoadDynamicConfig(dao *store.Store) (*DynamicConfig, error) {
type DynamicConfig struct {
dao *store.Store

DummyString string
DummyString2 string
DummyBool bool
DummyBool2 bool
DummyInt int

Github config.Github
Gitlab config.Gitlab

JWTSecret string
AdminKey string
}

// persist all config fields that are not already set in the database
Expand Down Expand Up @@ -140,3 +138,34 @@ func (c *DynamicConfig) load() error {

return json.Unmarshal([]byte(configString.Value), c)
}

func (c *DynamicConfig) IsGithub() bool {
return c.Github.AppID != ""
}

func (c *DynamicConfig) IsGitlab() bool {
return c.Gitlab.ClientID != ""
}

func (c *DynamicConfig) Org() string {
if c.IsGithub() {
return c.Github.Org
} else if c.IsGitlab() {
return c.Gitlab.Org
}

return ""
}

func (c *DynamicConfig) ScmURL() string {
if c.IsGithub() {
return "https://github.com"
} else if c.IsGitlab() {
if c.Gitlab.URL != "" {
return c.Gitlab.URL
}
return "https://gitlab.com"
}

return ""
}
26 changes: 14 additions & 12 deletions cmd/dashboard/dynamicconfig/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,27 @@ import (

func Test_UpdateConfig(t *testing.T) {
toUpdate := &DynamicConfig{
DummyString: "xyz",
DummyBool: true,
AdminKey: "admin-key",
Github: config.Github{
Debug: true,
},
}

new := &DynamicConfig{
DummyString: "cccc",
DummyString2: "host",
DummyBool: true,
DummyBool2: true,
DummyInt: 100,
AdminKey: "new-admin-key",
JWTSecret: "new-jwt-secret",
Github: config.Github{
Debug: true,
SkipVerify: true,
},
}

updateConfigWhenZeroValue(toUpdate, new)

assert.Equal(t, toUpdate.DummyString, "xyz", "Set values should not be updated")
assert.Equal(t, toUpdate.DummyString2, "host", "Empty strings should be updated")
assert.Equal(t, toUpdate.DummyBool, true, "Equal values should stay equal")
assert.Equal(t, toUpdate.DummyBool2, true, "Booelan fields should be set")
assert.Equal(t, toUpdate.DummyInt, 100, "Int fields should be set")
assert.Equal(t, toUpdate.AdminKey, "admin-key", "Set values should not be updated")
assert.Equal(t, toUpdate.JWTSecret, "new-jwt-secret", "Empty strings should be updated")
assert.Equal(t, toUpdate.Github.Debug, true, "Equal values should stay equal")
assert.Equal(t, toUpdate.Github.SkipVerify, true, "Booelan fields should be set")
}

func Test_UpdateConfig_StructFields(t *testing.T) {
Expand Down
Loading

0 comments on commit c624b99

Please sign in to comment.