roots / trellis-cli

A CLI to manage Trellis projects
https://roots.io/trellis/
MIT License
165 stars 25 forks source link

`trellis alias` generates wrong path for a site on Kinsta #446

Closed andronocean closed 1 month ago

andronocean commented 1 month ago

Version

1.11.1

What did you expect to happen?

This is a very minor bug, easy to correct manually. It seems to be happening because of differences between the file structure of a stock Trellis site vs a Kinsta environment, and Trellis's assumptions around the project_root variable.

What I expected: running trellis alias on a project with a staging environment on Kinsta should create the alias with a path: parameter like {{ project_root }} + /current/web/wp. It should use the custom {{ project_root }} I set in group_vars/staging/main.yml according to Kinsta's instructions for Bedrock & Trellis.

In other words, it should look something like this, for my project_root: /www/examplecom_123/public

# wp-cli.trellis-alias.yml

"@staging":
  path: "/www/examplecom_123/public/current/web/wp"

What actually happens?

The generated wp-cli.trellis-alias.yml inserts the site domain from the wordpress_sites.yml into the path:

"@staging":
  ssh: "examplecom@X.X.X.X:YYYYY"
  path: "/www/examplecom_123/public/example.com/current/web/wp"

Steps to reproduce

What my Trellis environment config looks like (actual sites anonymized):

# group_vars/staging/wordpress_sites.yml

# Created by trellis-cli v1.11.1
# Documentation: https://roots.io/trellis/docs/wordpress-sites/

wordpress_sites:
  example.com:
    site_hosts:
    - canonical: staging.example.com
    local_path: ../site
    repo: # redacted # 
    repo_subtree_path: site
    branch: main
    ...etc
# group_vars/staging/main.yml
# modified according to Kinsta instructions

mysql_root_password: "{{ vault_mysql_root_password }}" # Define this variable in group_vars/staging/vault.yml
project_root: /www/examplecom_123/public
www_root: /www/examplecom_123/public
web_user: examplecom
web_group: www-data

Note: trellis deploy works perfectly with this configuration — it's just the trellis alias command that generates the wrong WP CLI config. Manually correcting the path to /www/examplecom_123/public/current/web/wp fixes it and makes wp @staging somecommand work perfectly.

System info

Log output

No response

Please confirm this isn't a support request.

Yes

codepuncher commented 1 month ago

I have the same issue; have done for a while (I think since this commit).

$ trellis alias
$ <../bedrock/wp-cli.trellis-alias.yml
"@development":
  ssh: "example.test"
  path: "~/public/example/current/web/wp"
"@production":
  ssh: "example@0.0.0.0:1111"
  path: "~/public/example/current/web/wp"
"@staging":
  ssh: "example@0.0.0.0:2222"
  path: "~/public/example/current/web/wp"
$ grep '~/public'
group_vars/all/main.yml
www_root: ~/public
project_root: ~/public

each time i start a project i have to delete ~/ and /example/ to ensure the paths are public/current/web/wp

swalkinshaw commented 1 month ago

I don't entirely remember why that PR stopped using project_root, but I think the variable just didn't exist in that context so it was always defaulting to www_root + '/' + item.key ? I can take a look again