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

import() can now load URLs and recipes from third party and private composer repositories #3477

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

marvinhinz
Copy link
Contributor

@marvinhinz marvinhinz commented Feb 2, 2023

This is a quick proof of concept for this discussion/idea: #3475

It extends the existing include() function, so that URLs can be included in the deploy.php file. Also files from composer repositories can be included too. The included packages will be loaded automatically by creating a composer.json or adding them to an existing one.

Example usage in deploy.php with urls:

<?php
namespace Deployer;
import("https://pastebin.com/raw/bUpKm80E");
task("deploy", function() {
    writeln("deploy!");
    invoke("test");
});
localhost();

Output of dep deploy:

mhinz@dev:/srv/htdocs/deployer$ bin/dep deploy
 Do you really want to trust this remote recipe: https://pastebin.com/raw/bUpKm80E? (yes/no) [yes]:
 > y
task deploy
[localhost] deploy!
task test
[localhost] test!

Example usage in deploy.php with private composer repo:

<?php
namespace Deployer;
import("recipe/test.php", "some/custommodule:dev-master", "https://composer.example.org");
task("deploy", function() {
    writeln("deploy!");
    invoke("test");
});
localhost();

Output of dep deploy:

mhinz@dev:/srv/htdocs/deployer$ bin/dep deploy
 Do you really want to trust this remote recipe: recipe/test.php? (yes/no) [yes]:
 > y
task deploy
[localhost] deploy!
task test
[localhost] test!

This is especially useful when running a lot of projects with similar custom recipes (e.g. in agencies). The automated composer require is probably not really needed, as we could just throw an exception for missing composer packages. But i thought its a bit nicer for the dev experience.

There is still a lot of room for improvement, for example: the deploy.php configuration is loaded before the main symfony console application is running, this results in various little problems (to ask a user an interactive question, a command has to be run manually. Deployer::isWorker() always returns false, because the value is set too late (when the worker command is executed).

Should the user even be asked for confirmation? In theory it is a risk, but in comparison running the usual wget URL | bash commands are risky too.

  • Bug fix #…?
  • New feature?
  • BC breaks?
  • Tests added?
  • Docs added?

@antonmedv
Copy link
Member

Can we add some tests? Something like e2e?

@Schrank
Copy link
Contributor

Schrank commented Feb 2, 2023

We can add a test, which loads a file from this composer repository :-)

@marvinhinz
Copy link
Contributor Author

marvinhinz commented Feb 2, 2023

Sure will do :)

@antonmedv
Copy link
Member

And update to the documentation ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants