Closed sparkhom closed 7 years ago
Excellent!!! Any chance this could get merged? We're kind of stuck until it is!
Also -- one question on this. I made all of these changes manually and it still can't create the /bootstrap/cache/services.php file. It does all of the symlinking and then tries to composer install
, completely skipping the checks for all of the necessary folders.
That's odd... could you please send me the output of one of your deploys with the --trace
option enabled? As well, could you double check that the tasks at the bottom of laravel.rake
were updated with your manual changes? The reason that they weren't running before is because if fetch(:laravel_set_acl_paths)
would return false in that scope.
I'm on holiday until the new year, so I'll try to look at this sometime soon, otherwise I'll get around to it first thing in 2017.
For anyone that would like to test, they can do so with the following repository.
https://github.com/ikari7789/capistrano-laravel-test
I haven't had time to merge this in as actual tests yet, but it has a Vagrantfile to spin up an Ubuntu box with PHP. You need to install the capistrano-laravel plugin and then run run-tests.sh and it'll run a deploy for each version of Laravel from 4.2-5.3.
@sparkhom Thanks for taking the time. Here it is:
** Invoke staging (first_time)
** Execute staging
** Invoke load:defaults (first_time)
** Execute load:defaults
** Invoke deploy (first_time)
** Execute deploy
** Invoke deploy:starting (first_time)
** Invoke laravel:resolve_linked_dirs (first_time)
** Execute laravel:resolve_linked_dirs
** Execute deploy:starting
** Invoke deploy:check (first_time)
** Invoke git:check (first_time)
** Invoke git:wrapper (first_time)
** Execute git:wrapper
00:00 git:wrapper
01 mkdir -p /home/national/tmp
01 stdin: is not a tty
✔ 01 national@server.awesomeapp.com 1.210s
Uploading /home/national/tmp/git-ssh-hoshi-api-staging-mcblum.sh 100.0%
02 chmod 700 /home/national/tmp/git-ssh-hoshi-api-staging-mcblum.sh
02 stdin: is not a tty
✔ 02 national@server.awesomeapp.com 0.097s
** Execute git:check
00:02 git:check
01 git ls-remote --heads git@starfish.nationalmachine.io:hoshi/api.awesomeapp.com.git
01 stdin: is not a tty
01 f1bf976a14b8340ce206bc10de3481cc9bcf2746 refs/heads/contact-feature
01 2023b891ee32e821bca3a191fdae03e187aea581 refs/heads/laravel-5.3-upgrade
01 efbee4d2ad0bcfb40055e3d68b8000b05337af03 refs/heads/master
01 b7e5bc64bb7b44fd16748634cb6573823343143a refs/heads/podcasting-feed
01 9c789474ea31b8dd5406d071303ffc1f8231f23d refs/heads/refactory-july-2016
01 677de5c8223496825427ccc8731c3f5369aa3619 refs/heads/texting
✔ 01 national@server.awesomeapp.com 1.741s
** Execute deploy:check
** Invoke deploy:check:directories (first_time)
** Execute deploy:check:directories
00:03 deploy:check:directories
01 mkdir -p /home/national/public_html/stage/api.awesomeapp.com/shared /home/national/public_html/stage/api.awesomeapp.com/releases
01 stdin: is not a tty
✔ 01 national@server.awesomeapp.com 0.094s
** Invoke deploy:check:linked_dirs (first_time)
** Execute deploy:check:linked_dirs
00:03 deploy:check:linked_dirs
01 mkdir -p /home/national/public_html/stage/api.awesomeapp.com/shared/storage/app /home/national/public_html/stage/api.awesomeapp.com/shared/storage/framework/cache /home/national/public_html/stage/api.awesomeapp.com/shared…
01 stdin: is not a tty
✔ 01 national@server.awesomeapp.com 0.103s
** Invoke deploy:check:make_linked_dirs (first_time)
** Execute deploy:check:make_linked_dirs
** Invoke deploy:check:linked_files (first_time)
** Execute deploy:check:linked_files
** Invoke deploy:set_previous_revision (first_time)
** Execute deploy:set_previous_revision
** Invoke laravel:ensure_linked_dirs_exist (first_time)
** Execute laravel:ensure_linked_dirs_exist
00:04 laravel:ensure_linked_dirs_exist
01 mkdir -p storage/app
01 stdin: is not a tty
✔ 01 national@server.awesomeapp.com 0.092s
02 mkdir -p storage/framework/cache
02 stdin: is not a tty
✔ 02 national@server.awesomeapp.com 0.092s
03 mkdir -p storage/framework/sessions
03 stdin: is not a tty
✔ 03 national@server.awesomeapp.com 0.092s
04 mkdir -p storage/framework/views
04 stdin: is not a tty
✔ 04 national@server.awesomeapp.com 0.096s
05 mkdir -p storage/logs
05 stdin: is not a tty
✔ 05 national@server.awesomeapp.com 0.094s
** Invoke deploy:started (first_time)
** Execute deploy:started
** Invoke deploy:updating (first_time)
** Invoke deploy:new_release_path (first_time)
** Execute deploy:new_release_path
** Invoke git:create_release (first_time)
** Invoke git:update (first_time)
** Invoke git:clone (first_time)
** Invoke git:wrapper
** Execute git:clone
00:05 git:clone
The repository mirror is at /home/national/public_html/stage/api.awesomeapp.com/repo
** Execute git:update
00:05 git:update
01 git remote update --prune
01 stdin: is not a tty
01 Fetching origin
✔ 01 national@server.awesomeapp.com 2.052s
** Execute git:create_release
00:07 git:create_release
01 mkdir -p /home/national/public_html/stage/api.awesomeapp.com/releases/20161221035117
01 stdin: is not a tty
✔ 01 national@server.awesomeapp.com 0.110s
02 git archive master | /usr/bin/env tar -x -f - -C /home/national/public_html/stage/api.awesomeapp.com/releases/20161221035117
02 stdin: is not a tty
✔ 02 national@server.awesomeapp.com 0.183s
** Execute deploy:updating
** Invoke deploy:set_current_revision (first_time)
** Invoke git:set_current_revision (first_time)
** Execute git:set_current_revision
** Execute deploy:set_current_revision
00:07 deploy:set_current_revision
01 echo "efbee4d2ad0bcfb40055e3d68b8000b05337af03" >> REVISION
01 stdin: is not a tty
✔ 01 national@server.awesomeapp.com 0.098s
** Invoke deploy:symlink:shared (first_time)
** Execute deploy:symlink:shared
** Invoke deploy:symlink:linked_files (first_time)
** Execute deploy:symlink:linked_files
** Invoke deploy:symlink:linked_dirs (first_time)
** Execute deploy:symlink:linked_dirs
00:08 deploy:symlink:linked_dirs
01 mkdir -p /home/national/public_html/stage/api.awesomeapp.com/releases/20161221035117/storage /home/national/public_html/stage/api.awesomeapp.com/releases/20161221035117/storage/framework
01 stdin: is not a tty
✔ 01 national@server.awesomeapp.com 0.093s
02 ln -s /home/national/public_html/stage/api.awesomeapp.com/shared/storage/app /home/national/public_html/stage/api.awesomeapp.com/releases/20161221035117/storage/app
02 stdin: is not a tty
✔ 02 national@server.awesomeapp.com 0.097s
03 ln -s /home/national/public_html/stage/api.awesomeapp.com/shared/storage/framework/cache /home/national/public_html/stage/api.awesomeapp.com/releases/20161221035117/storage/framework/cache
03 stdin: is not a tty
✔ 03 national@server.awesomeapp.com 0.105s
04 ln -s /home/national/public_html/stage/api.awesomeapp.com/shared/storage/framework/sessions /home/national/public_html/stage/api.awesomeapp.com/releases/20161221035117/storage/framework/sessions
04 stdin: is not a tty
✔ 04 national@server.awesomeapp.com 0.093s
05 ln -s /home/national/public_html/stage/api.awesomeapp.com/shared/storage/framework/views /home/national/public_html/stage/api.awesomeapp.com/releases/20161221035117/storage/framework/views
05 stdin: is not a tty
✔ 05 national@server.awesomeapp.com 0.102s
06 ln -s /home/national/public_html/stage/api.awesomeapp.com/shared/storage/logs /home/national/public_html/stage/api.awesomeapp.com/releases/20161221035117/storage/logs
06 stdin: is not a tty
✔ 06 national@server.awesomeapp.com 0.091s
** Invoke deploy:updated (first_time)
** Invoke composer:install (first_time)
** Execute composer:install
** Invoke composer:run (first_time)
** Invoke laravel:upload_dotenv_file (first_time)
** Execute laravel:upload_dotenv_file
00:09 laravel:upload_dotenv_file
Uploading ./env/.env.staging 100.0%
** Execute composer:run
00:09 composer:run
01 composer install --no-interaction --quiet --optimize-autoloader
01 stdin: is not a tty
01
01
01 [ErrorException]
01 file_put_contents(/home/national/public_html/stage/api.awesomeapp.com/releases/20161221035117/bootstrap/cache/services.php): failed to open stream: No such file or directory
01
01
cap aborted!
SSHKit::Runner::ExecuteError: Exception while executing as national@server.awesomeapp.com: composer exit status: 1
composer stdout: [ErrorException]
file_put_contents(/home/national/public_html/stage/api.awesomeapp.com/releases/20161221035117/bootstrap/cache/services.php): failed to open stream: No such file or directory
composer stderr: stdin: is not a tty
/Users/mcblum/.rvm/gems/ruby-2.3.0/gems/sshkit-1.11.4/lib/sshkit/runners/parallel.rb:15:in `rescue in block (2 levels) in execute'
/Users/mcblum/.rvm/gems/ruby-2.3.0/gems/sshkit-1.11.4/lib/sshkit/runners/parallel.rb:11:in `block (2 levels) in execute'
SSHKit::Command::Failed: composer exit status: 1
composer stdout: [ErrorException]
file_put_contents(/home/national/public_html/stage/api.awesomeapp.com/releases/20161221035117/bootstrap/cache/services.php): failed to open stream: No such file or directory
composer stderr: stdin: is not a tty
/Users/mcblum/.rvm/gems/ruby-2.3.0/gems/sshkit-1.11.4/lib/sshkit/command.rb:100:in `exit_status='
/Users/mcblum/.rvm/gems/ruby-2.3.0/gems/sshkit-1.11.4/lib/sshkit/backends/netssh.rb:148:in `execute_command'
/Users/mcblum/.rvm/gems/ruby-2.3.0/gems/sshkit-1.11.4/lib/sshkit/backends/abstract.rb:141:in `block in create_command_and_execute'
/Users/mcblum/.rvm/gems/ruby-2.3.0/gems/sshkit-1.11.4/lib/sshkit/backends/abstract.rb:141:in `tap'
/Users/mcblum/.rvm/gems/ruby-2.3.0/gems/sshkit-1.11.4/lib/sshkit/backends/abstract.rb:141:in `create_command_and_execute'
/Users/mcblum/.rvm/gems/ruby-2.3.0/gems/sshkit-1.11.4/lib/sshkit/backends/abstract.rb:74:in `execute'
/Users/mcblum/.rvm/gems/ruby-2.3.0/gems/capistrano-composer-0.0.6/lib/capistrano/tasks/composer.rake:27:in `block (4 levels) in <top (required)>'
/Users/mcblum/.rvm/gems/ruby-2.3.0/gems/sshkit-1.11.4/lib/sshkit/backends/abstract.rb:85:in `within'
/Users/mcblum/.rvm/gems/ruby-2.3.0/gems/capistrano-composer-0.0.6/lib/capistrano/tasks/composer.rake:26:in `block (3 levels) in <top (required)>'
/Users/mcblum/.rvm/gems/ruby-2.3.0/gems/sshkit-1.11.4/lib/sshkit/backends/abstract.rb:29:in `instance_exec'
/Users/mcblum/.rvm/gems/ruby-2.3.0/gems/sshkit-1.11.4/lib/sshkit/backends/abstract.rb:29:in `run'
/Users/mcblum/.rvm/gems/ruby-2.3.0/gems/sshkit-1.11.4/lib/sshkit/runners/parallel.rb:12:in `block (2 levels) in execute'
Tasks: TOP => composer:run
The deploy has failed with an error: Exception while executing as national@server.awesomeapp.com: composer exit status: 1
composer stdout: [ErrorException]
file_put_contents(/home/national/public_html/stage/api.awesomeapp.com/releases/20161221035117/bootstrap/cache/services.php): failed to open stream: No such file or directory
composer stderr: stdin: is not a tty
** Invoke deploy:failed (first_time)
** Execute deploy:failed
** DEPLOY FAILED
** Refer to log/capistrano.log for details. Here are the last 20 lines:
DEBUG [27571cf3] stdin: is not a tty
INFO [27571cf3] Finished in 0.091 seconds with exit status 0 (successful).
DEBUG [00ddbdda] Running [ ! -e ./env/.env.staging ] as mcblum@localhost
DEBUG [00ddbdda] Command: [ ! -e ./env/.env.staging ]
DEBUG [00ddbdda] Finished in 0.006 seconds with exit status 256 (failed).
DEBUG Uploading ./env/.env.staging 0.0%
INFO Uploading ./env/.env.staging 100.0%
DEBUG [cc054487] Running if test ! -d /home/national/public_html/stage/api.awesomeapp.com/releases/20161221035117; then echo "Directory does not exist '/home/national/public_html/stage/api.awesomeapp.com/releases/20161221035117'" 1>&2; false; fi as national@server.awesomeapp.com
DEBUG [cc054487] Command: if test ! -d /home/national/public_html/stage/api.awesomeapp.com/releases/20161221035117; then echo "Directory does not exist '/home/national/public_html/stage/api.awesomeapp.com/releases/20161221035117'" 1>&2; false; fi
DEBUG [cc054487] stdin: is not a tty
DEBUG [cc054487] Finished in 0.095 seconds with exit status 0 (successful).
INFO [799e0665] Running /usr/bin/env composer install --no-interaction --quiet --optimize-autoloader as national@server.awesomeapp.com
DEBUG [799e0665] Command: cd /home/national/public_html/stage/api.awesomeapp.com/releases/20161221035117 && /usr/bin/env composer install --no-interaction --quiet --optimize-autoloader
DEBUG [799e0665] stdin: is not a tty
DEBUG [799e0665]
DEBUG [799e0665]
[ErrorException]
file_put_contents(/home/national/public_html/stage/api.awesomeapp.com/releases/20161221035117/bootstrap/cache/services.php): failed to open stream: No such file or directory
@sparkhom well this is crazy -- I just ran it again and it almost worked. Got until this error:
There are no commands defined in the "storage" namespace.
Huh, interesting. I assume you're getting this error because you're on a version of Laravel older than 5.3. Are you doing set :laravel_version, <your-laravel-version>
in your deployment configuration?
@sparkhom You'd think so, right? But I'm on 5.3 and here is the laravel-related stuff from my deploy.rb.
# Laravel Stuff
set :laravel_roles, :all
set :laravel_version, 5.3
For whatever reason, re-doing all of your tweaks has now eliminated that error but left me with:
DEBUG [5361a008] setfacl: Option -m: Invalid argument near character 3
I'm beginning to think the universe has it out for this project :) Just wanted to say again thank you for your help with this. I really appreciate it as this package is built into all of our app deploys. Here are the logs:
00:38 deploy:set_permissions:acl
01 setfacl -Rn -m u:www-data:rwX -m u:national:rwX /home/national/public_html/stage/api.awesomeapp.com/releases/20161221145954/bootstrap/cache /home/national/public_html/stage/api.awesomeapp.com/releases/20161221145954/storage /home/national/public_html/stage/api.awesomeapp.com/shared/storage/app /home/national/pub…
01 stdin: is not a tty
01 setfacl: Option -m: Invalid argument near character 3
cap aborted!
SSHKit::Runner::ExecuteError: Exception while executing as national@server.awesomeapp.com: setfacl exit status: 2
setfacl stdout: Nothing written
setfacl stderr: stdin: is not a tty
setfacl: Option -m: Invalid argument near character 3
/Users/mcblum/.rvm/gems/ruby-2.3.0/gems/sshkit-1.11.4/lib/sshkit/runners/parallel.rb:15:in `rescue in block (2 levels) in execute'
/Users/mcblum/.rvm/gems/ruby-2.3.0/gems/sshkit-1.11.4/lib/sshkit/runners/parallel.rb:11:in `block (2 levels) in execute'
SSHKit::Command::Failed: setfacl exit status: 2
setfacl stdout: Nothing written
setfacl stderr: stdin: is not a tty
setfacl: Option -m: Invalid argument near character 3
/Users/mcblum/.rvm/gems/ruby-2.3.0/gems/sshkit-1.11.4/lib/sshkit/command.rb:100:in `exit_status='
/Users/mcblum/.rvm/gems/ruby-2.3.0/gems/sshkit-1.11.4/lib/sshkit/backends/netssh.rb:148:in `execute_command'
/Users/mcblum/.rvm/gems/ruby-2.3.0/gems/sshkit-1.11.4/lib/sshkit/backends/abstract.rb:141:in `block in create_command_and_execute'
/Users/mcblum/.rvm/gems/ruby-2.3.0/gems/sshkit-1.11.4/lib/sshkit/backends/abstract.rb:141:in `tap'
/Users/mcblum/.rvm/gems/ruby-2.3.0/gems/sshkit-1.11.4/lib/sshkit/backends/abstract.rb:141:in `create_command_and_execute'
/Users/mcblum/.rvm/gems/ruby-2.3.0/gems/sshkit-1.11.4/lib/sshkit/backends/abstract.rb:74:in `execute'
/Users/mcblum/.rvm/gems/ruby-2.3.0/gems/capistrano-file-permissions-1.0.0/lib/capistrano/tasks/file-permissions.rake:45:in `block (4 levels) in <top (required)>'
/Users/mcblum/.rvm/gems/ruby-2.3.0/gems/sshkit-1.11.4/lib/sshkit/backends/abstract.rb:29:in `instance_exec'
/Users/mcblum/.rvm/gems/ruby-2.3.0/gems/sshkit-1.11.4/lib/sshkit/backends/abstract.rb:29:in `run'
/Users/mcblum/.rvm/gems/ruby-2.3.0/gems/sshkit-1.11.4/lib/sshkit/runners/parallel.rb:12:in `block (2 levels) in execute'
Tasks: TOP => deploy:updated => deploy:set_permissions:acl
The deploy has failed with an error: Exception while executing as national@server.awesomeapp.com: setfacl exit status: 2
setfacl stdout: Nothing written
setfacl stderr: stdin: is not a tty
setfacl: Option -m: Invalid argument near character 3
** Invoke deploy:failed (first_time)
** Execute deploy:failed
** DEPLOY FAILED
** Refer to log/capistrano.log for details. Here are the last 20 lines:
DEBUG [317732d5] Running [ -d /home/national/public_html/stage/api.awesomeapp.com/shared/storage/framework/cache ] as national@server.awesomeapp.com
DEBUG [317732d5] Command: [ -d /home/national/public_html/stage/api.awesomeapp.com/shared/storage/framework/cache ]
DEBUG [317732d5] stdin: is not a tty
DEBUG [317732d5] Finished in 0.080 seconds with exit status 0 (successful).
DEBUG [b062dad3] Running [ -d /home/national/public_html/stage/api.awesomeapp.com/shared/storage/framework/sessions ] as national@server.awesomeapp.com
DEBUG [b062dad3] Command: [ -d /home/national/public_html/stage/api.awesomeapp.com/shared/storage/framework/sessions ]
DEBUG [b062dad3] stdin: is not a tty
DEBUG [b062dad3] Finished in 0.080 seconds with exit status 0 (successful).
DEBUG [b5cd014b] Running [ -d /home/national/public_html/stage/api.awesomeapp.com/shared/storage/framework/views ] as national@server.awesomeapp.com
DEBUG [b5cd014b] Command: [ -d /home/national/public_html/stage/api.awesomeapp.com/shared/storage/framework/views ]
DEBUG [b5cd014b] stdin: is not a tty
DEBUG [b5cd014b] Finished in 0.083 seconds with exit status 0 (successful).
DEBUG [c291a8ef] Running [ -d /home/national/public_html/stage/api.awesomeapp.com/shared/storage/logs ] as national@server.awesomeapp.com
DEBUG [c291a8ef] Command: [ -d /home/national/public_html/stage/api.awesomeapp.com/shared/storage/logs ]
DEBUG [c291a8ef] stdin: is not a tty
DEBUG [c291a8ef] Finished in 0.081 seconds with exit status 0 (successful).
INFO [771d87dd] Running /usr/bin/env setfacl -Rn -m u:www-data:rwX -m u:national:rwX /home/national/public_html/stage/api.awesomeapp.com/releases/20161221145954/bootstrap/cache /home/national/public_html/stage/api.awesomeapp.com/releases/20161221145954/storage /home/national/public_html/stage/api.awesomeapp.com/shared/storage/app /home/national/public_html/stage/api.awesomeapp.com/releases/20161221145954/storage/app/public /home/national/public_html/stage/api.awesomeapp.com/releases/20161221145954/storage/framework /home/national/public_html/stage/api.awesomeapp.com/shared/storage/framework/cache /home/national/public_html/stage/api.awesomeapp.com/shared/storage/framework/sessions /home/national/public_html/stage/api.awesomeapp.com/shared/storage/framework/views /home/national/public_html/stage/api.awesomeapp.com/shared/storage/logs as national@server.awesomeapp.com
DEBUG [771d87dd] Command: /usr/bin/env setfacl -Rn -m u:www-data:rwX -m u:national:rwX /home/national/public_html/stage/api.awesomeapp.com/releases/20161221145954/bootstrap/cache /home/national/public_html/stage/api.awesomeapp.com/releases/20161221145954/storage /home/national/public_html/stage/api.awesomeapp.com/shared/storage/app /home/national/public_html/stage/api.awesomeapp.com/releases/20161221145954/storage/app/public /home/national/public_html/stage/api.awesomeapp.com/releases/20161221145954/storage/framework /home/national/public_html/stage/api.awesomeapp.com/shared/storage/framework/cache /home/national/public_html/stage/api.awesomeapp.com/shared/storage/framework/sessions /home/national/public_html/stage/api.awesomeapp.com/shared/storage/framework/views /home/national/public_html/stage/api.awesomeapp.com/shared/storage/logs
DEBUG [771d87dd] stdin: is not a tty
DEBUG [771d87dd] setfacl: Option -m: Invalid argument near character 3
I think this error must be why in all of our other Laravel deploys I have set :laravel_set_acl, false
. Back with earlier versions of this is appears that doing that had no effect on the shared directories or the creation of the required directories. Now it looks like it won't run the create directories if that is set to false.
Try putting set :laravel_server_user, '<your-server-user>'
in your deployment configuration file. <your-server-user>
should be the user that Laravel runs under; this setting defaults to www-data
, and I think that setfacl
is failing since that user doesn't exist on your server. Hopefully this gets it working for you!
@sparkhom YES! All good now. Thank you x100. Was really stuck with this.
Tested and didn't notice any anomalies. Sorry for the delay in getting this merged.
I tried to deploy my Laravel app the other day using this set of Capistrano tasks; it was mostly successful, but I noticed that my storage directory wasn't getting symlinked. I dug a little deeper found a couple of issues relating to storage:link not working with Laravel 5.3 and some ACL paths not getting created/set.
Additionally, this should fix #33 (I believe this is the same ACL path issue I ran into).