vscode-laravel-artisan icon indicating copy to clipboard operation
vscode-laravel-artisan copied to clipboard

Cannot run in Docker

Open jrseliga opened this issue 6 years ago • 4 comments

I am unable to run the commands against Docker, because the commands automatically cd into the current artisanRoot directory before running the artisan.docker.command.

Code Output:

[CMD] php artisan route:list
[ERR] Command failed: cd /home/user/Code/laravel/laravel/ && docker-compose --user laradock exec workspace && cd /var/www/laravel/laravel php artisan route:list

Wondering if the docker logic could branch a bit more, so that:

  1. "artisan.docker.root-path": "cd /path/to/docker-compose/repository" could be set to know where on the local machine the artisan.docker.command should be run from
  2. "artisan.docker.path-map": { "/var/www": "/home/user/Code" } can be set to inform the command what directory in the container to run the command against.
let localArtisanRoot = artisanRoot
let dockerPathMap = config.get('docker.path-map', null)
let dockerRoot = config.get('docker.root-path', null)

if (dockerEnabled) {
    // if user did not supply a custom dockerRoot, assume we should use the local path to the current artisan
    if(!dockerRoot) {
        dockerRoot = localArtisanRoot
    }
    // if user supplied a path map, replace in the path for docker
    if(dockerPathMap) {
        Object.entries(dockerPathMap).forEach(([replace, find]) => artisanRoot.replace(find, replace ))
    }
    command = `php artisan ${command}`
    cmd = `cd ${dockerRoot} && ${dockerCommand} "cd ${artisanRoot} ${command}"`
}

In this example, cmd will evaluate to:

cd /path/to/docker-compose/repository && docker-compose exec workspace bash -c "cd /var/www/project && php artisan route:list"

jrseliga avatar Feb 07 '19 15:02 jrseliga

I've a problem too. When I try to run my docker command with this wxtension I get the error: the input device is not a TTY

[ERR] Command failed: cd /home/victor/projects/api/ && docker-compose exec php php artisan route:list
the input device is not a TTY

But if I just copy the command of this output and run into my terminal, works properly: cd /home/victor/projects/api/ && docker-compose exec php php artisan route:list

Do you have any ideia?

Arkanius avatar Aug 22 '19 12:08 Arkanius

Same issue here simple solution is to add the option -T to exec but with this option i have no more output inside the OUTPUT panel

Vscode settings => Artisan > Docker:Command: docker-compose exec -T <app>

[CMD] php artisan key:generate --show [CMD] php artisan migrate [ERR] Command failed: cd /home/greefine/Projects/Blackfoot/airbnb-server-v2/ && docker-compose exec -T app php artisan migrate

GreeFine avatar Oct 03 '19 10:10 GreeFine

Yes! The -T option really solves the problem!

Arkanius avatar Oct 04 '19 12:10 Arkanius

Also, the plugin assumes artisan is already enabled in $PATH. Allowing to customize the command could be very helpful here.

agarzon avatar Feb 19 '20 03:02 agarzon

Marking issue as stale since there has'nt been any activity recently.

github-actions[bot] avatar Apr 27 '23 22:04 github-actions[bot]

Following this example below, I hope it helps others:

docker exec container_name php artisan migrate --database=api
status=$?
if [ $status -ne 0 ]; then
  echo "Erro: O comando de migração falhou com código de saída $status"
  exit 1
fi

denmely avatar Oct 25 '23 20:10 denmely