Enhancement: Enable support for containerized EasyEngine deployments #476
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.
Description
This PR updates the /etc/hosts modification logic to ensure compatibility when EasyEngine is running inside a Docker container (Containerized CLI).
The Problem
Currently, EasyEngine uses Filesystem::dumpFile() (or similar atomic-write logic) which attempts to create a temporary file and rename it to /etc/hosts. In Docker environments where /etc/hosts is bind-mounted from the host machine, this operation fails with "Device or resource busy" because Docker does not allow changing the Inode of mounted system files.
The Solution
The logic has been updated to use direct stream writing via file_put_contents() with LOCK_EX.
Inode Preservation: By writing directly to the existing file, we preserve the Inode, allowing Docker to sync changes seamlessly between the container and the host.
Backwards Compatibility: This change is completely transparent to users running EasyEngine natively on Linux/macOS.
Robustness: Switched to preg_quote() for safer regex handling of site URLs.
Reference Case
This improvement is based on successful implementation in a containerized version of EasyEngine available here: dinhngocdung/easyengine. This image allows users to run EasyEngine as a standalone tool without native installation, and this PR upstreaming ensures the core logic supports this modern deployment method.
Changes
Modified remove_etc_hosts_entry() to use file_put_contents.
Improved regex patterns to be more resilient and documented in English.
Added explicit exception handling for better debugging in container environments.