Best practice for Trellis with multiple sites

I’m creating a new Trellis project for my own website. In this project, I’d like to have the possibility of adding temporary staging environments for various bedrock-projects, as subdomains of my own domain. Thus, instead of the standard folder structure suggested in GitHub - roots/roots-example-project.com: Example Roots stack project (Trellis, Bedrock, Sage), mine will look something like this:

/
- ansible
- my-site
- client1-staging
- client2-staging

and so on.

Quiestion 1
In my group_vars, should I define subtree for each of the wordpress_sites as “my-site”, “client1-staging”, and so on, i.e. the name of the folder containing the bedrock installation of each site?

    wordpress_sites:
      my-site:
        site_hosts:
          - staging.mysite.com
        local_path: '../my-site' # path targeting local Bedrock site directory (relative to Ansible root)
        repo: git@bitbucket.org:user/my-site.git
        subtree: my-site
        [...]

      client1:
        site_hosts:
          - client1-staging.mysite.com
        local_path: '../client1-staging' # path targeting local Bedrock site directory (relative to Ansible root)
        repo: git@bitbucket.org:user/client-1.git
        subtree: client1-staging
        [...]

Question 2
Ideally, I’d like to track these projects as separate git repositories, with their own respective upstreams, i.e. the trellis repo for the ansible folder, bedrock for each of the sites and sage for the theme of each site. How would I go about doing this? I’ve initialized my own repos for each of the bedrock sites already, as this is necessary for the ansible deploys to work. But this leaves the ansible folder untracked. Should I set up another repo in the project root with everything other than /ansible in .gitignore (i.e all of the sites and .vagrant)?

Question 3
Each time I add another temporary staging site for a client by cloning bedrock, I’d have to re-provision my vagrant box, correct? Is there a way of adding a site to the box without deleting the data of existing sites?

2 Likes

Reg. Q1: Looking at main.yml, I guess subtree should be set, otherwise paths won’t be correct?

Reg. Q2: Found a couple of other posts regarding the same topic, i.e. this one where @Ivan_Svaljek and a couple of other people seems to have had the same setup - @evanfuture for example. How did you handle version control on your setups?

Reg. Q3: Based on this thread by @luqo33, @swalkinshaw suggests running vagrant reload after adding a new site. No data should be lost, right?

Q1: subtree is only needed if the root of a Git repo is not “Bedrock” itself". (ie: your git repo starts with subfolders like ansible and site). So for your initial setup, your subtrees are correct. Which leads to Q2

Q2: Each site should be its own repo and then create another repo for ansible too. So you’d have 4 repos going from your original example. Note that if you use repos for each site, you don’t need to set subtree anymore.

Q3: You’d need to run vagrant reload and probably vagrant provision too. This don’t destroy any existing data.

1 Like

Thanks, @swalkinshaw! Reg. Q2 – any thoughts on how to add multiple upstreams inside the repo of each site, i.e. one for bedrock and one for sage?

That’s not exactly possible since the upstreams just work on the root of the repo. Which obviously isn’t the correct path for Sage.

There’s a few workarounds that might be possible. Just search Stack Overflow and you’ll see a bunch.

1 Like

I have not repo for ansible yet. What is the sense of this repo? I mean, for what should I have it? Thank you!