I can run "npm run prod
". I put the same command in a deploy.sh
file. Again, I can still run the deploy script using ./deploy.sh,
and it works. But the same deploy script could not run when the git hook happens.
"npm i
" works both in the terminal, deploy script, and using git hook.
deploy.sh
script is as follows:
#!/bin/sh
php artisan down
git pull origin $1
composer install --no-interaction --prefer-dist --optimize-autoloader --no-dev
php artisan migrate --force
php artisan cache:clear
php artisan route:cache
php artisan config:cache
npm ci
# everything works fine, but the line below
npm run production
php artisan up
And the weird thing is, in the terminal, when I run ./deploy.sh
everything works, without any problem. but when the deploy script gets called using a GitHub webhook, it throws these errors:
So, npm run prod
works in terminal, works when I run the deploy script by ./deploy.sh
in the terminal, but not working when the git hook calls the laravel app to run the deploy script.
This is how I run the deploy.sh file using laravel:
$process = new Process(['./deploy.sh']);
$process->setWorkingDirectory(base_path());
$process->run(function ($type, $buffer) {
Log::info($buffer);
});
What I have tried already:
using cross-env
: not working.
using rm -rf node_modules & npm cache clean --force & npm i
: not working.