Fix tests silently skipped by Docker BuildKit#76
Conversation
Docker BuildKit (default since Docker 23.0) optimizes builds by skipping stages that are not referenced by the final target. The test stage (FROM build AS test) was not a dependency of the ship stage, so BuildKit skipped it entirely, meaning tests never ran during faas-cli build. Remove the separate test stage and move the test commands into the build stage which the ship stage depends on, ensuring tests are always executed when enabled. Change TEST_ENABLED default from true to false so tests are opt-in via --build-arg TEST_ENABLED=true. Signed-off-by: Han Verstraete <han@openfaas.com>
AI Pull Request OverviewSummary
Approval rating (1-10)9 Summary per fileSummary per file
Overall AssessmentThe changes correctly address the issue with Docker BuildKit silently skipping tests by integrating test execution into the build stage, which is a prerequisite for the final ship stage. Making testing opt-in by default is a sensible performance optimization. The modifications are consistent across all four template variants and align with the PR description. No regressions or security concerns identified. Detailed ReviewDetailed ReviewDockerfile ChangesAll four Dockerfiles (python3-flask, python3-flask-debian, python3-http, python3-http-debian) have identical changes:
This approach resolves the core issue without introducing new dependencies or altering the build process for users who disable tests. Test File Comment UpdatesEach README.md UpdateThe testing section now states "Testing is disabled by default and must be explicitly enabled," which is accurate and helps users understand the change. The examples for enabling tests via CLI or YAML remain unchanged and correct. Potential Considerations
No code issues, security risks, or performance regressions observed. AI agent details. |
Description
Remove the separate
FROM build AS teststage from all template Dockerfiles and move the test commands directly into thebuildstage. Change the default value ofTEST_ENABLEDfromtruetofalse, making testing opt-in. Update the README andhandler_test.pycomments to reflect the new default.Motivation and Context
Docker BuildKit (the default builder since Docker 23.0) optimizes builds by skipping stages that are not referenced by the final target. The
teststage was not a dependency of theshipstage, so BuildKit silently skipped it — meaning tests never ran duringfaas-cli build.By moving the test commands into the
buildstage (whichshipdepends on), tests are guaranteed to execute when enabled.design/approvedlabelHow Has This Been Tested?
Built a function using
faas-cli buildwith--build-arg TEST_ENABLED=trueand verified that tests are executed during the build. Also confirmed that without the build arg, tests are skipped as expected.Types of changes
Checklist:
git commit -s