Can I use an external tool through Docker?

I am looking an easy way to run an external tool on my code so I fix developers issues like for example coding standards. The tool for this is called PHP-CS-Fixer. I've created a Docker image containing such tool. Now I am trying to get this running from the IDE itself since it's a little annoying been running the command once and again several times.

This image is what I have done so far to setup the tool:

This mean the tool itself is running inside the Docker container and the source exists in the host (my PC) but has been mapped thru a VOLUME inside the Docker container (basically how Docker works).

But it is not working since I got the following error:

> 11:53 AM Error running PHP-CS-Fixer: Cannot start process, the working directory 'oneview_symfony/src' does not exist

Is there any way to achieve this?

0
10 comments

Hi there,

Well .. I'm not a Docker user myself .. but shouldn't the "Working directory" be a FULL path and not just "something that looks like a part of the path"?

2nd possible point -- why whole command is put into the "Program" field -- shouldn't parameters go into dedicated field?

Just in case: https://confluence.jetbrains.com/display/PhpStorm/Running+External+Tools+in+PhpStorm

0

P.S.

This is how it can be done via File Watcher (local execution though). But you can have a look at parameters used there etc

https://stackoverflow.com/q/44073562/783119

0

@Andriy,

it's not working either, see below:

Error:

6/13/17
3:07 PM Error running PHP-CS-Fixer: Cannot run program "docker exec -u www-data -it mmi_webserver_1 php_cs_fixer" (in directory "/home/rperez/sources/mmi/oneview_symfony/src"): error=2, No such file or directory
0

The error is correct: "docker exec -u www-data -it mmi_webserver_1 php_cs_fixer" is NOT a program.

The program here is "docker" (and it should be a full path to that file)  -- everything else are parameters... so they should be in corresponding "Parameters" field.

0

We're almost there, now the problem is the "Working Directory" since this one isn't at the same route in the Docker container. Take a look at the following error:

/usr/bin/docker exec -u www-data -i mmi_webserver_1 php-cs-fixer fix /home/rperez/sources/mmi/oneview_symfony/src/Schneider/QuoteBundle/Entity/AgreementType.php --verbose


[PhpCsFixer\ConfigurationException\InvalidConfigurationException (16)]
The path "/home/rperez/sources/mmi/oneview_symfony/src/Schneider/QuoteBundl
e/Entity/AgreementType.php" is not readable.


Exception trace:
() at /root/.composer/vendor/friendsofphp/php-cs-fixer/src/Console/ConfigurationResolver.php:349
PhpCsFixer\Console\ConfigurationResolver->PhpCsFixer\Console\{closure}() at n/a:n/a
array_map() at /root/.composer/vendor/friendsofphp/php-cs-fixer/src/Console/ConfigurationResolver.php:357
PhpCsFixer\Console\ConfigurationResolver->getPath() at /root/.composer/vendor/friendsofphp/php-cs-fixer/src/Console/ConfigurationResolver.php:512
PhpCsFixer\Console\ConfigurationResolver->computeConfigFiles() at /root/.composer/vendor/friendsofphp/php-cs-fixer/src/Console/ConfigurationResolver.php:210
PhpCsFixer\Console\ConfigurationResolver->getConfig() at /root/.composer/vendor/friendsofphp/php-cs-fixer/src/Console/ConfigurationResolver.php:560
PhpCsFixer\Console\ConfigurationResolver->getFormat() at /root/.composer/vendor/friendsofphp/php-cs-fixer/src/Console/ConfigurationResolver.php:405
PhpCsFixer\Console\ConfigurationResolver->getReporter() at /root/.composer/vendor/friendsofphp/php-cs-fixer/src/Console/Command/FixCommand.php:144
PhpCsFixer\Console\Command\FixCommand->execute() at /root/.composer/vendor/symfony/console/Command/Command.php:264
Symfony\Component\Console\Command\Command->run() at /root/.composer/vendor/symfony/console/Application.php:835
Symfony\Component\Console\Application->doRunCommand() at /root/.composer/vendor/symfony/console/Application.php:200
Symfony\Component\Console\Application->doRun() at /root/.composer/vendor/symfony/console/Application.php:124
Symfony\Component\Console\Application->run() at /root/.composer/vendor/friendsofphp/php-cs-fixer/php-cs-fixer:55

fix [--path-mode PATH-MODE] [--allow-risky ALLOW-RISKY] [--config CONFIG] [--dry-run] [--rules RULES] [--using-cache USING-CACHE] [--cache-file CACHE-FILE] [--diff] [--format FORMAT] [--stop-on-violation] [--show-progress SHOW-PROGRESS] [--] [<path>]...


