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 1 commit
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
34 changes: 32 additions & 2 deletions legacy/build-deploy-docker-compose.sh
Original file line number Diff line number Diff line change
Expand Up @@ -650,13 +650,43 @@ 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 [ ! -z "$LAGOON_PROJECT_VARIABLES" ]; then
DOCKER_PROJECT_BUILDER=($(echo $LAGOON_PROJECT_VARIABLES | jq -r '.[] | select(.scope == "build") | select(.name == "DOCKER_PROJECT_BUILDER") | "\(.value)"'))
fi
if [ ! -z "$LAGOON_ENVIRONMENT_VARIABLES" ]; then
TEMP_DOCKER_PROJECT_BUILDER=($(echo $LAGOON_ENVIRONMENT_VARIABLES | jq -r '.[] | select(.scope == "build") | select(.name == "DOCKER_PROJECT_BUILDER") | "\(.value)"'))
if [ ! -z $TEMP_DOCKER_PROJECT_BUILDER ]; then
DOCKER_PROJECT_BUILDER=$TEMP_DOCKER_PROJECT_BUILDER
fi
fi

case "$DOCKER_PROJECT_BUILDER" in
default|Default|False|false|0)
DOCKER_PROJECT_BUILDER=default
echo "Using default builder for $DOCKERFILE";
;;
*)
echo "Using dedicated builder $PROJECT for $DOCKERFILE";
DOCKER_PROJECT_BUILDER=${PROJECT}
docker builder create --name $DOCKER_PROJECT_BUILDER --driver docker-container || true
;;
esac
set -x

tobybellwood marked this conversation as resolved.
Show resolved Hide resolved
# 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 Down
Loading