Skip to content

Commit

Permalink
Merge pull request #3 from MaxCWhitehead/2.23.0-update
Browse files Browse the repository at this point in the history
2.23.0 update
  • Loading branch information
MaxCWhitehead authored Feb 6, 2025
2 parents 3d7c9fe + 70e484d commit e606b4d
Show file tree
Hide file tree
Showing 207 changed files with 5,688 additions and 1,207 deletions.
10 changes: 7 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,12 @@ RUN go install github.com/a8m/envsubst/cmd/[email protected]

WORKDIR /app

COPY . ./
COPY go.mod go.mod
COPY go.sum go.sum

COPY main.go main.go
COPY cmd/ cmd/
COPY internal/ internal/

ARG BUILD
ARG GO_VER
Expand Down Expand Up @@ -100,10 +105,9 @@ COPY legacy/build-deploy-docker-compose.sh /kubectl-build-deploy/build-deploy-do

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

COPY legacy/helmcharts /kubectl-build-deploy/helmcharts

ENV DBAAS_OPERATOR_HTTP=dbaas.lagoon.svc:5000
ENV DOCKER_HOST=docker-host.lagoon.svc
ENV LAGOON_FEATURE_FLAG_DEFAULT_DOCUMENTATION_URL=https://docs.lagoon.sh

