Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a WP-CLI alias #221

Closed
13 tasks done
johnbillion opened this issue Oct 5, 2020 · 14 comments · Fixed by #775
Closed
13 tasks done

Add a WP-CLI alias #221

johnbillion opened this issue Oct 5, 2020 · 14 comments · Fixed by #775
Assignees
Labels
could have Could be done, or nice to have, low priority for now developer advocacy Developer Advocacy related tasks
Milestone

Comments

@johnbillion
Copy link
Member

johnbillion commented Oct 5, 2020

Running a WP-CLI command on default Altis local server requires the following:

composer server cli -- [command]

This works fine but is a non-standard way of interfacing with WP-CLI. If your project is already set up you can instead add an alias:

touch wp-cli.yml && wp cli alias add @local --set-ssh=docker:www-data@xxx --config=project

where xxx is the name of the PHP container, eg. foo_php_1.

This allows you to subsequently run:

wp @local [command]

The advantage this has is that tab completion works and it's a more familiar, shorter, and memorable interface to WP-CLI.

Is it possible for Altis local server to provide a default alias that is aware of the PHP container name?


Acceptance Criteria

  • Add composer server create-alias command
  • Check for and handle an existing file
  • Output instructions/help
  • Add documentation

For Altis Team Use

Ready for Work Checklist

Is this ticket ready to be worked on? See
the Play Book Definition of Ready

  • Is the title clear?
  • Is the description clear and detailed enough?
  • Are acceptance criteria listed?
  • Have any dependencies been identified? (Optional)
  • Have any documentation/playbook changes been identified? (Optional)
  • Is an estimate or time box assigned?
  • Is a priority label assigned?
  • Is this ticket added to a milestone?
  • Is this ticket added to an epic? (Optional)
@johnbillion
Copy link
Member Author

It should also be possible to not use an alias, and put the ssh: config into a wp-cli.yml file in the root of the project, but there appears to be a bug in WP-CLI when using the docker scheme that I've not looked into yet.

@johnbillion
Copy link
Member Author

wp-cli/wp-cli#5447

@roborourke
Copy link
Contributor

I did experiment briefly with this as part of #224 regarding pipe detection. This approach requires WP CLI to be installed on the host machine though, not everyone has that. We could only ensure it by adding it as a dependency of local server and aliasing something like composer exec wp. The docker-compose scheme worked fine for me in testing but I hadn't tried that many different commands yet.

@johnbillion
Copy link
Member Author

johnbillion commented Oct 28, 2020

I don't think this relates to pipe detection etc, rather this is a bonus for anyone who does have WP-CLI installed locally. The wp-cli.yml file in the project root will get picked up when the user uses a wp command.

My thinking is that as part of the installation step of an Altis project the alias gets added with the name of the PHP container.

@roborourke
Copy link
Contributor

Fair. I guess it wouldn't be too hard to document that difference. Projects would potentially need to .gitignore the wp-cli.yml file though as it would screw up in production.

If you want to keep playing in the meantime use docker-compose:php for your SSH setting.

@johnbillion
Copy link
Member Author

Does Altis Cloud put a wp-cli.yml file into place on the prod server?

@johnbillion
Copy link
Member Author

johnbillion commented Oct 28, 2020

By the way WP-CLI supports a hierarchy for these config files so it could be wp-cli.local.yml instead: https://make.wordpress.org/cli/handbook/references/config/#config-files

@roborourke
Copy link
Contributor

No there's no generated wp-cli.yml in the cloud - it would still need to be git ignored. This could perhaps be done using a CLI command though eg. composer server create-wp-cli-yml that then prompts / recommends git ignoring it.

@johnbillion
Copy link
Member Author

In that case if we only introduce an alias into wp-cli.yml then we don't need to ensure it gets ignored by git because it won't affect production unless somebody explicitly tries to run that alias while SSHd into a production server, in which case they'll just get a connection error.

Prompting to ignore the file might be a good idea, but there might also be a benefit to committing this file so all developers have access to this alias. It would need setting up once. Maybe this means it would be better off as a Composer command such as composer server create-alias.

@johnbillion
Copy link
Member Author

I might have a play around with this as a learning exercise for myself. Not done anything with Composer plugins yet.

@johnbillion johnbillion self-assigned this Oct 28, 2020
@roborourke
Copy link
Contributor

Awesome, have at it!

Agree on your proposed name for the command. I think the output from the command should indicate how you would then use it eg:

Generating wp-cli.yml...
Done!

You can now run WP CLI commands using the following syntax:
wp @local cli info

Other nice thing it could do is check for WP CLI being installed on the host, and if not provide installation instructions or link to the WP CLi install docs

  • I personally do this using composer global require wp-cli/wp-cli-bundle
  • brew install wp-cli also an easier option but should only be mentioned if user is on a mac

@rmccue
Copy link
Member

rmccue commented Sep 2, 2023

Dug into this, and it's definitely possible; given the docker-compose container names are predictable, you can use them directly in docker-compose: config:

@local
    ssh: docker-compose:my-project-php

(These options aren't properly documented; opened wp-cli/handbook#462 for that.)

Due to wp-cli/wp-cli#5447 (comment) we can't specify a default alias, although we could support eg wp @local ... for example. We probably also don't want to specify this by default, as it'd break running wp-cli on the actual servers.

@missjwo missjwo added the developer advocacy Developer Advocacy related tasks label Dec 10, 2024
@johnbillion johnbillion removed their assignment Jan 13, 2025
@mikelittle mikelittle self-assigned this Jan 15, 2025
@mikelittle
Copy link
Contributor

I misread this ticket (I thought it was about an alias to the composer server cli command so that composer server wp would also work) and my 1 estimate was too low. I think it will be a 3.

@mikelittle mikelittle added this to the Altis v22 milestone Jan 21, 2025
@mikelittle mikelittle added the could have Could be done, or nice to have, low priority for now label Jan 21, 2025
@mikelittle
Copy link
Contributor

I tested it with

  • no existing file
  • and existing file without an @Local alias
  • and one with an @Local alias

The resultant file looks like this

@local:
  ssh: docker:www-data@altis-dev-php
  url: https://altis-dev.altis.dev/

I tested it with a number of commands

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
could have Could be done, or nice to have, low priority for now developer advocacy Developer Advocacy related tasks
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants