Varying-Vagrant-Vagrants / VVV

An open source Vagrant configuration for developing with WordPress
https://varyingvagrantvagrants.org
MIT License
4.54k stars 848 forks source link

Dashboard Add New Site #1262

Open tomjn opened 7 years ago

tomjn commented 7 years ago

It should be possible to add a new site using the standard VVV site template from the dashboard

I envision this as being a button under the list of sites that triggers a form. On submission, it modifies vvv-custom.yml then directs the user to re-provision so that changes take effect

borjalofe commented 7 years ago

This would be a great idea. I was thinking of doing it a bit (a lot) more complicated. Meaning, I'd create the site with WP-CLI and then try to update vvv-custom.yml through some kind of action/trigger related to vagrant halt.

If you can Add a New Site this way, could you Remove a Site the same way?

tomjn commented 7 years ago

By WP CLI do you mean you'd be provisioning the site manually from WP CLI then reprovisioning so it went live? Simply modifying vvv-custom.yml will trigger a provisioner if the custom site template is used on reprovision. PHP has access to vvv-custom.yml via /vagrant/vvv-custom.yml inside the VM so a YAML PHP library should be enough.

Removal should also work, though I prefer disabling, via skip_provisioning: true as we can't delete the folder and database via PHP without complicating things or running into edge cases

borjalofe commented 7 years ago

I didn't know I have access to vvv-custom.yml from the VM. That makes things a lot easier.

I was thinking about provisioning through a script with WP CLI and then update vvv-custom.yml somehow without reprovisioning. As I say, your way is a lot easier and a lot less messy.

Disabling is also a good option but if you list all the sites you have by reading vvv-custom.yml it would be great to have them filtered or marked somehow.

tomjn commented 7 years ago

There was some discussion about YAML parsers and commenting, and all the comments in vvv-custom.yml being removed when saving. While I think about it some more, an intermediary step is to have the dashboard give you YAML to copy paste after asking questions

To that end, I've added a section in #1280 that helps with this before any kind of UI is added:

screen shot 2017-09-14 at 09 28 38
dseidl commented 6 years ago

we've done something similiar. here is the link to the repo: https://github.com/towa-digital/towa-cli it's installable via composer require towa/towa-cli.

Features:

dingo-d commented 6 years ago

I am working on a project where I need to parse yaml to json, and for yaml I think you would need http://pecl.php.net/ library. This could be added by default in the vvv. The alternative is this: https://github.com/mustangostang/spyc. I still need to create a provision script that I can use as utility for my local development (pecl utility).

But couldn't adding a custom site be achieved with a bash script? What comes to mind is:

dseidl commented 6 years ago

@dingo-d see my link above (https://github.com/towa-digital/towa-cli)

except we update the vvv-config file (will change that soon) and we dont create the vvv-init and vvv-nginx on the fly (because we have them in our boilerplate setup repo) all your conditions are done.

vvv-custom.yml and on the fly init.sh and nginx.conf are planned soon.

tomjn commented 6 years ago

I'd note a few things:

delete a site (includes cleaning up db, nginx config, and yml config file, aswell the files)

Deleting the site folder and removing it from vvv-custom.yml should do all of this, only the DB should need specific cleanup. I would strongly recommend against manually moving nginx configs into place inside the VM. vv did the same thing, and it wasn't necessary. When VVV 2 came out, it became a problem, leading to pain for users. All that's needed is vagrant provision which will copy everything into place properly and do all the needed cleanup

I also see that towa-cli uses symfony/yaml, I considered using that but was apprehensive about scaling up the dashboard with a composer and vendor folder so quickly, so I used a simpler PHP library

I am working on a project where I need to parse yaml to json, and for yaml I think you would need http://pecl.php.net/ library. This could be added by default in the vvv. The alternative is this: https://github.com/mustangostang/spyc. I still need to create a provision script that I can use as utility for my local development (pecl utility).

It isn't, the dashboard currently uses a library to read YAML in:

www/default/dashboard/php/yaml.php

But if you really needed it, you can do that via a utility

But couldn't adding a custom site be achieved with a bash script? What comes to mind is:

  • user has to input data in the input fields in the dashboard
  • this data is used by the bash script that does the following:
  • see if vvv-custom.yml exists
    • if it does locate the line before utilities and append the new site with the prefilled data using find and sed
    • if it doesn't, just copy the vvv-config.yml and again append the new site like above
  • create necessary folders and provision scripts in it (vvv-init.sh and vvv-nginx.conf with the data from the input fields)
  • reprovision vagrant

So I see most users wanting to run this on the host machine, however, the vast majority of this is unnecessary:

By creating the provision folder manually, and hardcoding the nginx config and provisioning script, you're limiting flexibility. Instead a custom site template would be significantly better. This way the provisioner script can read values from vvv-custom.yml via the bash functions VVV provides to do different things. There's no need to have a dedicated tool in bash to generate the provision folder, and I'd advise against it.

For example, would it not be easier to type:

  dingo:
    repo: github.com/dingo/custom-vvv-site.git
    hosts:
      - dingo.test
    plugins:
      - yoast
      - github.com/dingo/test-plugin.git
    themes:
      - etc...

Then have vvv-init.sh check those and pass the values to WP CLI? This also means that:

I understand the vv cli based workflow is handy, but the config workflow is much easier. I also see the benefit of a CLI command, but it really needn't be as complicated as people think it should. Ask some questions, generate a YAML snippet and insert it into vvv-custom.yml using sed by inserting it on a new line after sites: then vagrant provision

except we update the vvv-config file (will change that soon) and we dont create the vvv-init and vvv-nginx on the fly (because we have them in our boilerplate setup repo) all your conditions are done.

Yay for configurable boilerplate, site templates are the future

vvv-custom.yml and on the fly init.sh and nginx.conf are planned soon.

:(

dingo-d commented 6 years ago

It isn't, the dashboard currently uses a library to read YAML in:

www/default/dashboard/php/yaml.php

This is some kind of a fork of a spyc library?

I'm all for site configs, wasn't aware of all the stuff that will happen automatically with provisioning. Would site configs be a separate yaml files or should they need to be added to the vvv-custom.yml file?

tomjn commented 6 years ago

I'm all for site configs, wasn't aware of all the stuff that will happen automatically with provisioning. Would site configs be a separate yaml files or should they need to be added to the vvv-custom.yml file?

vvv-custom.yml is the only YAML file, if it isn't in that file VVV doesn't know about it. But specifically, VVV uses that file to provision the sites, it's notjust a means of telling VVV what already exists.

You can create a site manually via a folder with a provision subfolder, but the golden path is to create a site template via a git repository that already contains those provisioner files, then configure it using the options in vvv-custom.yml. The ability to load a manually created folder is mostly for VVV 1 backwards compatibility, though the end result is always the same, you might as well save yourself the effort

As a refresher, the VVV mental model:

msaggiorato commented 4 years ago

There's a partial implementation of this here Varying-Vagrant-Vagrants/dashboard#1. Should we have this developed there?

tomjn commented 4 years ago

That's the PR for this issue, it's a WIP though, lots more to do