Skip to content

Commit

Permalink
Merge branch 'main' into f-jumppad-env-var
Browse files Browse the repository at this point in the history
  • Loading branch information
nicholasjackson authored Oct 30, 2023
2 parents e00c7c6 + a1d35d6 commit 07a8c95
Show file tree
Hide file tree
Showing 57 changed files with 1,523 additions and 423 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/build_and_deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
- name: Unit Test
run: |
go test -v -race ./pkg/jumppad
go test -v -race ./...
#- name: Upload Code Coverage
# uses: codecov/codecov-action@v1
Expand Down Expand Up @@ -135,6 +135,7 @@ jobs:
'./examples/local_exec',
'./examples/remote_exec',
'./examples/certificates',
'./examples/terraform',
]

steps:
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ bin/
dist/
.vscode
.envrc
.terraform
.terraform
.terraform.lock.hcl
7 changes: 6 additions & 1 deletion cmd/dev.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"time"

"github.com/jumppad-labs/jumppad/cmd/view"
"github.com/jumppad-labs/jumppad/pkg/clients"
"github.com/jumppad-labs/jumppad/pkg/jumppad"
"github.com/jumppad-labs/jumppad/pkg/utils"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -55,7 +56,11 @@ func newDevCmdFunc(variables *[]string, variablesFile, interval *string, ttyFlag
}
}

engine, _, _ = createEngine(v.Logger())
engineClients, _ := clients.GenerateClients(v.Logger())
engine, _, err := createEngine(v.Logger(), engineClients)
if err != nil {
return fmt.Errorf("unable to create engine: %s", err)
}

