diff --git a/cmd/helpers_values.go b/cmd/helpers_values.go index d3eda6a8..2448b23e 100644 --- a/cmd/helpers_values.go +++ b/cmd/helpers_values.go @@ -227,11 +227,11 @@ func composeToServiceValues(lYAML *lagoon.YAML, lagoonValues *lagoon.BuildValues func collectBuildVariables(lagoonValues lagoon.BuildValues) []lagoon.EnvironmentVariable { vars := []lagoon.EnvironmentVariable{} vars = append(vars, lagoon.EnvironmentVariable{Name: "LAGOON_PROJECT", Value: lagoonValues.Project, Scope: "runtime"}) - vars = append(vars, lagoon.EnvironmentVariable{Name: "LAGOON_ENVIRONMENT", Value: lagoonValues.Project, Scope: "runtime"}) - vars = append(vars, lagoon.EnvironmentVariable{Name: "LAGOON_ENVIRONMENT_TYPE", Value: lagoonValues.Project, Scope: "runtime"}) - vars = append(vars, lagoon.EnvironmentVariable{Name: "LAGOON_GIT_SHA", Value: lagoonValues.Project, Scope: "runtime"}) - vars = append(vars, lagoon.EnvironmentVariable{Name: "LAGOON_KUBERNETES", Value: lagoonValues.Project, Scope: "runtime"}) - vars = append(vars, lagoon.EnvironmentVariable{Name: "LAGOON_GIT_SAFE_BRANCH", Value: lagoonValues.Project, Scope: "runtime"}) //deprecated??? + vars = append(vars, lagoon.EnvironmentVariable{Name: "LAGOON_ENVIRONMENT", Value: lagoonValues.Environment, Scope: "runtime"}) + vars = append(vars, lagoon.EnvironmentVariable{Name: "LAGOON_ENVIRONMENT_TYPE", Value: lagoonValues.EnvironmentType, Scope: "runtime"}) + vars = append(vars, lagoon.EnvironmentVariable{Name: "LAGOON_GIT_SHA", Value: lagoonValues.GitSha, Scope: "runtime"}) + vars = append(vars, lagoon.EnvironmentVariable{Name: "LAGOON_KUBERNETES", Value: lagoonValues.Kubernetes, Scope: "runtime"}) + vars = append(vars, lagoon.EnvironmentVariable{Name: "LAGOON_GIT_SAFE_BRANCH", Value: lagoonValues.Environment, Scope: "runtime"}) //deprecated??? (https://github.com/uselagoon/lagoon/blob/1053965321495213591f4c9110f90a9d9dcfc946/images/kubectl-build-deploy-dind/build-deploy-docker-compose.sh#L748) if lagoonValues.BuildType == "branch" { vars = append(vars, lagoon.EnvironmentVariable{Name: "LAGOON_GIT_BRANCH", Value: lagoonValues.Branch, Scope: "runtime"}) } diff --git a/internal/lagoon/buildvalues.go b/internal/lagoon/buildvalues.go index 00ce8ba4..4f1595e7 100644 --- a/internal/lagoon/buildvalues.go +++ b/internal/lagoon/buildvalues.go @@ -6,7 +6,7 @@ type BuildValues struct { Environment string `json:"environment"` EnvironmentType string `json:"environmentType"` Namespace string `json:"namespace"` - GitSha int `json:"gitSha"` + GitSha string `json:"gitSha"` BuildType string `json:"buildType"` RoutesAutogenerateInsecure string `json:"routesAutogenerateInsecure"` RoutesAutogenerateEnabled string `json:"routesAutogenerateEnabled"` diff --git a/internal/lagoon/compose.go b/internal/lagoon/compose.go index 745d1f4c..c3309687 100644 --- a/internal/lagoon/compose.go +++ b/internal/lagoon/compose.go @@ -18,7 +18,7 @@ func UnmarshaDockerComposeYAML(file string, l *Compose) error { return nil } -// CheckLagoonLabel checks the labels in a compose service to see if the requested label exists, and returns the value if so +// CheckServiceLagoonLabel checks the labels in a compose service to see if the requested label exists, and returns the value if so func CheckServiceLagoonLabel(labels map[string]string, label string) string { for k, v := range labels { if k == label { @@ -28,16 +28,19 @@ func CheckServiceLagoonLabel(labels map[string]string, label string) string { return "" } +// Compose . type Compose struct { Services map[string]Service `json:"services"` } +// Service . type Service struct { Build ServiceBuild `json:"build"` Labels map[string]string `json:"labels"` // Image string `json:"image"` //@TODO: is this used by lagoon builds? } +// ServiceBuild . type ServiceBuild struct { Context string `json:"context"` Dockerfile string `json:"dockerfile"` diff --git a/internal/lagoon/lagoon.go b/internal/lagoon/lagoon.go index 71afc20b..8667089a 100644 --- a/internal/lagoon/lagoon.go +++ b/internal/lagoon/lagoon.go @@ -23,11 +23,12 @@ type Environment struct { // Environments . type Environments map[string]Environment -// Tasks +// TaskRun . type TaskRun struct { Run Task `json:"run"` } +// Tasks . type Tasks struct { Prerollout []TaskRun `json:"pre-rollout"` Postrollout []TaskRun `json:"post-rollout"` @@ -42,10 +43,12 @@ type YAML struct { Routes Routes `json:"routes"` } +// Routes . type Routes struct { Autogenerate Autogenerate `json:"autogenerate"` } +// Autogenerate . type Autogenerate struct { Enabled *bool `json:"enabled"` AllowPullRequests *bool `json:"allowPullRequests"` diff --git a/internal/lagoon/tasks.go b/internal/lagoon/tasks.go index 8de1f2b2..ada6fac8 100644 --- a/internal/lagoon/tasks.go +++ b/internal/lagoon/tasks.go @@ -5,8 +5,10 @@ import ( "context" "errors" "fmt" - "github.com/uselagoon/build-deploy-tool/internal/helpers" "io/ioutil" + "time" + + "github.com/uselagoon/build-deploy-tool/internal/helpers" corev1 "k8s.io/api/core/v1" v1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" @@ -14,11 +16,11 @@ import ( "k8s.io/client-go/rest" "k8s.io/client-go/tools/clientcmd" "k8s.io/client-go/tools/remotecommand" - "time" ) var debug bool +// Task . type Task struct { Name string `json:"name"` Command string `json:"command"` @@ -29,6 +31,7 @@ type Task struct { When string `json:"when"` } +// NewTask . func NewTask() Task { return Task{ Command: "", @@ -42,6 +45,7 @@ func (t Task) String() string { return fmt.Sprintf("{command: '%v', ns: '%v', service: '%v', shell:'%v'}", t.Command, t.Namespace, t.Service, t.Shell) } +// GetK8sClient . func GetK8sClient(config *rest.Config) (*kubernetes.Clientset, error) { // create the clientset clientset, err := kubernetes.NewForConfig(config) @@ -82,6 +86,7 @@ func getConfig() (*rest.Config, error) { return config, err } +// ExecuteTaskInEnvironment . func ExecuteTaskInEnvironment(task Task) error { if debug { fmt.Println("Executing task :", task.Command) @@ -108,6 +113,7 @@ func ExecuteTaskInEnvironment(task Task) error { return err } +// ExecPod . func ExecPod( podName, namespace string, command []string,