Process finished with exit code 16

 

And now take a look to my PHP interpreter configuration:

See how the working directory is being mapped inside the container, any ideas?

0

When you are using External Tools then you execute command/program directly (similarly to how it would be done in terminal) -- your PHP Interpreter does not participate in this, at all.

"Working directory" here is basically an another parameter that is passed to a "create process/execute task" OS system call/API that is used behind the scene -- it just tells OS what the "cwd" or "dir" (or whatever the actual correct command is that shows the current directory) should be used as "current directory".

As far as I understand:

  • "Working directory" parameter in your case could be left empty .. or perhaps point to a project root dir.
  • Instead of using $FileDir$ macro (which AFAIK will be expanded to  a full LOCAL folder) it should be a remote path (as the command will be executed inside the docker container). So you either pass full hardcoded path (which is no use here, as you have files in different folders) .. or you pass some hardcode path (the path to the project root) and then relative path part using a macro ...

So in the end it SHOULD look something like this (the "Parameters" field):

exec -u www-data -it mmi_webserver_1 php_cs_fixer fix /var/www/html/$FileDirRelativeToProjectRoot$/$Filename$ --verbose

 

 

1

That worked, thank you so much I'll post this solution in my blog if you don't mind

1

Hi @Andriy,

I am running the latest version of the EAP but now the command does not work anymore. See pics and error below. Any ideas? Why the path is missing now? This does not happen before

This is the error:

docker exec -u www-data -i mmi_webserver_1 php-cs-fixer fix /var/www/html//$Filename$ --verbose

[PhpCsFixer\ConfigurationException\InvalidConfigurationException (16)]
The path "/var/www/html//$Filename$" is not readable.

Exception trace:
() at /root/.composer/vendor/friendsofphp/php-cs-fixer/src/Console/ConfigurationResolver.php:357
PhpCsFixer\Console\ConfigurationResolver->PhpCsFixer\Console\{closure}() at n/a:n/a
array_map() at /root/.composer/vendor/friendsofphp/php-cs-fixer/src/Console/ConfigurationResolver.php:365
PhpCsFixer\Console\ConfigurationResolver->getPath() at /root/.composer/vendor/friendsofphp/php-cs-fixer/src/Console/ConfigurationResolver.php:520
PhpCsFixer\Console\ConfigurationResolver->computeConfigFiles() at /root/.composer/vendor/friendsofphp/php-cs-fixer/src/Console/ConfigurationResolver.php:208
PhpCsFixer\Console\ConfigurationResolver->getConfig() at /root/.composer/vendor/friendsofphp/php-cs-fixer/src/Console/ConfigurationResolver.php:568
PhpCsFixer\Console\ConfigurationResolver->getFormat() at /root/.composer/vendor/friendsofphp/php-cs-fixer/src/Console/ConfigurationResolver.php:413
PhpCsFixer\Console\ConfigurationResolver->getReporter() at /root/.composer/vendor/friendsofphp/php-cs-fixer/src/Console/Command/FixCommand.php:145
PhpCsFixer\Console\Command\FixCommand->execute() at /root/.composer/vendor/symfony/console/Command/Command.php:264
Symfony\Component\Console\Command\Command->run() at /root/.composer/vendor/symfony/console/Application.php:874
Symfony\Component\Console\Application->doRunCommand() at /root/.composer/vendor/symfony/console/Application.php:228
Symfony\Component\Console\Application->doRun() at /root/.composer/vendor/symfony/console/Application.php:130
Symfony\Component\Console\Application->run() at /root/.composer/vendor/friendsofphp/php-cs-fixer/php-cs-fixer:53

fix [--path-mode PATH-MODE] [--allow-risky ALLOW-RISKY] [--config CONFIG] [--dry-run] [--rules RULES] [--using-cache USING-CACHE] [--cache-file CACHE-FILE] [--diff] [--format FORMAT] [--stop-on-violation] [--show-progress SHOW-PROGRESS] [--] [<path>]...
0

Hi,

I'm not 100% sure .. but if your error/screenshot was not edited then the only thing I've spotted so far is $Filename$ macro have not been replaced by actual file name -- the path has still macro variable in it: /var/www/html//$Filename$

Try using the correct letter case: $FileName$ (notice capital N)

0

You were right the macro name has changed: before $Filename$, after: $FileName$ it worked now

0

Please sign in to leave a comment.