deployer
deployer copied to clipboard
Temporary workaround in shopware recipe uses constant path
- Deployer version: 7.0.0-rc2
- Deployment OS: Ubuntu 20.04
The following line in the shopware recipe fixes absolute paths in theme config files. But the given absolute path can vary from deployment to deployment:
runLocally('sed -i "" -E \'s/\\\\\/var\\\\\/www\\\\\/htdocs\\\\\/releases\\\\\/[0-9]+\\\\\///g\' files/theme-config/*');
In my case the project is stored in an other path than "/var/www/htdocs". There is currently no way to change this path.
Btw: if I'm right the workaround is no longer needed, since it was fixed in Shopware 6.4.6.0: https://issues.shopware.com/issues/NEXT-17720. Maybe the workaround can simply be deleted.
I didn’t get it) Can you make a pr to discuss it?
Created PR #2755 for removal of the workaround.
The PR mentioned causes deployments on 6.4.6.0 not to fail, but still won't work for <6.4.6.0 and when the release path is not exactly the same as /var/www/htdocs/releases. So that needs to be changed to {{deploy_path}}/releases.
Example file test.json;
[
{
"storefront": {
"path": "Resources\/app\/storefront\/src",
"entryFilePath": "Resources\/app\/storefront\/src\/main.js",
"webpack": null,
"styleFiles": [
"\/var\/www\/htdocs\/releases\/20211124115627\/vendor\/shopware\/storefront\/Resources\/app\/storefront\/src\/scss\/base.scss",
"\/var\/www\/htdocs\/releases\/20211124115627\/vendor\/shopware\/storefront\/Resources\/app\/storefront\/src\/scss\/skin\/shopware\/_base.scss",
"@Plugins"
]
}
}
]
Run sed -E 's#\\/var\\/www\\/htdocs\\/releases\\/[0-9]+\\/##g' test.json;
[
{
"storefront": {
"path": "Resources\/app\/storefront\/src",
"entryFilePath": "Resources\/app\/storefront\/src\/main.js",
"webpack": null,
"styleFiles": [
"vendor\/shopware\/storefront\/Resources\/app\/storefront\/src\/scss\/base.scss",
"vendor\/shopware\/storefront\/Resources\/app\/storefront\/src\/scss\/skin\/shopware\/_base.scss",
"@Plugins"
]
}
}
]
Let's say {{deploy_path}} is /data/web/ instead of /var/www/htdocs/.
That would mean this; \\/var\\/www\\/htdocs\\/
Would need to be this; \\/data\\/web\\/
So / needs to be escaped twice, so replacing / with \\/.
Which would give us;
$deployPath = get('deploy_path');
if (substr($deployPath, -1, 1) !== '/') {
$deployPath .= '/';
}
$deployPath .= 'releases/[0-9a-zA-Z]*/';
$escapedDeployPath = str_replace('/', '\\\\/', $deployPath);
runLocally("sed -iE 's#${escapedDeployPath}##g' files/theme-config/* || true");
Here's a quick & dirty test script;
<?php
file_put_contents('test.json', '[
{
"storefront": {
"path": "Resources\/app\/storefront\/src",
"entryFilePath": "Resources\/app\/storefront\/src\/main.js",
"webpack": null,
"styleFiles": [
"\/var\/www\/htdocs\/releases\/20211124115627\/vendor\/shopware\/storefront\/Resources\/app\/storefront\/src\/scss\/base.scss",
"\/var\/www\/htdocs\/releases\/20211124115627\/vendor\/shopware\/storefront\/Resources\/app\/storefront\/src\/scss\/skin\/shopware\/_base.scss",
"@Plugins"
]
}
}
]');
$deployPath = '/var/www/htdocs';
// Ensure deploy path has a trailing slash
if (substr($deployPath, -1, 1) !== '/') {
$deployPath .= '/';
}
$deployPath .= 'releases/[0-9a-zA-Z]*/';
$escapedDeployPath = str_replace('/', '\\\\/', $deployPath);
$command = "sed -E 's#${escapedDeployPath}##g' test.json";
echo $command . PHP_EOL . PHP_EOL;
echo shell_exec($command);
Output;
[
{
"storefront": {
"path": "Resources\/app\/storefront\/src",
"entryFilePath": "Resources\/app\/storefront\/src\/main.js",
"webpack": null,
"styleFiles": [
"vendor\/shopware\/storefront\/Resources\/app\/storefront\/src\/scss\/base.scss",
"vendor\/shopware\/storefront\/Resources\/app\/storefront\/src\/scss\/skin\/shopware\/_base.scss",
"@Plugins"
]
}
}
]
@Schrank I did a PR here; https://github.com/deployphp/deployer/pull/2801/files
It's not 100% perfect because it still relies on the release name being numeric, which might not be the case, while within reasonable probability we can assume it is.
edit; fixed the regex
@peterjaap Very clean work!
Thanks!