feat!: add MageForge bind-mount setup and dependency management#198
Open
dermatz wants to merge 6 commits into
Open
feat!: add MageForge bind-mount setup and dependency management#198dermatz wants to merge 6 commits into
dermatz wants to merge 6 commits into
Conversation
… config for automatic execution
Contributor
There was a problem hiding this comment.
Pull request overview
This PR adds a DDEV-side mechanism to ensure MageForge’s third-party Composer dependencies are installed into the Magento vendor/ directory when MageForge is bind-mounted into app/code (i.e., not Composer-installed in the Magento project).
Changes:
- Added a new DDEV web command to install missing MageForge
composer.jsondependencies into the Magento project. - Updated the Magento install script to run the dependency installer after installing Hyvä and before enabling the MageForge module.
- Updated DDEV
post-starthook to run the dependency installer automatically on environment start (only when Magento is already installed).
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
.ddev/config.yaml |
Runs the new dependency installer on post-start to keep Magento vendor/ in sync when MageForge is bind-mounted. |
.ddev/commands/web/install-module-deps |
New script that reads MageForge’s composer.json and installs missing non-Magento dependencies into the Magento project. |
.ddev/commands/web/install-magento |
Calls the dependency installer during Magento setup, before enabling MageForge. |
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
…le dependency script
Contributor
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
Comments suppressed due to low confidence (1)
.ddev/commands/web/install-magento:34
- The bind-mount guard runs before the "Magento already installed" short-circuit. This makes
ddev install-magentofail on already-installed setups if the mount isn't active, even though the command would otherwise exit early. Consider checking for an existing install first, then validating the bind-mount only when an install is actually needed.
# Guard: verify the MageForge bind-mount is active.
# The Docker bind-mount (../src → .../MageForge) is a kernel-level mount established
# when the containers start. If magento/ was deleted while DDEV was running, the mount
# becomes orphaned: its inode is gone, and recreating the directory produces a new inode
# not covered by the old mount. The module source would then be invisible to Magento.
# The only fix is a container restart, which re-establishes the mount on the new inode.
if [[ ! -f "${MAGENTO_FOLDER}/app/code/OpenForgeProject/MageForge/registration.php" ]]; then
echo "ERROR: The MageForge bind-mount is not active."
echo ""
echo "This happens when magento/ was deleted while DDEV was still running."
echo ""
echo "Fix: run 'ddev restart', then re-run 'ddev install-magento'."
exit 1
fi
# check if Magento is already installed
if [[ -f "${MAGENTO_FOLDER}/bin/magento" ]]; then
echo "Magento is already installed. Skipping install-magento."
exit 0
fi
Comment on lines
+41
to
+48
| \$missingConstraints = []; | ||
| \$missingNames = []; | ||
| foreach (\$deps as \$package => \$constraint) { | ||
| if (!is_dir('vendor/' . \$package)) { | ||
| \$missingConstraints[] = escapeshellarg(\"\$package:\$constraint\"); | ||
| \$missingNames[] = escapeshellarg(\$package); | ||
| } | ||
| } |
Comment on lines
+109
to
+120
| php -r " | ||
| \$f = 'app/etc/config.php'; | ||
| \$c = include \$f; | ||
| if (empty(\$c['modules']['OpenForgeProject_MageForge'])) { | ||
| \$c['modules']['OpenForgeProject_MageForge'] = 1; | ||
| ksort(\$c['modules']); | ||
| file_put_contents(\$f, '<?php' . PHP_EOL . 'return ' . var_export(\$c, true) . ';' . PHP_EOL); | ||
| echo 'Enabled OpenForgeProject_MageForge in app/etc/config.php' . PHP_EOL; | ||
| } else { | ||
| echo 'OpenForgeProject_MageForge already enabled in app/etc/config.php' . PHP_EOL; | ||
| } | ||
| " |
Comment on lines
+44
to
+56
| \$vendorDir = 'vendor/' . \$package; | ||
| // Check vendor dir exists AND the installed version satisfies the required constraint. | ||
| // A plain directory check would miss constraint changes and leave incompatible versions. | ||
| \$installedVersion = null; | ||
| \$installedJson = 'vendor/' . \$package . '/composer.json'; | ||
| if (is_dir(\$vendorDir) && is_file(\$installedJson)) { | ||
| \$installed = json_decode(file_get_contents(\$installedJson), true); | ||
| \$installedVersion = \$installed['version'] ?? null; | ||
| } | ||
| \$needsInstall = !is_dir(\$vendorDir); | ||
| if (!\$needsInstall && \$installedVersion !== null) { | ||
| // Use Composer's own semver check via the lock file if available. | ||
| \$lockFile = 'composer.lock'; |
| // This prevents Composer from touching unrelated Magento core dependencies. | ||
| passthru('composer require --no-interaction --no-update ' . implode(' ', \$missingConstraints), \$exitCode); | ||
| if (\$exitCode !== 0) { exit(\$exitCode); } | ||
| passthru('composer update --no-interaction ' . implode(' ', \$missingNames), \$exitCode); |
Comment on lines
+106
to
+110
| # Enable MageForge: the module is bind-mounted under app/code/ and therefore not registered | ||
| # via Composer autoload. bin/magento module:enable discovers it through the component registrar | ||
| # (registration.php), writes the entry to app/etc/config.php, and exits non-zero on any error. | ||
| bin/magento module:enable OpenForgeProject_MageForge | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This pull request improves the reliability and setup of the MageForge module in the Magento development environment, especially when the module is bind-mounted rather than installed via Composer. It adds robust checks to ensure the bind-mount is active, automates the installation of third-party dependencies, and clarifies the setup process to prevent common issues related to Docker mounts.
Key changes include:
Bind-mount reliability and verification:
.ddev/commands/web/install-magentoto check if the MageForge bind-mount is active, providing clear error messages and instructions if the mount is orphaned due to directory deletion while DDEV is running..ddev/config.yamlto explicitly create the full bind-mount target directory (magento/app/code/OpenForgeProject/MageForge) during pre-start, ensuring correct permissions and preventing mount issues.Dependency management for bind-mounted modules:
.ddev/commands/web/install-module-depsthat reads the module'scomposer.jsonand installs any missing non-Magento, non-PHP dependencies into the Magento vendor directory, addressing the limitation that Composer does not resolve dependencies for bind-mounted modules..ddev/commands/web/install-magentoto run the new dependency installation script after copying files and before runningsetup:upgrade, ensuring all required dependencies are present..ddev/config.yamlto automatically run the dependency installation script after the environment starts.Module registration improvements:
.ddev/commands/web/install-magentoto directly enable the MageForge module inapp/etc/config.phpvia a PHP script, ensuring the module is registered even though it's bind-mounted and not Composer-installed.