Ensure reliable /etc/hosts handling for EasyEngine in containerized environments
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức phù hợp với người mới
- 42/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức độ hoạt động
- Đình trệ
- Công nghệ
- docker, php
- Lĩnh vực
- infrastructure
Hướng nghiên cứu
Bắt đầu tại src/helper/site-utils.php, ở remove_etc_hosts_entry, và xem xét cách /etc/hosts được đọc và cập nhật. Xác minh hành vi trong cả một Docker container có /etc/hosts được mount và một môi trường ở cấp host, bao gồm cả các lỗi đọc hoặc ghi. Được xem là hoàn tất khi hành vi xóa hiện tại vẫn được giữ nguyên và các thao tác trong container không còn thất bại một cách im lặng.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Description:
This change ensures that EasyEngine can reliably handle /etc/hosts entries when deployed in Docker or containerized environments, without affecting functionality on host systems.
Context:
When EasyEngine is run inside a container, its attempt to update the host system's /etc/hosts file via a mounted volume may silently fail due to permission or compatibility issues in the Filesystem()->dumpFile() method.
/**
* Removes entry of the site from /etc/hosts
*
* @param string $site_url site name.
*
*/
function remove_etc_hosts_entry( $site_url ) {
$fs = new Filesystem();
$hosts_file = file_get_contents( '/etc/hosts' );
$site_url_escaped = preg_replace( '/\./', '\.', $site_url );
$hosts_file_new = preg_replace( "/127\.0\.0\.1\s+$site_url_escaped\n/", '', $hosts_file );
$fs->dumpFile( '/etc/hosts', $hosts_file_new );
}
Objective:
Not to change existing behavior, but to ensure consistent and reliable operation of the remove_etc_hosts_entry function across environments, especially in container deployments.
Modifications:
Refactored remove_etc_hosts_entry in src/helper/site-utils.php to use PHP's native file I/O operations with added safety and compatibility:
- Replaced
Filesystem()->dumpFile()withfile_put_contents()andfile_get_contents(). - Added
LOCK_EXto ensure atomic writes. - Used
stream_context_createwith'file' => ['privileged' => true]to improve write permissions handling in volume-mounted/etc/hosts. - Implemented
preg_quote()to safely match hostnames. - Included explicit error handling for file read/write failures.
Benefits:
- Container Compatibility: Improves EasyEngine’s robustness when run in Docker or similar environments.
- Backward-Safe: Function continues to work without modification on traditional (host-level) deployments.
- Resilience: Adds clear error messages in case of failure, reducing silent breakages.
Testing:
-
Verified successful read/write operations to
/etc/hostsin:- Docker container with volume-mounted
/etc/hosts - Host-level execution without container
- Docker container with volume-mounted
Updated Function:
/**
* Removes entry of the site from /etc/hosts
*
* @param string $site_url site name.
*
*/
function remove_etc_hosts_entry($site_url) {
$hosts_file = @file_get_contents('/etc/hosts');
if ($hosts_file === false) {
throw new Exception("Failed to read /etc/hosts");
}
$site_url_escaped = preg_quote($site_url, '/');
$hosts_file_new = preg_replace("/127\.0\.0\.1\s+$site_url_escaped\n/", '', $hosts_file);
$context = stream_context_create([
'file' => ['privileged' => true]
]);
$result = file_put_contents('/etc/hosts', $hosts_file_new, LOCK_EX, $context);
if ($result === false) {
throw new Exception("Failed to update /etc/hosts");
}
}
- Ngôn ngữ chính
- PHP
- Star
- 18
- Fork
- 27
- Merge trung bình
- 5 giờ 48 phút
- Pull request đã merge (30 ngày)
- 6
Chuẩn bị môi trường
Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của EasyEngine/site-command
-
Site Update Custom SSLĐang mở
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 30/100
EasyEngine/site-command#395 · 2 bình luận ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 45/100
EasyEngine/site-command#377 ·
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 25/100
EasyEngine/site-command#375 ·
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 20/100
EasyEngine/site-command#373 ·
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 38/100
EasyEngine/site-command#330 ·
Tất cả issue của EasyEngine/site-command
Issue tương tự
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
awslabs/aidlc-workflows#1879 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug customer-reported
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
MagnaCapax/PMSS#1011 ·
Maintainer thường phản hồi trong vòng 5 ngày
-
Talk Review
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 66/100
socallinuxexpo/scale-drupal#351 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
code4romania/cpc#47 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Bug Status: Needs Triage
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
Maintainer thường phản hồi trong vòng 1 ngày