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

fix: improve support of non-buildkit Docker build #880

Merged
merged 1 commit into from
Aug 16, 2023
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
4 changes: 4 additions & 0 deletions changelog.d/20230731_110301_regis_fix_non_buildkit_build.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
- [Improvement] Improve support of legacy non-BuildKit mode: (by @regisb)
- [Bugfix] Fix building of openedx Docker image.
- [Improvement] Remove `--cache-from` build option.
- [Improvement] Add a warning concerning the lack of support of the `--build-context` option.
1 change: 0 additions & 1 deletion tests/commands/test_images.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,6 @@ def test_images_build_plugin_with_args(self, image_build: Mock) -> None:
"--target",
"target",
"docker_args",
"--cache-from=type=registry,ref=service1:1.0.0-cache",
],
list(image_build.call_args[0][1:]),
)
Expand Down
28 changes: 18 additions & 10 deletions tutor/commands/images.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,16 +223,27 @@ def build(
image_build_args = [*command_args, *custom_args]

# Registry cache
if not no_registry_cache:
image_build_args.append(f"--cache-from=type=registry,ref={tag}-cache")
if cache_to_registry:
image_build_args.append(
f"--cache-to=type=registry,mode=max,ref={tag}-cache"
)
if utils.is_buildkit_enabled():
if not no_registry_cache:
image_build_args.append(
f"--cache-from=type=registry,ref={tag}-cache"
)
if cache_to_registry:
image_build_args.append(
f"--cache-to=type=registry,mode=max,ref={tag}-cache"
)

# Build contexts
for host_path, stage_name in build_contexts.get(name, []):
image_build_args.append(f"--build-context={stage_name}={host_path}")
if utils.is_buildkit_enabled():
fmt.echo_info(
f"Adding {host_path} to the build context '{stage_name}' of image '{image}'"
)
image_build_args.append(f"--build-context={stage_name}={host_path}")
else:
fmt.echo_alert(
f"Unable to add {host_path} to the build context '{stage_name}' of image '{host_path}' because BuildKit is disabled."
)

# Build
images.build(
Expand All @@ -257,9 +268,6 @@ def get_image_build_contexts(config: Config) -> dict[str, list[tuple[str, str]]]
for image_name, stage_name in hooks.Filters.IMAGES_BUILD_MOUNTS.iterate(
user_mount
):
fmt.echo_info(
f"Adding {user_mount} to the build context '{stage_name}' of image '{image_name}'"
)
if image_name not in build_contexts:
build_contexts[image_name] = []
build_contexts[image_name].append((user_mount, stage_name))
Expand Down
7 changes: 7 additions & 0 deletions tutor/templates/build/openedx/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@ RUN {% if is_buildkit_enabled() %}--mount=type=cache,target=/openedx/.cache/pip,
setuptools==67.6.1 pip==23.0.1. wheel==0.40.0

# Install base requirements
{% if not is_buildkit_enabled() %}
COPY --from=edx-platform /requirements/edx/base.txt /openedx/edx-platform/requirements/edx/base.txt
{% endif %}
RUN {% if is_buildkit_enabled() %}--mount=type=bind,from=edx-platform,source=/requirements/edx/base.txt,target=/openedx/edx-platform/requirements/edx/base.txt \
--mount=type=cache,target=/openedx/.cache/pip,sharing=shared {% endif %}pip install -r /openedx/edx-platform/requirements/edx/base.txt

Expand Down Expand Up @@ -126,6 +129,10 @@ RUN nodeenv /openedx/nodeenv --node=16.14.0 --prebuilt
# Install nodejs requirements
ARG NPM_REGISTRY={{ NPM_REGISTRY }}
WORKDIR /openedx/edx-platform
{% if not is_buildkit_enabled() %}
COPY --from=edx-platform /package.json /openedx/edx-platform/package.json
COPY --from=edx-platform /package-lock.json /openedx/edx-platform/package-lock.json
{% endif %}
RUN {% if is_buildkit_enabled() %}--mount=type=bind,from=edx-platform,source=/package.json,target=/openedx/edx-platform/package.json \
--mount=type=bind,from=edx-platform,source=/package-lock.json,target=/openedx/edx-platform/package-lock.json \
--mount=type=cache,target=/root/.npm,sharing=shared {% endif %}npm clean-install --no-audit --registry=$NPM_REGISTRY
Expand Down