// create the shipyard and sub folders in the users home directory
utils.CreateFolders()
Expand Down
23 changes: 15 additions & 8 deletions cmd/down.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package cmd
import (
"os"

"github.com/jumppad-labs/jumppad/pkg/clients"
"github.com/jumppad-labs/jumppad/pkg/clients/connector"
"github.com/jumppad-labs/jumppad/pkg/utils"
"github.com/spf13/cobra"
Expand All @@ -15,25 +16,31 @@ func newDestroyCmd(cc connector.Connector) *cobra.Command {
Long: "Remove all resources in the current state",
Example: `jumppad down`,
Run: func(cmd *cobra.Command, args []string) {
err := engine.Destroy()
l := createLogger()
engineClients, _ := clients.GenerateClients(l)
engine, _, err := createEngine(l, engineClients)
if err != nil {
l.Error("Unable to create engine", "error", err)
return
}

err = engine.Destroy()
logger := createLogger()

if err != nil {
logger.Error("Unable to destroy stack", "error", err)
l.Error("Unable to destroy stack", "error", err)
return
}

// clean up the data folder
os.RemoveAll(utils.GetDataFolder("", os.ModePerm))

// clean up the library folder
os.RemoveAll(utils.GetLibraryFolder("", os.ModePerm))
// clean up the data folders
os.RemoveAll(utils.DataFolder("", os.ModePerm))
os.RemoveAll(utils.LibraryFolder("", os.ModePerm))

// shutdown ingress when we destroy all resources
if cc.IsRunning() {
err = cc.Stop()
if err != nil {
logger.Error("Unable to destroy stack", "error", err)
logger.Error("Unable to destroy jumppad daemon", "error", err)
}
}
},
Expand Down
16 changes: 12 additions & 4 deletions cmd/purge.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,15 @@ func newPurgeCmdFunc(dt container.Docker, il images.ImageLog, l logger.Logger) f
bHasError = true
}

hcp := utils.GetBlueprintLocalFolder("")
hcp := utils.BlueprintLocalFolder("")
l.Info("Removing cached blueprints", "path", hcp)
err = os.RemoveAll(hcp)
if err != nil {
l.Error("Unable to remove cached blueprints", "error", err)
bHasError = true
}

bcp := utils.GetHelmLocalFolder("")
bcp := utils.HelmLocalFolder("")
l.Info("Removing cached Helm charts", "path", bcp)
err = os.RemoveAll(bcp)
if err != nil {
Expand All @@ -92,22 +92,30 @@ func newPurgeCmdFunc(dt container.Docker, il images.ImageLog, l logger.Logger) f
}

// delete the releases
rcp := utils.GetReleasesFolder()
rcp := utils.ReleasesFolder()
l.Info("Removing cached releases", "path", rcp)
err = os.RemoveAll(rcp)
if err != nil {
l.Error("Unable to remove cached Releases", "error", err)
bHasError = true
}

dcp := utils.GetDataFolder("", os.ModePerm)
dcp := utils.DataFolder("", os.ModePerm)
l.Info("Removing data folders", "path", dcp)
err = os.RemoveAll(dcp)
if err != nil {
l.Error("Unable to remove data folder", "error", err)
bHasError = true
}

ccp := utils.DataFolder("", os.ModePerm)
l.Info("Removing cache folders", "path", ccp)
err = os.RemoveAll(ccp)
if err != nil {
l.Error("Unable to remove cache folder", "error", err)
bHasError = true
}

cp := path.Join(utils.JumppadHome(), "config")
l.Info("Removing config", "path", cp)
err = os.RemoveAll(cp)
Expand Down
97 changes: 49 additions & 48 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,65 +23,23 @@ var rootCmd = &cobra.Command{
Long: `Jumppad is a tool that helps you create and run development, demo, and tutorial environments`,
}

var engine jumppad.Engine
var l logger.Logger
var engineClients *clients.Clients

var version string // set by build process
var date string // set by build process
var commit string // set by build process

func init() {

var vm gvm.Versions

// setup dependencies
l = createLogger()
engine, engineClients, vm = createEngine(l)

rootCmd.AddCommand(checkCmd)
rootCmd.AddCommand(outputCmd)
rootCmd.AddCommand(newDevCmd())
rootCmd.AddCommand(newEnvCmd(engine))
rootCmd.AddCommand(newRunCmd(engine, engineClients.ContainerTasks, engineClients.Getter, engineClients.HTTP, engineClients.Browser, vm, engineClients.Connector, l))
rootCmd.AddCommand(newTestCmd())
rootCmd.AddCommand(newDestroyCmd(engineClients.Connector))
rootCmd.AddCommand(statusCmd)
rootCmd.AddCommand(newPurgeCmd(engineClients.Docker, engineClients.ImageLog, l))
rootCmd.AddCommand(taintCmd)
rootCmd.AddCommand(newVersionCmd(vm))
rootCmd.AddCommand(uninstallCmd)
rootCmd.AddCommand(newPushCmd(engineClients.ContainerTasks, engineClients.Kubernetes, engineClients.HTTP, engineClients.Nomad, l))
rootCmd.AddCommand(newLogCmd(engine, engineClients.Docker, os.Stdout, os.Stderr), completionCmd)

// add the server commands
rootCmd.AddCommand(connectorCmd)
connectorCmd.AddCommand(newConnectorRunCommand())
connectorCmd.AddCommand(connectorStopCmd)
connectorCmd.AddCommand(newConnectorCertCmd())
func createEngine(l logger.Logger, c *clients.Clients) (jumppad.Engine, gvm.Versions, error) {

// add the generate command
rootCmd.AddCommand(generateCmd)
generateCmd.AddCommand(newGenerateReadmeCommand(engine))
}

func createEngine(l logger.Logger) (jumppad.Engine, *clients.Clients, gvm.Versions) {
engineClients, err := clients.GenerateClients(l)
if err != nil {
return nil, nil, nil
}

providers := config.NewProviders(engineClients)
providers := config.NewProviders(c)

engine, err := jumppad.New(providers, l)
if err != nil {
panic(err)
return nil, nil, err
}

o := gvm.Options{
Organization: "jumppad-labs",
Repo: "jumppad",
ReleasesPath: utils.GetReleasesFolder(),
ReleasesPath: utils.ReleasesFolder(),
}

o.AssetNameFunc = func(version, goos, goarch string) string {
Expand Down Expand Up @@ -112,7 +70,7 @@ func createEngine(l logger.Logger) (jumppad.Engine, *clients.Clients, gvm.Versio

vm := gvm.New(o)

return engine, engineClients, vm
return engine, vm, nil
}

func createLogger() logger.Logger {
Expand All @@ -130,9 +88,52 @@ func Execute(v, c, d string) error {
commit = c
date = d

var vm gvm.Versions

// setup dependencies
l := createLogger()

engineClients, _ := clients.GenerateClients(l)

// Check the system to see if Docker is running and everything is installed
s, err := engineClients.System.Preflight()
if err != nil {
fmt.Println("")
fmt.Println("###### SYSTEM DIAGNOSTICS ######")
fmt.Println(s)
return err
}

engine, vm, _ := createEngine(l, engineClients)

rootCmd.AddCommand(checkCmd)
rootCmd.AddCommand(outputCmd)
rootCmd.AddCommand(newDevCmd())
rootCmd.AddCommand(newEnvCmd(engine))
rootCmd.AddCommand(newRunCmd(engine, engineClients.ContainerTasks, engineClients.Getter, engineClients.HTTP, engineClients.System, vm, engineClients.Connector, l))
rootCmd.AddCommand(newTestCmd())
rootCmd.AddCommand(newDestroyCmd(engineClients.Connector))
rootCmd.AddCommand(statusCmd)
rootCmd.AddCommand(newPurgeCmd(engineClients.Docker, engineClients.ImageLog, l))
rootCmd.AddCommand(taintCmd)
rootCmd.AddCommand(newVersionCmd(vm))
rootCmd.AddCommand(uninstallCmd)
rootCmd.AddCommand(newPushCmd(engineClients.ContainerTasks, engineClients.Kubernetes, engineClients.HTTP, engineClients.Nomad, l))
rootCmd.AddCommand(newLogCmd(engine, engineClients.Docker, os.Stdout, os.Stderr), completionCmd)

// add the server commands
rootCmd.AddCommand(connectorCmd)
connectorCmd.AddCommand(newConnectorRunCommand())
connectorCmd.AddCommand(connectorStopCmd)
connectorCmd.AddCommand(newConnectorCertCmd())

// add the generate command
rootCmd.AddCommand(generateCmd)
generateCmd.AddCommand(newGenerateReadmeCommand(engine))

rootCmd.SilenceErrors = true

err := rootCmd.Execute()
err = rootCmd.Execute()

if err != nil {
fmt.Println("")
Expand Down
Loading

0 comments on commit 07a8c95

Please sign in to comment.