Skip to content

Commit

Permalink
fix: use the right values, minor formatting fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
shreddedbacon committed May 23, 2022
1 parent f597fda commit df74fa9
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 10 deletions.
10 changes: 5 additions & 5 deletions cmd/helpers_values.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"})
}
Expand Down
2 changes: 1 addition & 1 deletion internal/lagoon/buildvalues.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down
5 changes: 4 additions & 1 deletion internal/lagoon/compose.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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"`
Expand Down
5 changes: 4 additions & 1 deletion internal/lagoon/lagoon.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand All @@ -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"`
Expand Down
10 changes: 8 additions & 2 deletions internal/lagoon/tasks.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,22 @@ 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"
"k8s.io/client-go/kubernetes"
"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"`
Expand All @@ -29,6 +31,7 @@ type Task struct {
When string `json:"when"`
}

// NewTask .
func NewTask() Task {
return Task{
Command: "",
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -108,6 +113,7 @@ func ExecuteTaskInEnvironment(task Task) error {
return err
}

// ExecPod .
func ExecPod(
podName, namespace string,
command []string,
Expand Down

0 comments on commit df74fa9

Please sign in to comment.