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

Temporary workaround in shopware recipe uses constant path #2754

Closed
phizab opened this issue Nov 15, 2021 · 7 comments
Closed

Temporary workaround in shopware recipe uses constant path #2754

phizab opened this issue Nov 15, 2021 · 7 comments

Comments

@phizab
Copy link
Contributor

phizab commented Nov 15, 2021

  • 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.

@antonmedv
Copy link
Member

I didn’t get it) Can you make a pr to discuss it?

@phizab
Copy link
Contributor Author

phizab commented Nov 15, 2021

Created PR #2755 for removal of the workaround.

@peterjaap
Copy link
Contributor

peterjaap commented Nov 30, 2021

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.

@peterjaap
Copy link
Contributor

peterjaap commented Nov 30, 2021

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"
            ]
        }
    }
]

@peterjaap
Copy link
Contributor

peterjaap commented Nov 30, 2021

@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

@UlrichThomasGabor
Copy link
Contributor

@peterjaap Very clean work!

@Schrank
Copy link
Contributor

Schrank commented Apr 3, 2024

Thanks!

@Schrank Schrank closed this as completed Apr 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants