-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Allow Symfony 4.0 in composer.json #1420
Conversation
Does symfony 4.0 introduce BC? |
It theoretically could. All BC are first introduced as deprecations in the previous versions (e.g. 3.*). If deployer does not raise any deprecation notice with the 3.4 symfony components, it should be ok. |
Okay, will release new major v7 and will merge it there — more save approach. |
"symfony/finder": "~2.7|~3.0", | ||
"symfony/process": "~2.7|~3.0", | ||
"symfony/yaml": "~2.7|~3.0" | ||
"symfony/console": "~2.7 || ~3.0 || ~4.0", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Version specification is wrong.
x "~2.7 || ~3.0 || ~4.0"
o "~2.7|~3.0|~4.0"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
both are correct and work.
Besides these obvious changes, please also consider the few rather subtle changes that come with Symfony 4:
|
@tehplague can you be more specified on this one. Maybe you can show some examples? |
Sure. Well, my current implementation is rather "hacky" but works very well. It also provides support for Webpack Encore in the projects. We have inventory entries of the following form: .base: &base
repository: 'git@gitlab.com:some/project.git'
identity_file: identityFile
forwardAgent: true
bin/php: /usr/bin/php7.1
staging:
<<: *base
hostname: some.host.name
user: someuser
deploy_path: /path/to/application
http_group: somegroup
stage: staging
env_cmdline: 'source /etc/someapp/app_profile &&' and have the following Deployer configuration: <?php
use function Deployer\{
commandExist, server, task, run, runLocally, set, get, add, before, after, inventory, input, upload
};
use Symfony\Component\Yaml\Yaml;
require 'recipe/symfony3.php';
// Servers
inventory('build/build.properties.yml');
// Used to replace lots of set() invocations
task('load:config', function () {
$input = input();
$stage = $input->hasArgument('stage') ? $input->getArgument('stage') : -1;
// Configuration
$settingsContent = Yaml::parse(file_get_contents('build/settings.yml'));
$settings = isset($settingsContent[$stage]) ? $settingsContent[$stage] : $settingsContent['.base'];
foreach ($settings as $key => $config) {
set($key, $config);
}
})->desc('Load settings.yml');
// Make sure that settings are loaded
before('deploy', 'load:config');
task('deploy:vendors', function () {
if (!commandExist('unzip')) {
writeln('<comment>To speed up composer installation setup "unzip" command with PHP zip extension https://goo.gl/sxzFcD</comment>');
}
run('cd {{release_path}} && {{env_cmdline}} {{bin/composer}} {{composer_options}}');
});
task('frontend:build', function () {
runLocally('yarn install');
runLocally('yarn run build');
runLocally('rsync -azP public/dist {{user}}@{{hostname}}:{{release_path}}/public');
})
->desc('Build frontend assets');
task('fpm:restart', function() {
run('sudo service php7.2-fpm reload');
});
/**
* Clear Cache
*/
task('deploy:cache:clear', function () {
run('{{env_cmdline}} {{bin/php}} {{bin/console}} cache:clear {{console_options}} --no-warmup');
})->desc('Clear cache');
/**
* Warm up cache
*/
task('deploy:cache:warmup', function () {
run('{{env_cmdline}} {{bin/php}} {{bin/console}} cache:warmup {{console_options}}');
})->desc('Warm up cache');
/**
* Migrate database
*/
task('database:migrate', function () {
run('{{env_cmdline}} {{bin/php}} {{bin/console}} doctrine:migrations:migrate {{console_options}} --allow-no-migration');
})->desc('Migrate database');
/**
* Main task
*/
task('deploy', [
'deploy:info',
'deploy:prepare',
'deploy:release',
'deploy:update_code',
'deploy:clear_paths',
'deploy:create_cache_dir',
'deploy:shared',
'deploy:vendors',
'frontend:build',
'deploy:cache:clear',
'deploy:cache:warmup',
'database:migrate',
'deploy:symlink',
'fpm:restart',
'cleanup',
])->desc('Deploy application'); |
So you need something to configure params per stage? Like this: stage('production', function () {
set('key', 'value');
// ...
inventory('deploy/production.yml');
}); |
No, this is already handled by our settings.yml which allows per-stage configurations. We needed to be able to prepend some command to both Composer and the Symfony CLI which is why I needed to override all the tasks. |
Another possibility would be a sane approach to load a user profile on the destination host which would need the inventory and the SSH client interface to be extended. This would enable other features such as setting umask limits, etc. during deployments. |
@antonmedv To be clear: Symfony moved towards an environment-based configuration since 3.3. They have dropped the parameters.yml file in favor of several environment variables. In development environment, you put all of them in an local .env file and Symfony will automatically load them for convenience. But when it comes to production servers, you have to define these variables before executing any composer or console command. (I do not want to discuss whether this design choice is good or not, I just describe it). Hence we need a way to easily define a lot of environment variables before executing every local or remote command. The first that come in mind is the "source" shell built-in. (And more generally a way to prepend some string before every single command would be welcome, IMO) |
Now you can do it only for env vars. Let's think of how we can create more robust deployment script for symfony. So symfony requires a lot of environment params? Why not to create .env on server too? |
I'm not absolutely sure about the rationale behind not recommending Dotenv for production (which is officially discouraged: http://symfony.com/doc/current/components/dotenv.html). It might be due to performance considerations (manually parsing the env file on each request/invocation is slower than taking them directly from the process environment). Nevertheless, the Dotenv component is generally unavailable on production since it is installed as a dev dependency by default. So do not expect many projects to have it available for that purpose. |
Any sensitive (like passwords) or platform specific parameters usually go there. |
What about creating
|
It is created automatically with Hint: If APP_ENV env var exists symfony does not load |
@zorn-v I still don't consider moving DotEnv to |
So now Deployer has |
@tehplague I did not say that my solution is right. I just do it coz it was convenient for me (using DotEnv in prod instead of duplicate all vars in webserver and console). |
@antonmedv I imagine something like this: # Load environment variable from '/path/to/.env/file'
set('symfony_env_file', '/path/to/.env/file'); Resulting in prepending I cannot remember if |
@Adirelle: |
It's okay - deployer posix dependent. |
@antonmedv I think |
Deployer supports windows only as client machine, not target. |
When will this get merged? I guess after this It'll be worth having a symfony 4 recipe. |
I'll ty it figure out what's best to do really soon :) |
Already doing. |
What's the current state of this pull request? I would love to use deployer with my new Symfony 4 application. Can I support in something? |
We need this PR because you can't install deployer as a composer dependency in Laravel 5.6 because it uses symfony/console 4.0.4 and deployer wants 3.4.4 which is not satisfiable... |
I ended up installing the Deployed phar from deployer.org to avoid any conflict. Unfortunately, the provided SHA1 cannot be easily extracted, which prevents automated secure installation. It would be nice to have Deployer available through something like https://phar.io/ (But maybe it is another issue.) |
@Adirelle Def a work around for now! thnx for pointing out phar.io. Will submit a issue for getting on phar easily. |
See https://deployer.org/manifest.json for sha hashes |
Closing this issue (#1559 was merged). |
#SymfonyConHackday2017