elementor / lokl-cli

Interactive script to launch and manage your Lokl sites
The Unlicense
66 stars 7 forks source link

Add the option for mounting volumes #21

Closed IlanVivanco closed 3 years ago

IlanVivanco commented 3 years ago

It'll be ideal to be able to mount volumes to an instance for developing themes/plugins locally.

There is no option on the CLI yet, but I was able to do it manually using the Lokl image.

docker run -v /home/ilan/code/my-plugin:/usr/html/wp-content/plugins/my-plugin -e N="plugin-in-dev" -e P="5555" --name=plugin-in-dev -p 5555:5555 -d lokl/lokl:php7-5.0.0-rc1
leonstafford commented 3 years ago

Thanks for checking out the project, @IlanVivanco! And, for sharing this method for mounting!

Do you encounter any issues with file permissions using this, ie if you edit, does it keep the root:root ownership within the container's files? If you do some editing of those mounted files from within the container, will that set incorrect permissions on the host?

I imagine this will work fine across all platforms, as Windows users seem to use Docker in a way that uses unix-style filepaths, but I'm not 100% sure on that.

I'd like not to force share any access to host's files by default, but can see this being an big need for anyone doing plugin/theme development, like you (and me, but I don't do any syncing as yet, I can get away with small edits with Vim within the container, but would definitely use a mounting option if available!). There is an issue/feature request to add a browser-based code editor, which will be nice for some users, but in your case, you may want to sync same dir to say a PHP7 and PHP8 container or a whole bunch of containers with different WP configs simultaneously.

A few ideas of approach:

Not exclusive options, I still want Lokl to be as simple as possible for users who don't want to touch any code/config files.

Note, please be aware of a pretty severe issue (with workaround) reported in Lokl here that you may encounter soon.

IlanVivanco commented 3 years ago

Hey @leonstafford, I'm really sorry I missed this notification.

Do you encounter any issues with file permissions using this, ie if you edit, does it keep the root:root ownership within the container's files? If you do some editing of those mounted files from within the container, will that set incorrect permissions on the host?

I haven't had any issues so far.

I imagine this will work fine across all platforms, as Windows users seem to use Docker in a way that uses unix-style filepaths, but I'm not 100% sure on that.

That is correct, I'm using WSL2 and Docker for Windows. But the containers basically run on the Ubuntu 20.04 side. You can run Docker directly from Windows, but I have no experience with that I'm afraid.

I'd like not to force share any access to host's files by default, but can see this being an big need for anyone doing plugin/theme development, like you (and me, but I don't do any syncing as yet, I can get away with small edits with Vim within the container, but would definitely use a mounting option if available!). There is an issue/feature request to add a browser-based code editor, which will be nice for some users, but in your case, you may want to sync same dir to say a PHP7 and PHP8 container or a whole bunch of containers with different WP configs simultaneously.

I don't hate this idea, but that only would work for quick changes/tweaks. I don't think it'll be reliable for long-term development.

Last, but not least, the idea of a templating system seems like a good approach to me.

leonstafford commented 3 years ago

Hola @IlanVivanco~ No worries re timing - I miss/delay a lot of comms.

Great feedback and templating seems certainty to get built in! If you have time/interest, I'm happy to let you build it - my main constraint I'd like to keep is no requirement to do anything else on the host system, so if it can allow current workflow to continue for other users, but provide that great functionality for others, that would be awesome!).

Doesn't have to do all the magic for first iteration, just allowing to mount volumes if template is detected (maybe global vs site-specific rules in tpl?). Things like specifying ports, plugins, themes, integration with wizard, etc could be incremental improvements later).

Also, no pressure at all, I'm happy to work on this, just can't guarantee how soon I'll get to it. I can definitely help test/feedback.

IlanVivanco commented 3 years ago

Unfortunately, I don't have the time available now. But I'll be watching your progress and ping you if I manage to free my calendar.

leonstafford commented 3 years ago

@IlanVivanco, @mtplr, I aim to get at least a simple version of this functionality done quite soon, as I am in need of it myself for some projects. Will update when ready to test!

leonstafford commented 3 years ago

Thinking out loud...

In my case and for plugin/theme devs, they may want to spin up multiple sites with same development files mounted.

From Docker Volumes page:

If your container generates non-persistent state data, consider using a tmpfs mount to avoid storing the data anywhere permanently, and to increase the container’s performance by avoiding writing into the container’s writable layer.

This may be important consideration, as we're going to have a bunch of Composer or Node packages (re)generating on the host...

leonstafford commented 3 years ago

looked at a yaml parser for bash, but not POSIX friendly enough, so creating own simple templating system for now.

leonstafford commented 3 years ago

tmpfs mounting has limitations, limited to Linux, so will use regular volume mounts

leonstafford commented 3 years ago

making some progress:

Lokl Site Templates Found

Please choose one to use for this site:

1)  default
2)  php8-with-all-plugins-mounted
leonstafford commented 3 years ago

This is now working quite well for mounting volumes from a chosen template file.

Will sync with the leonstafford/lokl repo and release in version 5.0.0 soon.

leonstafford commented 3 years ago

This is released now in 5.0.0. Please give it a try and let me know any issues:

https://github.com/leonstafford/lokl-cli#site-templates