-
-
Notifications
You must be signed in to change notification settings - Fork 175
Optimize Docker builds: move asset compilation to native platform stage #1139
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
base: master
Are you sure you want to change the base?
Conversation
e2d4f78 to
2962dee
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #1139 +/- ##
============================================
- Coverage 58.31% 58.30% -0.02%
Complexity 7294 7294
============================================
Files 580 580
Lines 23207 23207
============================================
- Hits 13534 13531 -3
- Misses 9673 9676 +3 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
@copilot Does it require any change to the github action for the docker builds? |
No changes are required to the GitHub Actions workflows. Docker Buildx (already configured via
The workflows will work as-is and benefit from the performance improvements immediately. |
|
@copilot The docker builds fail with: |
... Fixed in 09bbbd3. Added The issue was that composer needs git when installing some packages from source. The multi-stage build exposed this latent dependency because the composer-deps stage uses Git is already present in Dockerfile-frankenphp, so only Dockerfile needed the update. |
|
|
... Fixed in 4a73aa3. Added a The issue was that webpack needs The fix adds an intermediate stage that:
This maintains the performance benefit of building assets once on native platform while ensuring all required files are available. |
|
|
|
... Fixed in 8e8ada6. Added The Symfony console commands require the |
- Add multi-stage build with separate composer-deps and assets stages - Assets are built once on native platform (node:22-bookworm-slim) - Pre-built assets copied into final images for all platforms - Remove Node.js/Yarn installation from final images (smaller size) - Use --ignore-platform-reqs for composer in assets stage - Applies to both Dockerfile and Dockerfile-frankenphp Co-authored-by: jbtronics <[email protected]>
The assets are copied while running as www-data user, so the --chown flag is redundant. This makes it consistent with the frankenphp version. Co-authored-by: jbtronics <[email protected]>
Git is required by composer when installing packages from source. This dependency was exposed by the multi-stage build changes where composer-deps stage uses --no-scripts and the final stage needs to complete the installation. Co-authored-by: jbtronics <[email protected]>
Webpack build requires var/translations files generated by Symfony's cache warmup. Added intermediate 'translations' stage that: - Copies composer dependencies and app files - Generates autoloader - Runs cache warmup to create translation files - Assets stage now copies these translations before building This fixes the webpack build errors about missing translation exports. Co-authored-by: jbtronics <[email protected]>
Symfony console requires .env file to bootstrap. Added COPY .env to translations stage so cache:warmup can run successfully. Co-authored-by: jbtronics <[email protected]>
8e8ada6 to
9402382
Compare
|
@copilot Just work in the whole project directory to compile the yarn assets, and then copy over the result, to avoid the hassle with missing files in the build process |
Refactored to copy the entire project directory in composer-deps and assets stages instead of cherry-picking specific files. This: - Eliminates the separate translations stage - Avoids missing file issues - Simplifies the build process - Maintains performance benefit of building assets once on native platform Both stages now use COPY . . to get all project files, avoiding the complexity of tracking which files are needed. Co-authored-by: jbtronics <[email protected]>
Done in 6a1792d. Simplified the approach to copy the entire project directory instead of individual files. Changes:
|
|
The build process is not faster. Still each processor architecture builds the things on its own |
|
@copilot The build process is not faster. Still each processor architecture builds the things on its own |
…UILDPLATFORM Added --platform=$BUILDPLATFORM to composer-deps and assets stages to ensure they run on the native build platform (amd64) instead of being built separately for each target architecture (amd64, arm64, arm/v7). This is the critical change that makes the optimization work: - Without this flag, Docker Buildx builds these stages for each target platform - With this flag, stages run once on native platform and results are copied to all targets - Eliminates ARM emulation overhead for CPU-intensive asset compilation Co-authored-by: jbtronics <[email protected]>
Fixed in c5210a3. Added This was the missing piece - without the Now:
This is the standard Docker Buildx pattern for cross-platform builds with platform-agnostic build stages. |
Docker Build Optimization: Build Assets Outside ARM Emulation
Problem Solved
The original Docker build process installed Node.js/Yarn and built frontend assets inside each platform-specific container. For ARM platforms (arm64, arm/v7), this meant running CPU-intensive Webpack builds under QEMU emulation, which is ~10x slower than native execution.
Solution
Restructured both
DockerfileandDockerfile-frankenphpusing Docker multi-stage builds to:Critical optimization: Uses
--platform=$BUILDPLATFORMin FROM statements for composer-deps and assets stages to force execution on the native build platform (amd64), preventing Docker Buildx from building these stages separately under emulation for each target architecture.Technical Changes
Dockerfile (47 additions, 64 deletions):
--platform=$BUILDPLATFORMto composer-deps and assets stages (critical for performance)composer-depsstage that copies entire project withCOPY . .assetsstage for building frontend assetsyarn install && yarn buildfrom final stageCOPY --from=assets /build/public/build ./public/buildgitpackage (required by composer for source installs)Dockerfile-frankenphp (same structure):
--platform=$BUILDPLATFORMto composer-deps and assets stages (critical for performance)composer-depsstage that copies entire projectassetsstage with all project filesyarn buildfrom final stageBenefits
How It Works
The
--platform=$BUILDPLATFORMflag is essential for this optimization:Validation
Checklist
Original prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.