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

chore: initial DOCKER_PROJECT_BUILDER #381

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
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
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ RUN --mount=type=cache,target=/root/.cache/go-build \
# RUN go mod download
# RUN go build -o /app/build-deploy-tool

FROM docker:27.1.1-alpine3.20
FROM docker:27.3.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
20 changes: 18 additions & 2 deletions legacy/build-deploy-docker-compose.sh
Original file line number Diff line number Diff line change
Expand Up @@ -650,13 +650,24 @@ if [[ "$BUILD_TYPE" == "pullrequest" || "$BUILD_TYPE" == "branch" ]]; then
echo "Using BuildKit for $DOCKERFILE"
fi

# Decide whether to use a dedicated project builder for Docker builds - disabled by default.
DOCKER_PROJECT_BUILDER=default
if [ "$(featureFlag DOCKER_PROJECT_BUILDER)" = enabled ]; then
DOCKER_PROJECT_BUILDER=${PROJECT}
docker builder create --name $DOCKER_PROJECT_BUILDER --driver docker-container || true
fi

# now do the actual image build
if [ $BUILD_TARGET == "false" ]; then
echo "Building ${BUILD_CONTEXT}/${DOCKERFILE}"
DOCKER_BUILDKIT=$DOCKER_BUILDKIT docker build --network=host "${BUILD_ARGS[@]}" -t $TEMPORARY_IMAGE_NAME -f $BUILD_CONTEXT/$DOCKERFILE $BUILD_CONTEXT
if [ $DOCKER_BUILDKIT -eq 0 ]; then
DOCKER_BUILDKIT=$DOCKER_BUILDKIT docker build --network=host "${BUILD_ARGS[@]}" -t $TEMPORARY_IMAGE_NAME -f $BUILD_CONTEXT/$DOCKERFILE $BUILD_CONTEXT
else
DOCKER_BUILDKIT=$DOCKER_BUILDKIT docker build --network=host --builder $DOCKER_PROJECT_BUILDER --load "${BUILD_ARGS[@]}" -t $TEMPORARY_IMAGE_NAME -f $BUILD_CONTEXT/$DOCKERFILE $BUILD_CONTEXT
fi
else
echo "Building target ${BUILD_TARGET} for ${BUILD_CONTEXT}/${DOCKERFILE}"
DOCKER_BUILDKIT=$DOCKER_BUILDKIT docker build --network=host "${BUILD_ARGS[@]}" -t $TEMPORARY_IMAGE_NAME -f $BUILD_CONTEXT/$DOCKERFILE --target $BUILD_TARGET $BUILD_CONTEXT
DOCKER_BUILDKIT=$DOCKER_BUILDKIT docker build --network=host --builder $DOCKER_PROJECT_BUILDER --load "${BUILD_ARGS[@]}" -t $TEMPORARY_IMAGE_NAME -f $BUILD_CONTEXT/$DOCKERFILE --target $BUILD_TARGET $BUILD_CONTEXT
fi

# Keep a list of the images we have built, as we need to push them to the registry later
Expand All @@ -668,6 +679,11 @@ if [[ "$BUILD_TYPE" == "pullrequest" || "$BUILD_TYPE" == "branch" ]]; then
done
fi

if [ "$(featureFlag DOCKER_PROJECT_BUILDER)" = enabled ]; then
echo "stopping builder $DOCKER_PROJECT_BUILDER"
docker builder stop --builder $DOCKER_PROJECT_BUILDER
fi
shreddedbacon marked this conversation as resolved.
Show resolved Hide resolved

# print information about built image sizes
function printBytes {
local -i bytes=$1;
Expand Down
Loading