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

WSL Installation Upgrades and Documentation #1958

Merged
merged 4 commits into from
Apr 27, 2024

Conversation

karmendra
Copy link

  • bin/homestead
    • Registered WslApplyFolderMapping command
  • scripts\features\mariadb.sh
    • Stop the mysql service before uninstall and remove the installation tracking file.
  • scripts\features\mysql.sh
    • Create feature installation script for mysql.
  • scripts\features\postgresql.sh
    • Removed systemctl disable postgresq from the end to make sure it works after the feature install
  • src\WslApplyFeatures.php
    • Changed the command name from wsl:apply-features to wsl:features.
  • src\WslApplyFolderMapping.php
    • Added new command to do folder mapping
  • src\WslCreateDatabaseCommand.php
    • Changed the command name from wsl:create-databases to wsl:databases.
  • src\WslCreateSiteCommand.php
    • Changed the command name from wsl:create-sites to wsl:sites.
    • Remove nginx/sites-enabled/* as well while removing existing nginx sites.
    • Add cron job for laravel schedule:run if mentioned in yaml file.
  • wsl.md
    • Documentation for Installing Homestead on Windows subsystem for Linux

Karmendra Suthar added 2 commits March 1, 2024 16:23
- bin/homestead - Registered WslApplyFolderMapping command
- scripts\features\mariadb.sh - stop the mysql service before uninstall and remove the installation tracking file.
- scripts\features\mysql.sh - Create feature installation script for mysql.
- scripts\features\postgresql.sh - removed `systemctl disable postgresq` from the end to make sure it works after the feature install
- src\WslApplyFeatures.php - Changed the command name from wsl:apply-features to wsl:features.
- src\WslApplyFolderMapping.php - Added new command to do folder mapping
- src\WslCreateDatabaseCommand.php - Changed the command name from wsl:create-databases to wsl:databases.
- src\WslCreateSiteCommand.php - Changed the command name from wsl:create-sites to wsl:sites.
  - Remove nginx/sites-enabled/* as well while removing existing nginx sites.
  - Add cron job for laravel schedule:run if mentioned in yaml file.
- wsl.md - Documentation for Installing Homestead on Windows subsystem for Linux
@karmendra
Copy link
Author

@svpernova09 / @MichaelBelgium , I just fixed a typo that I found in wsl.md. This PR is ready to merge, let me know if there is anything else to be addressed.

@svpernova09, I have checked php8.3.sh, there are only two environment vars (WSL_USER_NAME and WSL_USER_GROUP) and these are populated from the files storing these values.

@MichaelBelgium
Copy link

Looks okay for me, I don't see the benefit of the wsl:folders command tho. But I see its perhaps required due the change from wsl_sites to sites, which means the separate mapping for wsl will be gone

So this change is from, eg,

wsl_sites:
  - map: homestead.test
    to: /mnt/c/Users/<user>/Documents/code/public

to

folders:
    - map: ~/code
      to: /mnt/c/Users/<user>/Documents/code

sites:
    - map: homestead.test
      to: /mnt/c/Users/<user>/Documents/code/public

If i'm correct, the command will loop through folders and create a symlink between ~/code and /mnt/c/Users//Documents/code

Although, if someone does the config from below, the symbolic link will be useless i think?

sites:
    - map: homestead.test
      to: /mnt/c/Users/<user>/Documents/code/public

in stead of

sites:
    - map: homestead.test
      to: ~/code/public

which is the symlink

Lastly the checks you did before in wsl init, those were good, i'd keep those

if [[ $EUID -ne 0 ]]; then
    echo "Error: This script must be run as root.">&2

    exit 1
fi

# ....

# Set default
if [ -z "${WSL_USER_NAME}" ]; then
    WSL_USER_NAME=vagrant
fi
if [ -z "${WSL_USER_GROUP}" ]; then
    WSL_USER_GROUP=vagrant
fi

# Validate user and group
if ! id "$WSL_USER_NAME" &>/dev/null; then
    echo "Error: User $WSL_USER_NAME does not exist.">&2

    exit 1
fi
if ! getent group "$WSL_USER_GROUP" &>/dev/null; then
    echo "Error: Group $WSL_USER_GROUP does not exist.">&2

    exit 1
fi
if ! groups "$WSL_USER_NAME" | grep -q "\b$WSL_USER_GROUP\b"; then
    echo "Error: User $WSL_USER_NAME is not a member of group $WSL_USER_GROUP.">&2

    exit 1
fi

@karmendra
Copy link
Author

My idea for wsl:folders was just to replicate the feature from vagrant.
But the problem with approach of code hosted in windows and linked in ubuntu is that it is really slow to render these webpages.

Website load much faster if the code is in Ubuntu's file system. Problem here is code would be lost if wsl is unregistered, unlike the previous approach.

I will work on wsl:backup command that can easily backup the sites and database in future.

Regarding the validations, I will go ahead and add those validations in wsl-init.

Thanks.

@svpernova09
Copy link
Contributor

Giving this a review now. Sorry for the delays. I found a bug in the MariaDB installer so far. Should be good to merge this soon.

@svpernova09
Copy link
Contributor

I think we want to keep the WSL config separate from the Homestead Configuration. I traditionally have a giant Homestead.yaml that gets configured and passed around various machines and configurations.

At some point this WSL stuff will need to get pulled out of Homestead because it's not really.... Homestead in the Vagrant sense.

@karmendra
Copy link
Author

Hi @MichaelBelgium

Lastly the checks you did before in wsl init, those were good, i'd keep those

I updated the wsl-init to add those checks.

P.S. Sorry for the delay, I was on long vacation.


To install a distribution, use the following command:
```powershell
> wsl --install Ubuntu-22.04
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be wsl --install -d Ubuntu-22.04 isn't it ?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sdespont What does the -d option do? I can't even find it in the docs

The docs say wsl --install <Distribution Name>

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The -d stands for "distribution", it permits to keep compatibility for older systems. Also, I am using Windows 23H2 but I need to specify the -d in the install command.
image

@MichaelBelgium
Copy link

Hi @MichaelBelgium

Lastly the checks you did before in wsl init, those were good, i'd keep those

I updated the wsl-init to add those checks.

@karmendra I don't see the checks in this PR?

@karmendra
Copy link
Author

@karmendra I don't see the checks in this PR?

Thanks @MichaelBelgium for checking this, I thought I have done the changes but looks like I have forgotten to push my changes.
image
I just pushed my changes, please have a look.

@svpernova09 svpernova09 merged commit 36bd28d into laravel:wsl-rework Apr 27, 2024
4 checks passed
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.

None yet

4 participants