Skip to content

Improved /etc/hosts management to support EasyEngine deployment in Containers #443

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

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

dinhngocdung
Copy link

Detailed Description:

This PR addresses the issue of EasyEngine being unable to reliably manage the host's /etc/hosts file when deployed in a container, which hinders the use of EasyEngine in virtualized environments.

-> Easyengine on Container

Problem:
The remove_etc_hosts_entry function in src/helper/site-utils.php currently uses Filesystem()->dumpFile(). This method is incompatible or has permission limitations when the container attempts to modify the host's /etc/hosts via a volume mount.

Solution:
The remove_etc_hosts_entry function has been refactored to use PHP's native file_get_contents and file_put_contents methods. Improvements include:

  • Using LOCK_EX for atomic write operations.
  • Using stream_context_create with 'file' => ['privileged' => true] for permission handling.
  • Adding explicit error handling for file read/write operations.
  • Using preg_quote to escape special characters in the URL.

Benefits:

  • Container Deployment: Enables EasyEngine to operate effectively in Docker containers, allowing precise /etc/hosts management.
  • Host Compatibility: Remains fully functional when deployed directly on the host machine.
  • Robustness: Improves the reliability of file write operations.

Testing:
Successfully tested in a Docker container environment and directly on the host machine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant