From fe6454ca547d67d9b63e172afff614e70bb1c68d Mon Sep 17 00:00:00 2001 From: Toby Bellwood Date: Wed, 21 Aug 2024 10:13:21 +1000 Subject: [PATCH 1/2] build: update docker version to 27.1.1 --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 6f45d2e7..776e449b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -35,7 +35,7 @@ RUN --mount=type=cache,target=/root/.cache/go-build \ # RUN go mod download # RUN go build -o /app/build-deploy-tool -FROM docker:20.10.24 +FROM docker:27.1.1-alpine3.20 LABEL org.opencontainers.image.authors="The Lagoon Authors" maintainer="The Lagoon Authors" LABEL org.opencontainers.image.source="https://github.com/uselagoon/lagoon-images" repository="https://github.com/uselagoon/lagoon-images" From 6357fd055e4f6a4ac50cc61933bb6541ec0ab2bb Mon Sep 17 00:00:00 2001 From: Toby Bellwood Date: Wed, 21 Aug 2024 10:56:06 +1000 Subject: [PATCH 2/2] chore: enable BuildKit by default --- Dockerfile | 6 +++--- cmd/identify_imagebuild.go | 2 +- cmd/identify_imagebuild_test.go | 30 +++++++++++++-------------- internal/generator/buildvalues.go | 2 +- internal/generator/generator.go | 5 ++++- legacy/build-deploy-docker-compose.sh | 12 ++++++----- 6 files changed, 31 insertions(+), 26 deletions(-) diff --git a/Dockerfile b/Dockerfile index 776e449b..00fcec7c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,8 +1,8 @@ ARG UPSTREAM_REPO ARG UPSTREAM_TAG ARG GO_VER -FROM ${UPSTREAM_REPO:-uselagoon}/commons:${UPSTREAM_TAG:-latest} as commons -FROM golang:${GO_VER:-1.21}-alpine3.18 as golang +FROM ${UPSTREAM_REPO:-uselagoon}/commons:${UPSTREAM_TAG:-latest} AS commons +FROM golang:${GO_VER:-1.21}-alpine3.18 AS golang RUN apk add --no-cache git RUN go install github.com/a8m/envsubst/cmd/envsubst@v1.4.2 @@ -72,7 +72,7 @@ RUN apk add -U --repository http://dl-cdn.alpinelinux.org/alpine/edge/testing au && apk upgrade --no-cache openssh openssh-keygen openssh-client-common openssh-client-default \ && apk add --no-cache openssl curl jq parallel bash git py-pip skopeo \ && git config --global user.email "lagoon@lagoon.io" && git config --global user.name lagoon \ - && pip install shyaml yq + && pip install --break-system-packages shyaml yq RUN architecture=$(case $(uname -m) in x86_64 | amd64) echo "amd64" ;; aarch64 | arm64 | armv8) echo "arm64" ;; *) echo "amd64" ;; esac) \ && curl -Lo /usr/bin/kubectl https://dl.k8s.io/release/$KUBECTL_VERSION/bin/linux/${architecture}/kubectl \ diff --git a/cmd/identify_imagebuild.go b/cmd/identify_imagebuild.go index 071e594a..3aa6f427 100644 --- a/cmd/identify_imagebuild.go +++ b/cmd/identify_imagebuild.go @@ -31,7 +31,7 @@ var imageBuildIdentify = &cobra.Command{ } type imageBuild struct { - BuildKit bool `json:"buildKit"` + BuildKit *bool `json:"buildKit"` Images []imageBuilds `json:"images"` BuildArguments map[string]string `json:"buildArguments"` ContainerRegistries []generator.ContainerRegistry `json:"containerRegistries,omitempty"` diff --git a/cmd/identify_imagebuild_test.go b/cmd/identify_imagebuild_test.go index 5e55a1ee..7490343f 100644 --- a/cmd/identify_imagebuild_test.go +++ b/cmd/identify_imagebuild_test.go @@ -34,7 +34,7 @@ func TestImageBuildConfigurationIdentification(t *testing.T) { LagoonYAML: "internal/testdata/basic/lagoon.yml", }, true), want: imageBuild{ - BuildKit: false, + BuildKit: helpers.BoolPtr(true), BuildArguments: map[string]string{ "LAGOON_BUILD_NAME": "lagoon-build-abcdefg", "LAGOON_PROJECT": "example-project", @@ -72,7 +72,7 @@ func TestImageBuildConfigurationIdentification(t *testing.T) { LagoonYAML: "internal/testdata/complex/lagoon.varnish.yml", }, true), want: imageBuild{ - BuildKit: false, + BuildKit: helpers.BoolPtr(true), BuildArguments: map[string]string{ "LAGOON_BUILD_NAME": "lagoon-build-abcdefg", "LAGOON_PROJECT": "example-project", @@ -158,7 +158,7 @@ func TestImageBuildConfigurationIdentification(t *testing.T) { }, }, true), want: imageBuild{ - BuildKit: false, + BuildKit: helpers.BoolPtr(true), BuildArguments: map[string]string{ "LAGOON_FEATURE_FLAG_ROOTLESS_WORKLOAD": "enabled", "LAGOON_BUILD_NAME": "lagoon-build-abcdefg", @@ -235,7 +235,7 @@ func TestImageBuildConfigurationIdentification(t *testing.T) { }, }, true), want: imageBuild{ - BuildKit: false, + BuildKit: helpers.BoolPtr(true), BuildArguments: map[string]string{ "LAGOON_FEATURE_FLAG_ROOTLESS_WORKLOAD": "enabled", "LAGOON_BUILD_NAME": "lagoon-build-abcdefg", @@ -282,7 +282,7 @@ func TestImageBuildConfigurationIdentification(t *testing.T) { }, }, { - name: "test4 - basic-persistent with worker-persistent with buildkit", + name: "test4 - basic-persistent with worker-persistent with buildkit disabled", description: "create a basic-persistent that gets a pvc and mount that volume on a worker-persistent type", args: testdata.GetSeedData( testdata.TestData{ @@ -298,16 +298,16 @@ func TestImageBuildConfigurationIdentification(t *testing.T) { }, { Name: "DOCKER_BUILDKIT", - Value: "true", + Value: "false", Scope: "build", }, }, }, true), want: imageBuild{ - BuildKit: true, + BuildKit: helpers.BoolPtr(false), BuildArguments: map[string]string{ "LAGOON_FEATURE_FLAG_ROOTLESS_WORKLOAD": "enabled", - "DOCKER_BUILDKIT": "true", + "DOCKER_BUILDKIT": "false", "LAGOON_BUILD_NAME": "lagoon-build-abcdefg", "LAGOON_PROJECT": "example-project", "LAGOON_ENVIRONMENT": "main", @@ -354,7 +354,7 @@ func TestImageBuildConfigurationIdentification(t *testing.T) { LagoonYAML: "internal/testdata/basic/lagoon.yml", }, true), want: imageBuild{ - BuildKit: false, + BuildKit: helpers.BoolPtr(true), BuildArguments: map[string]string{ "LAGOON_BUILD_NAME": "lagoon-build-abcdefg", "LAGOON_PROJECT": "example-project", @@ -395,7 +395,7 @@ func TestImageBuildConfigurationIdentification(t *testing.T) { }, }, true), want: imageBuild{ - BuildKit: false, + BuildKit: helpers.BoolPtr(true), BuildArguments: map[string]string{ "LAGOON_BUILD_NAME": "lagoon-build-abcdefg", "LAGOON_PROJECT": "example-project", @@ -439,7 +439,7 @@ func TestImageBuildConfigurationIdentification(t *testing.T) { LagoonYAML: "internal/testdata/complex/lagoon.varnish.yml", }, true), want: imageBuild{ - BuildKit: false, + BuildKit: helpers.BoolPtr(true), BuildArguments: map[string]string{ "LAGOON_BUILD_NAME": "lagoon-build-abcdefg", "LAGOON_PROJECT": "example-project", @@ -503,7 +503,7 @@ func TestImageBuildConfigurationIdentification(t *testing.T) { }, }, true), want: imageBuild{ - BuildKit: false, + BuildKit: helpers.BoolPtr(true), BuildArguments: map[string]string{ "LAGOON_BUILD_NAME": "lagoon-build-abcdefg", "LAGOON_PROJECT": "example-project", @@ -585,7 +585,7 @@ func TestImageBuildConfigurationIdentification(t *testing.T) { ImageCacheBuildArgsJSON: `[{"image":"harbor.example/example-project/main/node@sha256:e90daba405cbf33bab23fe8a021146811b2c258df5f2afe7dadc92c0778eef45","name":"node"}]`, }, true), want: imageBuild{ - BuildKit: false, + BuildKit: helpers.BoolPtr(true), BuildArguments: map[string]string{ "LAGOON_BUILD_NAME": "lagoon-build-abcdefg", "LAGOON_PROJECT": "example-project", @@ -631,7 +631,7 @@ func TestImageBuildConfigurationIdentification(t *testing.T) { }, }, true), want: imageBuild{ - BuildKit: false, + BuildKit: helpers.BoolPtr(true), BuildArguments: map[string]string{ "LAGOON_BUILD_NAME": "lagoon-build-abcdefg", "LAGOON_PROJECT": "example-project", @@ -722,7 +722,7 @@ func TestImageBuildConfigurationIdentification(t *testing.T) { LagoonYAML: "internal/testdata/basic/lagoon.forcebaseimagepull.yml", }, true), want: imageBuild{ - BuildKit: false, + BuildKit: helpers.BoolPtr(true), BuildArguments: map[string]string{ "LAGOON_BUILD_NAME": "lagoon-build-abcdefg", "LAGOON_PROJECT": "example-project", diff --git a/internal/generator/buildvalues.go b/internal/generator/buildvalues.go index 9ba9c12f..f1494aef 100644 --- a/internal/generator/buildvalues.go +++ b/internal/generator/buildvalues.go @@ -65,7 +65,7 @@ type BuildValues struct { CronjobsDisabled bool `json:"cronjobsDisabled" description:"this controls whether cronjobs are enabled for this environment or not"` FeatureFlags map[string]bool `json:"-" description:"these are used by templating systems to turn on or off certain functionality based on if feature flags are defined"` ImageRegistry string `json:"imageRegistry" description:"the image registry in use for this environment, usually harbor"` - DockerBuildKit bool `json:"dockerBuildKit" description:"the flag to determine if docker buildkit is used"` + DockerBuildKit *bool `json:"dockerBuildKit" description:"the flag to determine if docker buildkit is used"` ImageBuildArguments map[string]string `json:"imageBuildArguments" description:"where the calculated image build arguments are stored"` EnvironmentVariables []lagoon.EnvironmentVariable `json:"environmentVariables" description:"the merged project and environment variables for this environment"` LagoonYAML lagoon.YAML `json:"lagoonYAML" description:"the unmarshalled lagoon yaml file"` diff --git a/internal/generator/generator.go b/internal/generator/generator.go index e84f5f44..80a7be5d 100644 --- a/internal/generator/generator.go +++ b/internal/generator/generator.go @@ -353,7 +353,10 @@ func NewGenerator( // collect docker buildkit value dockerBuildKit, _ := lagoon.GetLagoonVariable("DOCKER_BUILDKIT", []string{"build"}, buildValues.EnvironmentVariables) if dockerBuildKit != nil { - buildValues.DockerBuildKit, _ = strconv.ParseBool(dockerBuildKit.Value) + bk, _ := strconv.ParseBool(dockerBuildKit.Value) + buildValues.DockerBuildKit = &bk + } else { + buildValues.DockerBuildKit = helpers.BoolPtr(true) } // get any lagoon service type overrides diff --git a/legacy/build-deploy-docker-compose.sh b/legacy/build-deploy-docker-compose.sh index 8b416f1a..ec2b616c 100755 --- a/legacy/build-deploy-docker-compose.sh +++ b/legacy/build-deploy-docker-compose.sh @@ -644,11 +644,13 @@ if [[ "$BUILD_TYPE" == "pullrequest" || "$BUILD_TYPE" == "branch" ]]; then BUILD_CONTEXT=$(echo "$IMAGE_BUILD_DATA" | jq -r '.imageBuild.context // ""') # the build target for this image build, the original source for this value is from the `docker-compose file` BUILD_TARGET=$(echo "$IMAGE_BUILD_DATA" | jq -r '.imageBuild.target // false') - # determine if buildkit should be used for this build - DOCKER_BUILDKIT=0 - if [ "$(echo "${ENVIRONMENT_IMAGE_BUILD_DATA}" | jq -r '.buildKit // false')" == "true" ]; then - DOCKER_BUILDKIT=1 - echo "Using BuildKit for $DOCKERFILE"; + # determine if buildkit should be disabled for this build + DOCKER_BUILDKIT=1 + if [ "$(echo "${ENVIRONMENT_IMAGE_BUILD_DATA}" | jq -r '.buildKit')" == "false" ]; then + DOCKER_BUILDKIT=0 + echo "Not using BuildKit for $DOCKERFILE" + else + echo "Using BuildKit for $DOCKERFILE" fi # now do the actual image build