Does anyone know if it is possible and, if so, how to use a symlink to share a module or theme between two different ddev projects?

The problem I am trying to solve is that I am working on a contributed theme. I would like to make css changes to the theme and see how they effect two or more different sites with different content and different configuration. 

I suppose my other option is to simply copy the changes from one project to another each time I make changes.

Comments

I don't use DDev, but Lando, but I think the approach is fairly similar. When you are using the website within the container then the file root is /app/ (may be different in DDev) so you wouldn't be able to go outside that.

I've never tried, but that is my understanding, limited as it is.

Different DDEV projects can communicate with each other. Here is a little information on that:

https://ddev.readthedocs.io/en/stable/users/usage/faq/#can-different-projects-communicate-with-each-other

But, I think that @yorkshirepudding might be correct, that linking via symlink may not be possible.  I understand the reasons why it would be difficult, but it's not clear to me that there isn't anyway to build some kind of virtual bridge between projects. 

jenlampton's picture

I was able to get this working today. It only took two changes.

Here's my setup and use case:

Git clones of the contributed projects I have ever worked on live on my computer (MacOS) at ~/_backdrop/_contributions. When I am working on one of these modules from an active development site, I remove the module from that site's codebase, and replace it with a symlink to the git clone of contrib:

rm -r metatag
ln -s ~/_backdrop/_contributions/metatag

Then I do all the work for metatag on the site where I had the problem or want the feature, until I'm done. At this point I have a patch/PR (or new release) for the module. So I restore the previous module to the site, apply the patch (or update to the lates version), and commit the change.

rm metatag
git checkout metatag
patch -p1 metatag < diff.patch
git add ../PATCHES.txt metatag
git commit -m "Applied metatag patch and documented patched module."

I love this workflow as it allows me to keep my project work from my community work, but still bring the two together when needed (without needing to remember to copy files from place to place) In this case, my contributed projects ~/_backdrop/_contributions are never going to be "inside" a ddev project, but they can be available to all of them.

1 Add a post-start hook to create an identical path inside ddev as outside.

On ddev my first directory is /home and on MacOS it was /Users. After that, the paths are identical.

hooks:
  post-start:
    - exec: sudo ln -s /home /Users;

2 mount the contributed directory as a volume inside Docker:

I created a new file named docker-compose.mounts.yaml and added the following

services:
  web:
    volumes:
    - "$HOME/_backdrop/_contributions:/Users/jenlampton/_backdrop/_contributions"

Then I did a ddev restart and now I can add a symlink on my workstation that is copied via mutagen into docker, and it still works!

To test that you got the paths right, change into the destination directory in terminal cd /Users/jlampton/_backdrop/_contributions and make sure you are in the right place. Then use the exact same command on the ddev container and make sure you can see the same files: cd /Users/jlampton/_backdrop/_contributions.

If so, profit.