Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 4 additions & 1 deletion cmd/dev.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,11 @@ func newDevCmdFunc(variables *[]string, variablesFile, interval *string, ttyFlag
}
}

defaultRegistry := jumppad.GetDefaultRegistry()
registryCredentials := jumppad.GetRegistryCredentials()

engineClients, _ := clients.GenerateClients(v.Logger())
engine, _, err := createEngine(v.Logger(), engineClients)
engine, err := createEngine(v.Logger(), engineClients, defaultRegistry, registryCredentials)
if err != nil {
return fmt.Errorf("unable to create engine: %s", err)
}
Expand Down
6 changes: 5 additions & 1 deletion cmd/down.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/jumppad-labs/jumppad/pkg/clients"
"github.com/jumppad-labs/jumppad/pkg/clients/connector"
"github.com/jumppad-labs/jumppad/pkg/clients/logger"
"github.com/jumppad-labs/jumppad/pkg/jumppad"
"github.com/jumppad-labs/jumppad/pkg/utils"
"github.com/spf13/cobra"
)
Expand All @@ -25,7 +26,10 @@ func newDestroyCmd(cc connector.Connector, l logger.Logger) *cobra.Command {
engineClients, _ := clients.GenerateClients(l)
engineClients.ContainerTasks.SetForce(force)

engine, _, err := createEngine(l, engineClients)
defaultRegistry := jumppad.GetDefaultRegistry()
registryCredentials := jumppad.GetRegistryCredentials()

engine, err := createEngine(l, engineClients, defaultRegistry, registryCredentials)
if err != nil {
l.Error("Unable to create engine", "error", err)
return
Expand Down
24 changes: 20 additions & 4 deletions cmd/plugin_build.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ type Jumppad struct {
Plugins []Plugin `hcl:"plugin,block"`
}

var outputPath string

var pluginCmd = &cobra.Command{
Use: "build",
Short: "Checks the system to ensure required dependencies are installed",
Expand Down Expand Up @@ -64,13 +66,21 @@ var pluginCmd = &cobra.Command{
l := createLogger()
engineClients, _ := clients.GenerateClients(l)

// create binary output folder
err = os.MkdirAll(filepath.Dir(outputPath), 0755)
if err != nil {
panic(err)
}

// create a temp output folder
tmp := utils.JumppadTemp()
output := filepath.Join(tmp, "jumppad_build")

os.RemoveAll(output)

os.MkdirAll(output, 0755)
err = os.MkdirAll(output, 0755)
if err != nil {
panic(err)
}

src := filepath.Join(output, "src")

Expand Down Expand Up @@ -182,9 +192,9 @@ var pluginCmd = &cobra.Command{
},
},
Outputs: []build.Output{
build.Output{
{
Source: "/src/bin/jumppad",
Destination: filepath.Join(bin, "jumppad"),
Destination: outputPath,
},
},
}, l)
Expand All @@ -193,6 +203,8 @@ var pluginCmd = &cobra.Command{
if err != nil {
panic(err)
}

os.Chmod(outputPath, 0755)
},
}

Expand All @@ -211,3 +223,7 @@ COPY ./local /local
RUN go mod tidy
RUN CGO_ENABLED=0 GOOS=${OS} GOARCH=${ARCH} go build -ldflags "-X main.version=custom" -o bin/jumppad main.go
`

func init() {
pluginCmd.Flags().StringVarP(&outputPath, "output", "o", filepath.Join(utils.JumppadTemp(), "jumppad"), "Output the binary to a specific path")
}
71 changes: 23 additions & 48 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ import (
"os"
"strings"

gvm "github.com/shipyard-run/version-manager"

"github.com/jumppad-labs/jumppad/cmd/changelog"
"github.com/jumppad-labs/jumppad/pkg/clients"
"github.com/jumppad-labs/jumppad/pkg/clients/logger"
Expand All @@ -16,10 +14,9 @@ import (

"github.com/spf13/cobra"
"github.com/spf13/pflag"
"github.com/spf13/viper"
)

var configFile = ""

var rootCmd = &cobra.Command{
Use: "jumppad",
Short: "Modern cloud native development environments",
Expand All @@ -38,49 +35,15 @@ func globalFlags() *pflag.FlagSet {
return flags
}

func createEngine(l logger.Logger, c *clients.Clients) (jumppad.Engine, gvm.Versions, error) {
func createEngine(l logger.Logger, c *clients.Clients, defaultRegistry string, registryCredentials map[string]string) (jumppad.Engine, error) {
providers := config.NewProviders(c)

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

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

o.AssetNameFunc = func(version, goos, goarch string) string {
// No idea why we set the release architecture for the binary like this
if goarch == "amd64" {
goarch = "x86_64"
}

switch goos {
case "linux":
return fmt.Sprintf("jumppad_%s_%s_%s.tar.gz", version, goos, goarch)
case "darwin":
return fmt.Sprintf("jumppad_%s_%s_%s.zip", version, goos, goarch)
case "windows":
return fmt.Sprintf("jumppad_%s_%s_%s.zip", version, goos, goarch)
}

return ""
}

o.ExeNameFunc = func(version, goos, goarch string) string {
if goos == "windows" {
return "jumppad.exe"
}

return "jumppad"
return nil, err
}

vm := gvm.New(o)

return engine, vm, nil
return engine, nil
}

func createLogger() logger.Logger {
Expand All @@ -98,26 +61,38 @@ func Execute(v, c, d string) error {
commit = c
date = d

var vm gvm.Versions

// setup dependencies
l := createLogger()

viper.AddConfigPath(utils.JumppadHome())
viper.SetConfigName("config")
err := viper.ReadInConfig()
if err != nil {
if _, ok := err.(viper.ConfigFileNotFoundError); ok {
l.Debug("No config file found, using defaults")
} else {
return err
}
}

defaultRegistry := jumppad.GetDefaultRegistry()
registryCredentials := jumppad.GetRegistryCredentials()

engineClients, _ := clients.GenerateClients(l)

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

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(newRunCmd(engine, engineClients.ContainerTasks, engineClients.Getter, engineClients.HTTP, engineClients.System, engineClients.Connector, l))
rootCmd.AddCommand(newTestCmd())
rootCmd.AddCommand(newDestroyCmd(engineClients.Connector, l))
rootCmd.AddCommand(statusCmd)
rootCmd.AddCommand(newPurgeCmd(engineClients.Docker, engineClients.ImageLog, l))
rootCmd.AddCommand(taintCmd)
rootCmd.AddCommand(newVersionCmd(vm))
rootCmd.AddCommand(newVersionCmd())
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)
Expand Down Expand Up @@ -169,7 +144,7 @@ func Execute(v, c, d string) error {
return nil
}

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

if err != nil {
showErr(err)
Expand Down
11 changes: 6 additions & 5 deletions cmd/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ import (
"github.com/jumppad-labs/jumppad/pkg/config/resources/nomad"
"github.com/jumppad-labs/jumppad/pkg/jumppad"
"github.com/jumppad-labs/jumppad/pkg/utils"
gvm "github.com/shipyard-run/version-manager"
"github.com/spf13/cobra"
"k8s.io/client-go/util/jsonpath"
)
Expand Down Expand Up @@ -117,7 +116,7 @@ type CucumberRunner struct {
args []string
e jumppad.Engine
cli *clients.Clients
vm gvm.Versions
cred map[string]string
testFolder string
testPath string
basePath string
Expand Down Expand Up @@ -178,8 +177,11 @@ func (cr *CucumberRunner) initializeSuite(ctx *godog.ScenarioContext) {

cl := logger.NewLogger(sb, logger.LogLevelDebug)

defaultRegistry := jumppad.GetDefaultRegistry()
registryCredentials := jumppad.GetRegistryCredentials()

cli, _ := clients.GenerateClients(cl)
engine, vm, err := createEngine(cl, cli)
engine, err := createEngine(cl, cli, defaultRegistry, registryCredentials)
if err != nil {
fmt.Printf("Unable to setup tests: %s\n", err)
return
Expand All @@ -188,7 +190,7 @@ func (cr *CucumberRunner) initializeSuite(ctx *godog.ScenarioContext) {
cr.e = engine
cr.l = cl
cr.cli = cli
cr.vm = vm
cr.cred = registryCredentials

// do we need to pure the cache
if *cr.purge {
Expand Down Expand Up @@ -281,7 +283,6 @@ func (cr *CucumberRunner) iRunApplyAtPathWithVersion(fp, version string) error {
cr.cli.Getter,
cr.cli.HTTP,
cr.cli.System,
cr.vm,
cr.cli.Connector,
&noOpen,
cr.force,
Expand Down
7 changes: 3 additions & 4 deletions cmd/up.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (
"time"

"github.com/jumppad-labs/hclconfig/resources"
gvm "github.com/shipyard-run/version-manager"

"github.com/jumppad-labs/jumppad/pkg/clients/connector"
cclients "github.com/jumppad-labs/jumppad/pkg/clients/container"
Expand All @@ -34,7 +33,7 @@ import (
markdown "github.com/MichaelMure/go-term-markdown"
)

func newRunCmd(e jumppad.Engine, dt cclients.ContainerTasks, bp getter.Getter, hc http.HTTP, bc system.System, vm gvm.Versions, cc connector.Connector, l logger.Logger) *cobra.Command {
func newRunCmd(e jumppad.Engine, dt cclients.ContainerTasks, bp getter.Getter, hc http.HTTP, bc system.System, cc connector.Connector, l logger.Logger) *cobra.Command {
var noOpen bool
var force bool
var y bool
Expand All @@ -57,7 +56,7 @@ func newRunCmd(e jumppad.Engine, dt cclients.ContainerTasks, bp getter.Getter, h
jumppad up github.com/jumppad-labs/blueprints/kubernetes-vault
`,
Args: cobra.ArbitraryArgs,
RunE: newRunCmdFunc(e, dt, bp, hc, bc, vm, cc, &noOpen, &force, &runVersion, &y, &variables, &variablesFile, l),
RunE: newRunCmdFunc(e, dt, bp, hc, bc, cc, &noOpen, &force, &runVersion, &y, &variables, &variablesFile, l),
SilenceUsage: true,
}

