diff --git a/changelog.d/20230731_110301_regis_fix_non_buildkit_build.md b/changelog.d/20230731_110301_regis_fix_non_buildkit_build.md new file mode 100644 index 0000000..74c9b73 --- /dev/null +++ b/changelog.d/20230731_110301_regis_fix_non_buildkit_build.md @@ -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. diff --git a/tests/commands/test_images.py b/tests/commands/test_images.py index f3e0132..cd0545a 100644 --- a/tests/commands/test_images.py +++ b/tests/commands/test_images.py @@ -147,7 +147,6 @@ class ImagesTests(PluginsTestCase, TestCommandMixin): "--target", "target", "docker_args", - "--cache-from=type=registry,ref=service1:1.0.0-cache", ], list(image_build.call_args[0][1:]), ) diff --git a/tutor/commands/images.py b/tutor/commands/images.py index 0108fed..d21e280 100644 --- a/tutor/commands/images.py +++ b/tutor/commands/images.py @@ -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( @@ -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)) diff --git a/tutor/templates/build/openedx/Dockerfile b/tutor/templates/build/openedx/Dockerfile index abfe968..f515550 100644 --- a/tutor/templates/build/openedx/Dockerfile +++ b/tutor/templates/build/openedx/Dockerfile @@ -89,6 +89,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 @@ -123,6 +126,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