RUN architecture=$(case $(uname -m) in x86_64 | amd64) echo "amd64" ;; aarch64 | arm64 | armv8) echo "arm64" ;; *) echo "amd64" ;; esac) \
&& curl -sSL https://github.com/uselagoon/lagoon-linter/releases/download/v0.8.0/lagoon-linter_0.8.0_linux_${architecture}.tar.gz \
Expand Down
7 changes: 1 addition & 6 deletions cmd/config_fastly.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,6 @@ func FastlyConfigGeneration(debug bool, domain string) (lagoon.Fastly, error) {
if err != nil {
return lagoon.Fastly{}, fmt.Errorf("error reading fastly-cache-no-cache-id flag: %v", err)
}
fastlyAPISecretPrefix, err := rootCmd.PersistentFlags().GetString("fastly-api-secret-prefix")
if err != nil {
return lagoon.Fastly{}, fmt.Errorf("error reading fastly-api-secret-prefix flag: %v", err)
}
fastlyServiceID, err := rootCmd.PersistentFlags().GetString("fastly-service-id")
if err != nil {
return lagoon.Fastly{}, fmt.Errorf("error reading fastly-service-id flag: %v", err)
Expand All @@ -55,7 +51,6 @@ func FastlyConfigGeneration(debug bool, domain string) (lagoon.Fastly, error) {

fastlyCacheNoCahce = helpers.GetEnv("LAGOON_FASTLY_NOCACHE_SERVICE_ID", fastlyCacheNoCahce, debug)
fastlyServiceID = helpers.GetEnv("ROUTE_FASTLY_SERVICE_ID", fastlyServiceID, debug)
fastlyAPISecretPrefix = helpers.GetEnv("FASTLY_API_SECRET_PREFIX", fastlyAPISecretPrefix, debug)

// get the project and environment variables
projectVariables = helpers.GetEnv("LAGOON_PROJECT_VARIABLES", projectVariables, debug)
Expand All @@ -70,7 +65,7 @@ func FastlyConfigGeneration(debug bool, domain string) (lagoon.Fastly, error) {

// generate the fastly configuration from the provided flags/variables
f := &lagoon.Fastly{}
err = lagoon.GenerateFastlyConfiguration(f, fastlyCacheNoCahce, fastlyServiceID, domain, fastlyAPISecretPrefix, lagoonEnvVars)
err = lagoon.GenerateFastlyConfiguration(f, fastlyCacheNoCahce, fastlyServiceID, domain, lagoonEnvVars)
if err != nil {
return lagoon.Fastly{}, err
}
Expand Down
51 changes: 4 additions & 47 deletions cmd/config_fastly_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ func TestGenerateFastlyConfig(t *testing.T) {
cacheNoCache string
serviceID string
domain string
secretPrefix string
}
tests := []struct {
name string
Expand All @@ -31,12 +30,10 @@ func TestGenerateFastlyConfig(t *testing.T) {
cacheNoCache: "",
serviceID: "",
domain: "example.com",
secretPrefix: "fastly-api-",
},
want: lagoon.Fastly{
ServiceID: "service-id",
APISecretName: "",
Watch: true,
ServiceID: "service-id",
Watch: true,
},
},
{
Expand All @@ -47,44 +44,10 @@ func TestGenerateFastlyConfig(t *testing.T) {
cacheNoCache: "",
serviceID: "",
domain: "example.com",
secretPrefix: "fastly-api-",
},
want: lagoon.Fastly{
ServiceID: "service-id",
APISecretName: "",
Watch: true,
},
},
{
name: "test3 check LAGOON_FASTLY_SERVICE_ID with secret",
args: args{
projectVars: `[{"name":"LAGOON_SYSTEM_ROUTER_PATTERN","value":"${service}-${project}-${environment}.example.com","scope":"internal_system"},{"name":"LAGOON_FASTLY_SERVICE_ID","value":"service-id:true:secret","scope":"global"}]`,
envVars: `[]`,
cacheNoCache: "",
serviceID: "",
domain: "example.com",
secretPrefix: "fastly-api-",
},
want: lagoon.Fastly{
ServiceID: "service-id",
APISecretName: "fastly-api-secret",
Watch: true,
},
},
{
name: "test4 check LAGOON_FASTLY_SERVICE_IDS with secret",
args: args{
projectVars: `[{"name":"LAGOON_SYSTEM_ROUTER_PATTERN","value":"${service}-${project}-${environment}.example.com","scope":"internal_system"},{"name":"LAGOON_FASTLY_SERVICE_IDS","value":"example.com:service-id:true:secret","scope":"global"}]`,
envVars: `[]`,
cacheNoCache: "",
serviceID: "",
domain: "example.com",
secretPrefix: "fastly-api-",
},
want: lagoon.Fastly{
ServiceID: "service-id",
APISecretName: "fastly-api-secret",
Watch: true,
ServiceID: "service-id",
Watch: true,
},
},
{
Expand All @@ -95,7 +58,6 @@ func TestGenerateFastlyConfig(t *testing.T) {
cacheNoCache: "",
serviceID: "dedicated-service-id",
domain: "example.com",
secretPrefix: "fastly-api-",
},
want: lagoon.Fastly{
ServiceID: "dedicated-service-id",
Expand All @@ -110,7 +72,6 @@ func TestGenerateFastlyConfig(t *testing.T) {
cacheNoCache: "",
serviceID: "dedicated-service-id",
domain: "example.com",
secretPrefix: "fastly-api-",
},
want: lagoon.Fastly{
ServiceID: "service-id",
Expand All @@ -130,10 +91,6 @@ func TestGenerateFastlyConfig(t *testing.T) {
if err != nil {
t.Errorf("%v", err)
}
err = os.Setenv("FASTLY_API_SECRET_PREFIX", tt.args.secretPrefix)
if err != nil {
t.Errorf("%v", err)
}
err = os.Setenv("LAGOON_PROJECT_VARIABLES", tt.args.projectVars)
if err != nil {
t.Errorf("%v", err)
Expand Down
62 changes: 59 additions & 3 deletions cmd/identify_imagebuild_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"os"
"testing"

"github.com/andreyvit/diff"
"github.com/uselagoon/build-deploy-tool/internal/dbaasclient"
"github.com/uselagoon/build-deploy-tool/internal/generator"
"github.com/uselagoon/build-deploy-tool/internal/helpers"
Expand Down Expand Up @@ -752,6 +753,61 @@ func TestImageBuildConfigurationIdentification(t *testing.T) {
},
},
},
{
name: "test12 Force Pull Base Images with variable replacement",
args: testdata.GetSeedData(
testdata.TestData{
Namespace: "example-project-main",
ProjectName: "example-project",
EnvironmentName: "main",
Branch: "main",
LagoonYAML: "internal/testdata/basic/lagoon.forcebaseimagepull-2.yml",
ProjectVariables: []lagoon.EnvironmentVariable{
{
Name: "BASE_IMAGE_TAG",
Value: "my-tag",
Scope: "build",
},
{
Name: "BASE_IMAGE_REPO",
Value: "my-repo",
Scope: "build",
},
},
}, true),
want: imageBuild{
BuildKit: helpers.BoolPtr(true),
BuildArguments: map[string]string{
"BASE_IMAGE_TAG": "my-tag",
"BASE_IMAGE_REPO": "my-repo",
"LAGOON_BUILD_NAME": "lagoon-build-abcdefg",
"LAGOON_PROJECT": "example-project",
"LAGOON_ENVIRONMENT": "main",
"LAGOON_ENVIRONMENT_TYPE": "production",
"LAGOON_BUILD_TYPE": "branch",
"LAGOON_GIT_SOURCE_REPOSITORY": "ssh://[email protected]/lagoon-demo.git",
"LAGOON_KUBERNETES": "remote-cluster1",
"LAGOON_GIT_SHA": "abcdefg123456",
"LAGOON_GIT_BRANCH": "main",
"NODE_IMAGE": "example-project-main-node",
"LAGOON_SSH_PRIVATE_KEY": "-----BEGIN OPENSSH PRIVATE KEY-----\nthisisafakekey\n-----END OPENSSH PRIVATE KEY-----",
},
ForcePullImages: []string{
"registry.com/my-repo/imagename:my-tag",
},
Images: []imageBuilds{
{
Name: "node",
ImageBuild: generator.ImageBuild{
BuildImage: "harbor.example/example-project/main/node:latest",
Context: "internal/testdata/basic/docker",
DockerFile: "basic.dockerfile",
TemporaryImage: "example-project-main-node",
},
},
},
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down Expand Up @@ -788,10 +844,10 @@ func TestImageBuildConfigurationIdentification(t *testing.T) {
t.Errorf("%v", err)
}

oJ, _ := json.Marshal(out)
wJ, _ := json.Marshal(tt.want)
oJ, _ := json.MarshalIndent(out, "", " ")
wJ, _ := json.MarshalIndent(tt.want, "", " ")
if string(oJ) != string(wJ) {
t.Errorf("returned output %v doesn't match want %v", string(oJ), string(wJ))
t.Errorf("ImageBuildConfigurationIdentification() = \n%v", diff.LineDiff(string(oJ), string(wJ)))
}
t.Cleanup(func() {
helpers.UnsetEnvVars(tt.vars)
Expand Down
2 changes: 1 addition & 1 deletion cmd/identify_lagoonservices.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (

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

type identifyServices struct {
Expand Down
9 changes: 6 additions & 3 deletions cmd/template_autogen_ingress.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"github.com/spf13/cobra"
generator "github.com/uselagoon/build-deploy-tool/internal/generator"
"github.com/uselagoon/build-deploy-tool/internal/helpers"
ingresstemplate "github.com/uselagoon/build-deploy-tool/internal/templating/ingress"
servicestemplates "github.com/uselagoon/build-deploy-tool/internal/templating"
)

var autogenRouteGeneration = &cobra.Command{
Expand All @@ -31,14 +31,17 @@ func AutogeneratedIngressGeneration(g generator.GeneratorInput) error {
return err
}
savedTemplates := g.SavedTemplatesPath

// generate the templates
for _, route := range lagoonBuild.AutogeneratedRoutes.Routes {
// autogenerated routes use the `servicename` as the name of the ingress resource, use `IngressName` in routev2 to handle this
if g.Debug {
fmt.Printf("Templating autogenerated ingress manifest for %s to %s\n", route.Domain, fmt.Sprintf("%s/%s.yaml", savedTemplates, route.LagoonService))
}
templateYAML, err := ingresstemplate.GenerateIngressTemplate(route, *lagoonBuild.BuildValues)
ingress, err := servicestemplates.GenerateIngressTemplate(route, *lagoonBuild.BuildValues)
if err != nil {
return fmt.Errorf("couldn't generate template: %v", err)
}
templateYAML, err := servicestemplates.TemplateIngress(ingress)
if err != nil {
return fmt.Errorf("couldn't generate template: %v", err)
}
Expand Down
50 changes: 27 additions & 23 deletions cmd/template_autogen_ingress_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,57 +187,61 @@ func TestAutogeneratedIngressGeneration(t *testing.T) {
want: "internal/testdata/node/autogen-templates/ingress-7",
},
{
name: "test10 autogenerated routes with fastly and specific secret",
name: "test11 autogenerated route development environment",
args: testdata.GetSeedData(
testdata.TestData{
ProjectName: "example-project",
EnvironmentName: "main",
Branch: "main",
EnvironmentType: "development",
LagoonYAML: "internal/testdata/node/lagoon.yml",
ProjectVariables: []lagoon.EnvironmentVariable{
{
Name: "LAGOON_FASTLY_SERVICE_ID",
Value: "service-id:true:secretname",
Scope: "build",
},
{
Name: "LAGOON_FASTLY_AUTOGENERATED",
Value: "enabled",
Scope: "build",
},
},
}, true),
templatePath: "testoutput",
want: "internal/testdata/node/autogen-templates/ingress-8",
want: "internal/testdata/node/autogen-templates/ingress-9",
},
{
name: "test11 autogenerated route development environment",
name: "test12 autogenerated route development environment - no insecure redirect",
args: testdata.GetSeedData(
testdata.TestData{
ProjectName: "example-project",
EnvironmentName: "main",
Branch: "main",
EnvironmentType: "development",
LagoonYAML: "internal/testdata/node/lagoon.yml",
LagoonYAML: "internal/testdata/node/lagoon.autogen-5.yml",
}, true),
templatePath: "testoutput",
want: "internal/testdata/node/autogen-templates/ingress-9",
want: "internal/testdata/node/autogen-templates/ingress-10",
},
{
name: "test12 autogenerated route development environment - no insecure redirect",
name: "test-development-service-type-override-a",
description: `this test should fail because the replacement type has no persistent label in the associated docker-compose file
realistically, this is not something that should be done on an already deployed service due to changing
service types not being properly supported`,
args: testdata.GetSeedData(
testdata.TestData{
ProjectName: "example-project",
EnvironmentName: "main",
Branch: "main",
EnvironmentType: "development",
LagoonYAML: "internal/testdata/node/lagoon.autogen-5.yml",
LagoonYAML: "internal/testdata/node/lagoon.yml",
ProjectVariables: []lagoon.EnvironmentVariable{
{
Name: "LAGOON_SERVICE_TYPES",
Value: "node:node-persistent",
Scope: "build",
},
},
}, true),
templatePath: "testoutput",
want: "internal/testdata/node/autogen-templates/ingress-10",
emptyDir: true,
want: "",
wantErr: true,
},
{
name: "test13 autogenerated route development service type override",
name: "test-development-service-type-override-b",
description: `this test should pass because the replacement service type is just a basic type
realistically, this is not something that should be done on an already deployed service due to changing
service types not being properly supported`,
args: testdata.GetSeedData(
testdata.TestData{
ProjectName: "example-project",
Expand All @@ -248,13 +252,13 @@ func TestAutogeneratedIngressGeneration(t *testing.T) {
ProjectVariables: []lagoon.EnvironmentVariable{
{
Name: "LAGOON_SERVICE_TYPES",
Value: "node:node-persistent",
Value: "node:basic",
Scope: "build",
},
},
}, true),
templatePath: "testoutput",
want: "internal/testdata/node/autogen-templates/ingress-11",
want: "internal/testdata/node/autogen-templates/test-development-service-type-override",
},
{
name: "test14 autogenerated route development no service type override",
Expand Down
Loading

0 comments on commit e606b4d

Please sign in to comment.