Expand All @@ -69,7 +68,7 @@ func newRunCmd(e jumppad.Engine, dt cclients.ContainerTasks, bp getter.Getter, h
return runCmd
}

func newRunCmdFunc(e jumppad.Engine, dt cclients.ContainerTasks, bp getter.Getter, hc http.HTTP, bc system.System, vm gvm.Versions, cc connector.Connector, noOpen *bool, force *bool, runVersion *string, autoApprove *bool, variables *[]string, variablesFile *string, l logger.Logger) func(cmd *cobra.Command, args []string) error {
func newRunCmdFunc(e jumppad.Engine, dt cclients.ContainerTasks, bp getter.Getter, hc http.HTTP, bc system.System, cc connector.Connector, noOpen *bool, force *bool, runVersion *string, autoApprove *bool, variables *[]string, variablesFile *string, l logger.Logger) func(cmd *cobra.Command, args []string) error {
return func(cmd *cobra.Command, args []string) error {
// create the shipyard and sub folders in the users home directory
utils.CreateFolders()
Expand Down
2 changes: 1 addition & 1 deletion cmd/up_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ func setupRun(t *testing.T, timeout string) (*cobra.Command, *runMocks) {
tasks: mockContainer,
}

cmd := newRunCmd(mockEngine, mockContainer, mockGetter, mockHTTP, mockSystem, nil, mockConnector, logger.NewTestLogger(t))
cmd := newRunCmd(mockEngine, mockContainer, mockGetter, mockHTTP, mockSystem, mockConnector, logger.NewTestLogger(t))
cmd.SetOut(bytes.NewBuffer([]byte("")))

return cmd, rm
Expand Down
3 changes: 1 addition & 2 deletions cmd/version.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
package cmd

import (
gvm "github.com/shipyard-run/version-manager"
"github.com/spf13/cobra"
)

func newVersionCmd(vm gvm.Versions) *cobra.Command {
func newVersionCmd() *cobra.Command {
var versionCmd = &cobra.Command{
Use: "version",
Short: "jumppad version manager commands",
Expand Down
4 changes: 4 additions & 0 deletions examples/module_registry/main.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module "registry" {
source = "jumppad/postgres"
version = "0.1.0"
}
Loading
Loading