Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

change: update docker and enable buildkit by default #360

Merged
merged 4 commits into from
Sep 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ ARG UPSTREAM_REPO
ARG UPSTREAM_TAG
ARG GO_VER
FROM ${UPSTREAM_REPO:-uselagoon}/commons:${UPSTREAM_TAG:-latest} AS commons

FROM golang:${GO_VER:-1.22}-alpine3.20 AS golang

RUN apk add --no-cache git
Expand Down Expand Up @@ -35,7 +36,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/build-deploy-tool" repository="https://github.com/uselagoon/build-deploy-tool"
Expand Down
2 changes: 1 addition & 1 deletion cmd/identify_imagebuild.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down
30 changes: 15 additions & 15 deletions cmd/identify_imagebuild_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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{
Expand All @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion internal/generator/buildvalues.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down
5 changes: 4 additions & 1 deletion internal/generator/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 7 additions & 5 deletions legacy/build-deploy-docker-compose.sh
Original file line number Diff line number Diff line change
Expand Up @@ -641,11 +641,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
Expand Down
Loading