Enhancement: Add descriptive name for docker container images#67827
Conversation
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
|
Hey, thanks for implementing this. The one change I would suggest would be to check is there already a cache directory for this project. Otherwise people will Option 1: keep using the old directory // Traditional cache directory name
const md5CacheDirectoryPath = path.resolve(
await getCacheDirectory(),
md5( configFilePath )
);
// If there is an older-style cache directory, use that, otherwise use the more descriptive name.
const cacheDirectoryPath = fs.existsSync( md5CacheDirectoryPath )
? md5CacheDirectoryPath
: path.resolve(
await getCacheDirectory(),
'wp-env-' + directory + '-' + md5( configFilePath )
);Option 2: Rename the old directory to the new name // Traditional cache directory name
const md5CacheDirectoryPath = path.resolve(
await getCacheDirectory(),
md5( configFilePath )
);
// Newer, more descriptive directory name
const cacheDirectoryPath = path.resolve(
await getCacheDirectory(),
'wp-env-' + directory + '-' + md5( configFilePath )
);
// If there is an older-style cache directory, rename it to the more descriptive name.
if(fs.existsSync( md5CacheDirectoryPath )) {
await fs.promises.rename( md5CacheDirectoryPath, cacheDirectoryPath );
}The first option is safe. The second one is probably safe – I don't know where else this id might be used. I guess in Docker itself, once the directory is renamed Docker will treat it as missing. If the container is already running when NB: I don't write much JavaScript and I haven't tested that code. |
e4a508a to
d4b8a76
Compare
|
@BrianHenryIE Thanks for looking into this! As per your guidance, I am in favour of Option 1 as it is relatively much safer. I've ensured that if an older cache directory exists than it uses that, else create with the more descriptive name. |
6fd6ea0 to
679ff26
Compare
679ff26 to
14169c0
Compare
|
Updated the PR @BrianHenryIE |
mcsf
left a comment
There was a problem hiding this comment.
I've left a few suggestions, but I'm interested in more opinions.
Co-authored-by: Miguel Fonseca <150562+mcsf@users.noreply.github.com>
e59ea75 to
5c80ea5
Compare
|
Updates since last review:-
wp-env-gutenberg-4f82b1c3-wordpress-1 # dev
wp-env-gutenberg-test-05be9432-wordpress-1 # test env |
|
Hi @mcsf hoping to get your review, whenever you get some bandwidth 🙂 |
mcsf
left a comment
There was a problem hiding this comment.
Thanks for your work and for your patience, @Takshil-Kunadia!
| // Descriptive cache directory name. Format: wp-env-<project-dir>[-<variant>]-<short-hash> | ||
| const descriptiveCacheDirectoryPath = path.resolve( | ||
| await getCacheDirectory(), | ||
| buildDescriptiveCacheDirectoryName( configFilePath ) | ||
| ); |
There was a problem hiding this comment.
It's a minor point by now, but we should avoid computing this path when we don't need it:
const cacheDirPath = existsSync( legacyPath )
? legacyPath
: path.resolve(
await getCacheDir(),
buildDescriptiveName( conf ))
or, more readable:
let cacheDirPath = legacyPath
if ( ! exists( cacheDirPath ) ) {
cacheDirPath = path.resolve(
..
)
}
There was a problem hiding this comment.
I didn't want to block your PR because of this small thing, so feel free to submit a subsequent patch for this!
There was a problem hiding this comment.
I raise a follow up PR to implement this lazy-evaluation 👍

Resolves #64153
What?
The docker container image names are indistinguishable. See screenshots shared in #64153
Container, image, and cache-directory names generated by wp-env are an indistinguishable wall of md5 hashes. This PR replaces them with readable, directory-aware names while preserving every existing environment on disk.
Why?
It would enhance the clarity and usability of directory names generated by wp-env. Using more descriptive names based on the project folder and file would make it easier to identify directories. Container names remain unique while reducing clutter in file explorers or Docker, making management more efficient. This solution would simplify troubleshooting and improve workflow for developers.
How?
Instead of directly using MD5 of the directory name
gutenberg/packages/env/lib/config/load-config.js
Lines 45 to 48 in f9b966b
As suggested use a prefix. Prepend it with
wp-env-<project-dir>[-<variant>]-<short-hash>Backwards compatibility
Upgrading wp-env must not orphan a running environment. If the legacy pure-md5 cache directory already exists for a given config file, wp-env keeps using it; the new descriptive name only takes effect for fresh environments.
Adopting the new names on an existing environment
Run
wp-env destroyfollowed bywp-env start. (destroy will delete all resources, please test this in a new env, not an old one whose data you wanna preserve)Testing Instructions
npm run build..wp-env.json, runnpm run wp-env start.ls ~/.wp-env/showswp-env-<folder>-<8hex>/.docker psshows readable container names.npx wp-env start --config .wp-env.test.json, container names should include-test-..wp-env.jsonin a subdirectory of another project with.wp-env.jsonshould produce a distinct cache dir.Screenshots