Ensure reliable /etc/hosts handling for EasyEngine in containerized environments
まだ誰も着手していません。
評価
- 難易度
- 3/5
- 見積もり時間
- 1〜2日
- 初心者へのやさしさ
- 42/100
- issue の種類
- バグ
- 明瞭さ
- 明確に書かれている
- 活発さ
- 停滞
- 技術スタック
- docker, php
調査の方向性
src/helper/site-utils.php の remove_etc_hosts_entry から始め、/etc/hosts の読み取りと更新の方法を確認します。/etc/hosts をマウントした Docker コンテナ内と、ホストレベルの環境の両方で、読み取りまたは書き込みに失敗した場合も含めて動作を検証します。既存の削除動作が維持され、コンテナ化された操作がサイレントに失敗しなくなれば完了です。
索引モデルが issue の本文から書いたものです。
説明
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");
}
}
- 主要言語
- PHP
- スター
- 18
- フォーク
- 27
- PR マージ指標
- 30日以内にマージされた PR はありません
環境構築
このプロジェクトの環境構築ファイルはまだ確認していません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
EasyEngine/site-command のほかの issue
-
難易度 4/5 3〜5日 初心者へのやさしさ 30/100
EasyEngine/site-command#395 · コメント 2 件 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 45/100
EasyEngine/site-command#377 ·
-
難易度 3/5 1〜2日 初心者へのやさしさ 25/100
EasyEngine/site-command#375 ·
-
難易度 4/5 3〜5日 初心者へのやさしさ 20/100
EasyEngine/site-command#373 ·
-
難易度 4/5 3〜5日 初心者へのやさしさ 38/100
EasyEngine/site-command#330 ·
EasyEngine/site-command の issue をすべて見る
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
-
domain/crm-after-sales Platform(Default) priority/high
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
メンテナーはふだん 1 日以内に返信
-
kind/bug status/to verify
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
PHP-CS-Fixer/PHP-CS-Fixer#9867 ·
メンテナーはふだん 1 日以内に返信
-
sync-en
難易度 1/5 1〜3時間 初心者へのやさしさ 86/100
メンテナーはふだん 2 日以内に返信
-
sync-en
難易度 1/5 1〜3時間 初心者へのやさしさ 88/100
メンテナーはふだん 2 日以内に返信