Skip to content
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

Fixed wp-env start On Windows #50895

Merged
merged 8 commits into from
May 24, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 4 additions & 8 deletions packages/env/lib/get-host-user.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,10 @@ module.exports = function getHostUser() {
const hostUser = os.userInfo();

// On Windows the uid and gid will be -1. Since there isn't a great way to handle this,
// we're just going to say that the host user is root. On Windows you'll likely be
// using WSL to run commands inside the container, which has a uid and gid. If
// you aren't, you'll be mounting directories from Windows, to a Linux
// VM (Docker Desktop uses one), to the guest OS. I assume that
// when dealing with this configuration that file ownership
// has the same kind of magic handling that macOS uses.
const uid = ( hostUser.uid === -1 ? 0 : hostUser.uid ).toString();
const gid = ( hostUser.gid === -1 ? 0 : hostUser.gid ).toString();
// we're just going to assign them to 1000. Docker Desktop already takes care of
// permission-related issues using magic, so this should be fine.
const uid = ( hostUser.uid === -1 ? 1000 : hostUser.uid ).toString();
const gid = ( hostUser.gid === -1 ? 1000 : hostUser.gid ).toString();

return {
name: hostUser.username,
Expand Down
7 changes: 6 additions & 1 deletion packages/env/lib/init-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -207,8 +207,13 @@ RUN echo "$HOST_USERNAME ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers`;
}
case 'cli': {
dockerFileContent += `
# Make sure we're working with the latest packages.
RUN apk update

# Install some basic PHP dependencies.
RUN apk --no-cache add $PHPIZE_DEPS && touch /usr/local/etc/php/php.ini

# Set up sudo so they can have root access.
RUN apk --no-cache add sudo linux-headers
RUN echo "$HOST_USERNAME ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers`;
break;
Expand Down Expand Up @@ -238,7 +243,7 @@ RUN rm /tmp/composer-setup.php`;
// Install any Composer packages we might need globally.
// Make sure to do this as the user and ensure the binaries are available in the $PATH.
dockerFileContent += `
USER $HOST_USERNAME
USER $HOST_UID:$HOST_GID
ENV PATH="\${PATH}:/home/$HOST_USERNAME/.composer/vendor/bin"
RUN composer global require --dev yoast/phpunit-polyfills:"^1.0"
USER root`;
Expand Down