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

adds devcontainer to install command #203

Merged
merged 2 commits into from
Jul 29, 2021

Conversation

videlalvaro
Copy link
Contributor

I'm working with the VS Code & GitHub teams and we like to propose the following idea.

When working in projects that have a complex infrastructure - say a MySQL backend, with Redis for caching - it's hard to get the project started due to infrastructure setup. Thanks to Sail, Laravel addresses most of those problems, making it easy to start new projects. We want to improve that experience even further by enabling the current project setup to “just work” in VS Code.

Imagine opening a folder with a Laravel project and the editor takes care of setting up the environment automatically for the user. Not only on the infrastructure level, but also installing the required editor extensions so the developer can start hacking right away.

By adding a .devcontainer/devcontainer.json file to a project VS Code will detect that the project can be opened inside a container and do all the heavy lifting for the user.

A more detailed description of this feature can be found here: laravel/ideas#2660

Here's the .devcontainer.json documentation https://code.visualstudio.com/docs/remote/devcontainerjson-reference

Since Sail already does most of the heavy lifting for a user when it comes to containers, adding a .devcontainer.json to a project is the natural next step. This would allow VS Code to fire up the containers after prompting the user for confirmation. Once the user has told VS Code to start the containers, VS Code will use the docker-compose generated by Sail to start those containers, and connect remotely to them, so the user has a development environment that's ready to work in the containers.

Besides the container side of the PR, it also suggests a list of Laravel extensions for VS Code, in order to provide a sort of standardized dev environment for Laravel developers. Of course the list suggested here can be improved.

Caveat

For this to work auto-magically with VS Code the .env file requires the following variables to be set:

Also based on the installed services we could specify a list of ports to be forwarded to the user computer.

WWWGROUP=1000
WWWUSER=1000

If the team thinks it's OK to add that to the .env file then I could update the PR accordingly.

@finagin
Copy link
Contributor

finagin commented Jul 28, 2021

@videlalvaro, I don't use VS Code and I don't need extra files in my project. Make it an option. I can do PR if you have problems with it.

@taylorotwell taylorotwell merged commit 30896b5 into laravel:master Jul 29, 2021
@taylorotwell
Copy link
Member

Converted to option. Thanks!

@videlalvaro
Copy link
Contributor Author

Awesome @taylorotwell thanks!

Do you think there's room for documentation perhaps on the Sail site? I could help write those.

@taylorotwell
Copy link
Member

@videlalvaro sure!

driesvints pushed a commit that referenced this pull request Aug 17, 2021
* adds devcontainer to install command

* formatting

Co-authored-by: Taylor Otwell <taylorotwell@gmail.com>
taylorotwell added a commit that referenced this pull request Aug 17, 2021
* adds devcontainer to install command (#203)

* adds devcontainer to install command

* formatting

Co-authored-by: Taylor Otwell <taylorotwell@gmail.com>

* add env options

Co-authored-by: Alvaro Videla <videlalvaro@gmail.com>
Co-authored-by: Taylor Otwell <taylorotwell@gmail.com>
@videlalvaro
Copy link
Contributor Author

videlalvaro commented Sep 22, 2021

@taylorotwell

I'm trying to see what is the best place to update the docs.

What would be the best way to have this https://laravel.com/docs/8.x/installation#choosing-your-sail-services support the devcontainer installation?

I tried something like the following URL curl -s "https://laravel.build/st?with=mysql,redis&devcontainer" trying to pass the --devcontainer option, but that didn't work. I'd assume the URL parameters aren't being expanded on laravel.build

Any suggestions?

Should this be documented in the Sail side of things?

@driesvints
Copy link
Member

@videlalvaro probably on the Sail docs specifically.

I tried something like the following URL curl -s "https://laravel.build/st?with=mysql,redis&devcontainer" trying to pass the --devcontainer option, but that didn't work. I'd assume the URL parameters aren't being expanded on laravel.build

I think this indeed is because the sail server code still needs to be updated. I have it on my list to look into this at some point and get a fully working VS Code setup. But it might be a while before I get to that.

I'm btw in the GitHub Stars channel on the GitHub partners slack if you want to hmu on this :)

@xanderificnl
Copy link

xanderificnl commented Sep 30, 2021

In the meantime, it is possible to misuse the with parameter like so:

curl -s https://laravel.build/app-name?with=mysql,redis,meilisearch,mailhog,selenium%20--devcontainer | bash

Also, if someone can point me to the laravel.build source code, I could add the option for the devcontainer.

@driesvints
Copy link
Member

@xanderificnl it's closed source

@xanderificnl
Copy link

Is there a reason for it being closed source? i.e. does it do more than just spit out a bash script?

@driesvints
Copy link
Member

We just don't want that one publicly for now, sorry.

@videlalvaro
Copy link
Contributor Author

@driesvints hey, we would like to perhaps create a laravel/devcontainer tutorial. Do you think the server code could be updated so something like this would work officially? #203 (comment)

@burkeholland
Copy link

We really like this setup and would love to promote Laravel with VS Code. If we could get this added to the server code, we could get rolling on our side with some content on Laravel and VS Code.

@driesvints
Copy link
Member

I'm sorry @videlalvaro @burkeholland, I totally lost track of @videlalvaro's question. We've recently open sourced the app that runs the Sail install process. Take a look at https://github.com/laravel/sail-server, feel free to make a PR and we'll have a look 👍

@xanderificnl
Copy link

It works: https://laravel.build/test?devcontainer -- enjoy!

@videlalvaro
Copy link
Contributor Author

videlalvaro commented Nov 18, 2021

EDIT: nevermind, I see it's here in the code already https://github.com/videlalvaro/sail-server/blob/master/routes/web.php#L25

@driesvints is the solution proposed by @xanderificnl above officially supported?

This: https://laravel.build/test?devcontainer

If yes, I could send a PR documenting that, and also we could start building some video demos with this.

@driesvints
Copy link
Member

Yes we deployed that 👍

You can also use the parameter with a default value if that's more clearer to users: https://laravel.build/test?devcontainer=true

@videlalvaro
Copy link
Contributor Author

Yeah I just saw that in the code https://github.com/videlalvaro/sail-server/blob/master/routes/web.php#L25

Awesome!

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.

6 participants