Skip to content

Commit

Permalink
Merge pull request #289 from uselagoon/service-templates
Browse files Browse the repository at this point in the history
feat: replace helm with go service templates
  • Loading branch information
tobybellwood authored Jul 21, 2024
2 parents 017d8e3 + 7e775fd commit 5859bae
Show file tree
Hide file tree
Showing 587 changed files with 20,401 additions and 14,139 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
.idea
test-resources/output
testoutput
1 change: 0 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ WORKDIR /kubectl-build-deploy/git
COPY legacy/docker-entrypoint.sh /lagoon/entrypoints/100-docker-entrypoint.sh
COPY legacy/build-deploy.sh /kubectl-build-deploy/build-deploy.sh
COPY legacy/build-deploy-docker-compose.sh /kubectl-build-deploy/build-deploy-docker-compose.sh
COPY legacy/rootless.values.yaml /kubectl-build-deploy/rootless.values.yaml

COPY legacy/scripts /kubectl-build-deploy/scripts

Expand Down
4 changes: 0 additions & 4 deletions cmd/config_fastly.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@ import (
"github.com/uselagoon/build-deploy-tool/internal/lagoon"
)

var (
domainName string
)

var fastlyConfigGeneration = &cobra.Command{
Use: "fastly",
Aliases: []string{"f"},
Expand Down
1 change: 1 addition & 0 deletions cmd/config_fastly_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ func TestGenerateFastlyConfig(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
helpers.UnsetEnvVars(nil) //unset variables before running tests
// set the environment variables from args
err := os.Setenv("LAGOON_FASTLY_NOCACHE_SERVICE_ID", tt.args.cacheNoCache)
if err != nil {
Expand Down
34 changes: 5 additions & 29 deletions cmd/identify_dbaas_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,30 +13,6 @@ import (

// these tests uses the same files as the dbaas templates
func TestIdentifyDBaaSConsumers(t *testing.T) {
type args struct {
name string
alertContact string
statusPageID string
projectName string
environmentName string
branch string
prNumber string
prHeadBranch string
prBaseBranch string
environmentType string
buildType string
activeEnvironment string
standbyEnvironment string
cacheNoCache string
serviceID string
secretPrefix string
projectVars string
envVars string
lagoonVersion string
lagoonYAML string
valuesFilePath string
templatePath string
}
tests := []struct {
name string
args testdata.TestData
Expand All @@ -52,7 +28,7 @@ func TestIdentifyDBaaSConsumers(t *testing.T) {
ProjectName: "example-project",
EnvironmentName: "main",
Branch: "main",
LagoonYAML: "../internal/testdata/complex/lagoon.yml",
LagoonYAML: "internal/testdata/complex/lagoon.yml",
}, true),
templatePath: "testdata/output",
want: []string{
Expand All @@ -66,7 +42,7 @@ func TestIdentifyDBaaSConsumers(t *testing.T) {
ProjectName: "example-project",
EnvironmentName: "main",
Branch: "main",
LagoonYAML: "../internal/testdata/complex/lagoon.yml",
LagoonYAML: "internal/testdata/complex/lagoon.yml",
ProjectVariables: []lagoon.EnvironmentVariable{
{Name: "LAGOON_SERVICE_TYPES", Value: "mariadb:mariadb-shared", Scope: "build"},
},
Expand All @@ -83,7 +59,7 @@ func TestIdentifyDBaaSConsumers(t *testing.T) {
ProjectName: "example-project",
EnvironmentName: "main",
Branch: "main",
LagoonYAML: "../internal/testdata/complex/lagoon.yml",
LagoonYAML: "internal/testdata/complex/lagoon.yml",
ProjectVariables: []lagoon.EnvironmentVariable{
{Name: "LAGOON_DBAAS_ENVIRONMENT_TYPES", Value: "mariadb:development2", Scope: "build"},
},
Expand All @@ -100,7 +76,7 @@ func TestIdentifyDBaaSConsumers(t *testing.T) {
ProjectName: "example-project",
EnvironmentName: "main",
Branch: "main",
LagoonYAML: "../internal/testdata/complex/lagoon.yml",
LagoonYAML: "internal/testdata/complex/lagoon.yml",
ProjectVariables: []lagoon.EnvironmentVariable{
{Name: "LAGOON_SERVICE_TYPES", Value: "mariadb:mariadb-shared", Scope: "build"},
},
Expand All @@ -117,7 +93,7 @@ func TestIdentifyDBaaSConsumers(t *testing.T) {
ProjectName: "example-project",
EnvironmentName: "main",
Branch: "main",
LagoonYAML: "../internal/testdata/complex/lagoon.multidb.yml",
LagoonYAML: "internal/testdata/complex/lagoon.multidb.yml",
}, true),
templatePath: "testdata/output",
want: []string{
Expand Down
2 changes: 1 addition & 1 deletion cmd/identify_feature.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func IdentifyFeatureFlag(g generator.GeneratorInput, name string) (string, error
if forceFlagVar != "" {
return forceFlagVar, nil
}
featureFlagVar, _ := lagoon.GetLagoonVariable(fmt.Sprintf("%s%s", "LAGOON_FEATURE_FLAG_", name), []string{"build", "global"}, *lagoonBuild.LagoonEnvironmentVariables)
featureFlagVar, _ := lagoon.GetLagoonVariable(fmt.Sprintf("%s%s", "LAGOON_FEATURE_FLAG_", name), []string{"build", "global"}, lagoonBuild.BuildValues.EnvironmentVariables)
if featureFlagVar != nil {
return featureFlagVar.Value, nil
}
Expand Down
48 changes: 14 additions & 34 deletions cmd/identify_feature_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,33 +7,12 @@ import (
"github.com/uselagoon/build-deploy-tool/internal/helpers"
"github.com/uselagoon/build-deploy-tool/internal/lagoon"
"github.com/uselagoon/build-deploy-tool/internal/testdata"

// changes the testing to source from root so paths to test resources must be defined from repo root
_ "github.com/uselagoon/build-deploy-tool/internal/testing"
)

func TestIdentifyFeatureFlag(t *testing.T) {
type args struct {
name string
alertContact string
statusPageID string
projectName string
environmentName string
branch string
prNumber string
prHeadBranch string
prBaseBranch string
environmentType string
buildType string
activeEnvironment string
standbyEnvironment string
cacheNoCache string
serviceID string
secretPrefix string
projectVars string
envVars string
lagoonVersion string
lagoonYAML string
valuesFilePath string
templatePath string
}
tests := []struct {
name string
args testdata.TestData
Expand All @@ -51,7 +30,7 @@ func TestIdentifyFeatureFlag(t *testing.T) {
ProjectName: "example-project",
EnvironmentName: "main",
Branch: "main",
LagoonYAML: "../internal/testdata/node/lagoon.yml",
LagoonYAML: "internal/testdata/node/lagoon.yml",
ProjectVariables: []lagoon.EnvironmentVariable{
{
Name: "LAGOON_FEATURE_FLAG_ROOTLESS_WORKLOAD",
Expand All @@ -60,7 +39,7 @@ func TestIdentifyFeatureFlag(t *testing.T) {
},
},
}, true),
templatePath: "testdata/output",
templatePath: "testoutput",
want: "enabled",
},
{
Expand All @@ -71,7 +50,7 @@ func TestIdentifyFeatureFlag(t *testing.T) {
ProjectName: "example-project",
EnvironmentName: "main",
Branch: "main",
LagoonYAML: "../internal/testdata/node/lagoon.yml",
LagoonYAML: "internal/testdata/node/lagoon.yml",
EnvVariables: []lagoon.EnvironmentVariable{
{
Name: "LAGOON_FEATURE_FLAG_ROOTLESS_WORKLOAD",
Expand All @@ -80,7 +59,7 @@ func TestIdentifyFeatureFlag(t *testing.T) {
},
},
}, true),
templatePath: "testdata/output",
templatePath: "testoutput",
want: "enabled",
},
{
Expand All @@ -91,9 +70,9 @@ func TestIdentifyFeatureFlag(t *testing.T) {
ProjectName: "example-project",
EnvironmentName: "main",
Branch: "main",
LagoonYAML: "../internal/testdata/node/lagoon.yml",
LagoonYAML: "internal/testdata/node/lagoon.yml",
}, true),
templatePath: "testdata/output",
templatePath: "testoutput",
vars: []helpers.EnvironmentVariable{
{
Name: "LAGOON_FEATURE_FLAG_FORCE_ROOTLESS_WORKLOAD",
Expand All @@ -110,9 +89,9 @@ func TestIdentifyFeatureFlag(t *testing.T) {
ProjectName: "example-project",
EnvironmentName: "main",
Branch: "main",
LagoonYAML: "../internal/testdata/node/lagoon.yml",
LagoonYAML: "internal/testdata/node/lagoon.yml",
}, true),
templatePath: "testdata/output",
templatePath: "testoutput",
vars: []helpers.EnvironmentVariable{
{
Name: "LAGOON_FEATURE_FLAG_FORCE_ROOTLESS_WORKLOAD",
Expand All @@ -133,7 +112,7 @@ func TestIdentifyFeatureFlag(t *testing.T) {
ProjectName: "example-project",
EnvironmentName: "main",
Branch: "main",
LagoonYAML: "../internal/testdata/node/lagoon.yml",
LagoonYAML: "internal/testdata/node/lagoon.yml",
ProjectVariables: []lagoon.EnvironmentVariable{
{
Name: "LAGOON_FEATURE_FLAG_ROOTLESS_WORKLOAD",
Expand Down Expand Up @@ -162,7 +141,7 @@ func TestIdentifyFeatureFlag(t *testing.T) {
ProjectName: "example-project",
EnvironmentName: "main",
Branch: "main",
LagoonYAML: "../internal/testdata/node/lagoon.yml",
LagoonYAML: "internal/testdata/node/lagoon.yml",
ProjectVariables: []lagoon.EnvironmentVariable{
{
Name: "LAGOON_FEATURE_FLAG_ROOTLESS_WORKLOAD",
Expand All @@ -182,6 +161,7 @@ func TestIdentifyFeatureFlag(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
helpers.UnsetEnvVars(tt.vars) //unset variables before running tests
// set the environment variables from args
savedTemplates := tt.templatePath
generator, err := testdata.SetupEnvironment(*rootCmd, savedTemplates, tt.args)
Expand Down
78 changes: 78 additions & 0 deletions cmd/identify_imagebuild.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
package cmd

import (
"encoding/json"
"fmt"

"github.com/spf13/cobra"
generator "github.com/uselagoon/build-deploy-tool/internal/generator"
)

var imageBuildIdentify = &cobra.Command{
Use: "image-builds",
Aliases: []string{"image-build", "img-build", "ib"},
Short: "Identify the configuration for building images for a Lagoon build",
RunE: func(cmd *cobra.Command, args []string) error {
gen, err := generator.GenerateInput(*rootCmd, false)
if err != nil {
return err
}
out, err := ImageBuildConfigurationIdentification(gen)
if err != nil {
return err
}
bc, err := json.Marshal(out)
if err != nil {
return err
}
fmt.Println(string(bc))
return nil
},
}

type imageBuild struct {
BuildKit bool `json:"buildKit"`
Images []imageBuilds `json:"images"`
BuildArguments map[string]string `json:"buildArguments"`
ContainerRegistries []generator.ContainerRegistry `json:"containerRegistries,omitempty"`
}

type imageBuilds struct {
Name string `json:"name"`
ImageBuild generator.ImageBuild `json:"imageBuild"`
}

// ImageBuildConfigurationIdentification takes the output of the generator and turns it into a JSON payload
// that can be used by the legacy bash to build container images. This payload contains the buildkit flag if it was as part of the build
// but it also provides all the container contexts and dockerfile paths that can be passed to the build command
// this includes the:
// * temporary image name (namespace-service)
// * the push image name (registry/project/environment/service:latest)
// * the pull through image, if there is no dockerfile
// * eventually other information like build args etc
func ImageBuildConfigurationIdentification(g generator.GeneratorInput) (imageBuild, error) {

lServices := imageBuild{}
lagoonBuild, err := generator.NewGenerator(
g,
)
if err != nil {
return lServices, err
}
lServices.BuildKit = lagoonBuild.BuildValues.DockerBuildKit
lServices.BuildArguments = lagoonBuild.BuildValues.ImageBuildArguments
for _, service := range lagoonBuild.BuildValues.Services {
if service.ImageBuild != nil {
lServices.Images = append(lServices.Images, imageBuilds{
Name: service.Name,
ImageBuild: *service.ImageBuild,
})
}
}
lServices.ContainerRegistries = lagoonBuild.BuildValues.ContainerRegistry
return lServices, nil
}

func init() {
identifyCmd.AddCommand(imageBuildIdentify)
}
Loading

0 comments on commit 5859bae

Please sign in to comment.