Skip to content

Commit

Permalink
Committing initial build/deploy task work
Browse files Browse the repository at this point in the history
  • Loading branch information
bomoko committed May 3, 2022
1 parent 32ab231 commit 3298a95
Show file tree
Hide file tree
Showing 6 changed files with 638 additions and 4 deletions.
1 change: 1 addition & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ func init() {
rootCmd.CompletionOptions.DisableDefaultCmd = true
rootCmd.AddCommand(templateCmd)
rootCmd.AddCommand(configCmd)
rootCmd.AddCommand(tasksScaffold) //TODO: BMK :- Remove or change this to the appropriate command when ready
}

// initConfig reads in config file and ENV variables if set.
Expand Down
66 changes: 66 additions & 0 deletions cmd/tasks_scaffold.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package cmd

import (
"encoding/json"
"fmt"
"github.com/spf13/cobra"
"github.com/uselagoon/build-deploy-tool/internal/helpers"
"github.com/uselagoon/build-deploy-tool/internal/lagoon"
)

var tasksScaffold = &cobra.Command{
Use: "taskScaffold",
Aliases: []string{"ts"},
Short: "This is just a scaffolding command to get me started writing tasks stuff",
RunE: func(cmd *cobra.Command, args []string) error {
// get the project and environment variables
projectVariables = helpers.GetEnv("LAGOON_PROJECT_VARIABLES", projectVariables, true)
environmentVariables = helpers.GetEnv("LAGOON_ENVIRONMENT_VARIABLES", environmentVariables, true)

// unmarshal and then merge the two so there is only 1 set of variables to iterate over
projectVars := []lagoon.EnvironmentVariable{}
envVars := []lagoon.EnvironmentVariable{}
json.Unmarshal([]byte(projectVariables), &projectVars)
json.Unmarshal([]byte(environmentVariables), &envVars)
lagoonEnvVars := lagoon.MergeVariables(projectVars, envVars)

if len(envVars) > 0 {
for i, envVar := range lagoonEnvVars {
fmt.Sprintf("lagoonEnvVars[%i] is %v:%v\n", i, envVar.Name, envVar.Value)
}
} else {
fmt.Println("No Project or Environment Variables!")
}

//For now, we actually just want to run some arbitrary command in a running container, perhaps?

task := lagoon.NewTask()
task.Command = "env"
lagoon.ExecuteTaskInEnvironment(task)

command := []string{
"sh",
"-c",
"env",
}
stdout, stdin, error := lagoon.ExecPod("nginx-deployment", "default", command, false)

if error != nil {
panic(error.Error())
}
fmt.Println(stdout)
fmt.Println(stdin)

return nil
},
}

func init() {
configCmd.AddCommand(tasksScaffold)
tasksScaffold.Flags().StringVarP(&domainName, "domain", "D", "",
"The .lagoon.yml file to read")
tasksScaffold.Flags().StringVarP(&projectVariables, "project-variables", "v", "",
"The projects environment variables JSON payload")
tasksScaffold.Flags().StringVarP(&environmentVariables, "environment-variables", "V", "",
"The environments environment variables JSON payload")
}
16 changes: 15 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,45 @@ module github.com/uselagoon/build-deploy-tool
go 1.17

require (
github.com/PaesslerAG/gval v1.1.2
github.com/google/go-cmp v0.5.7
github.com/spf13/cobra v1.4.0
k8s.io/api v0.23.6
k8s.io/apimachinery v0.23.6
k8s.io/client-go v0.23.6
sigs.k8s.io/yaml v1.3.0
)

require (
github.com/PaesslerAG/gval v1.1.2 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/go-logr/logr v1.2.0 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/google/gofuzz v1.1.0 // indirect
github.com/googleapis/gnostic v0.5.5 // indirect
github.com/imdario/mergo v0.3.5 // indirect
github.com/inconshreveable/mousetrap v1.0.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/moby/spdystream v0.2.0 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/stretchr/testify v1.7.1 // indirect
golang.org/x/net v0.0.0-20220412020605-290c469a71a5 // indirect
golang.org/x/oauth2 v0.0.0-20210819190943-2bc19b11175f // indirect
golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e // indirect
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 // indirect
golang.org/x/text v0.3.7 // indirect
golang.org/x/time v0.0.0-20210723032227-1f47c861a9ac // indirect
golang.org/x/xerrors v0.0.0-20220411194840-2f41105eb62f // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/protobuf v1.27.1 // indirect
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect
k8s.io/klog/v2 v2.30.0 // indirect
k8s.io/kube-openapi v0.0.0-20211115234752-e816edb12b65 // indirect
k8s.io/utils v0.0.0-20211116205334-6203023598ed // indirect
sigs.k8s.io/json v0.0.0-20211020170558-c049b76a60c6 // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.2.1 // indirect
Expand Down
Loading

0 comments on commit 3298a95

Please sign in to comment.