rennokki/laravel-aws-eb

Permission error on aws deploy

hendal opened this issue · 8 comments

Hi I was trying to make use of your repo but can't seem to use it correctly I am getting a permission error on deploy

2020/05/23 01:48:58.813242 [INFO] Following platform hooks will be executed in order: [configure_php_ini.sh install_imagick.sh install_latest_node_js.sh install_memcached_discovery.sh install_supervisor.sh update_composer.sh]
2020/05/23 01:48:58.813249 [INFO] Running platform hook: .platform/hooks/prebuild/configure_php_ini.sh
2020/05/23 01:48:58.813440 [ERROR] An error occurred during execution of command [app-deploy] - [RunPreBuildHooks]. Stop running the command. Error: Command .platform/hooks/prebuild/configure_php_ini.sh failed with error fork/exec .platform/hooks/prebuild/configure_php_ini.sh: permission denied 

I made sure to run the commands:

$ chmod +x .platform/hooks/prebuild/*.sh

$ chmod +x .platform/hooks/predeploy/*.sh

$ chmod +x .platform/hooks/postdeploy/*.sh

And I am generating the zip running the following command

zip ../laravel-default.zip -r * .[^.]* -x "vendor/*" -x ".git/*"

From what I can see its because zips don't save permissions from chmod, got any ideas to overcome this? I am attaching the eb log, it seems like nothing gets run.

eb-engine.log

Hey I'm facing the same issue.

How did you fixed this one?

I am using Windows and adding +x permission on the files is kind of useless.

So, if you are using Powershell, Cmd, or GIT Bash for Windows, you do not get any benefit from the chmod. Git Bash only emulates the Linux's CLI, but the subsidiary filesystem is still DOS.

To fix this, you have two options as stated here: #8

You either switch to a Linux machine (the best way) or use Windows 10's WSL app from Microsoft Store to bring up a Linux terminal that actually works or you opt-in for CI/CD, where you have Unix-based environment where you can run the chmod properly.

in case anyone is having this issue while not on Windows:

I was running into this problem even after making the shell scripts executable.

If you are using the git command to zip the source code, like git archive -v -o ../source.zip --format=zip HEAD you need to make sure you've added/committed everything.

Also you can ensure your shell scripts are being tracked properly in git by running:
git update-index --chmod=+x .platform/hooks/postdeploy/01-permissions.sh
git update-index --chmod=+x .platform/hooks/postdeploy/02-cache.sh

This fixed the issue for me

According to this doc page: https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/eb3-cli-git.html, using the ebcli will behave just like normal zip archival, while also respecting the git files and the tree. If you are using ebcli, you won't need to zip the files as long as you can simply just use the ebcli to init, set app & environment, and deploy the current working directory.

In my vast experience with EB deployments, zipping would be the least favorite and I had issues with zipping the chmod-ded files until I turned my eyes to ebcli.

Also, instead of making sure you committed everything, you shall look for the --staged parameter in case you are using ebcli.

The readme section Deploying from the CI/CD pipeline also applies if you are using Docker or UNIX-based systems: https://github.com/rennokki/laravel-aws-eb#deploying-from-the-cicd-pipeline

I don't think the .zip format is the issue, I just tried with a .tar file with the same exact outcome even though the .sh files had execution rights.
.tar by default will preserve file permissions and ownership when creating the archive so the issue is probably the way the file is uncompressed on the Amazon side, I think the only workaround for this is probably to change the way I deploy my app

As I said, I don't recommend using the traditional method of zipping (or making it a tarball) and uploading it, over ebcli.

Have you checked this: https://superuser.com/a/1083144 ? The user AWS' is extracting the files to is not root, btw (it's webapp or web, can't remember; Amazon AMI uses webapp, if I remember it correctly)

iKlsR commented

Just adding a step to my actions workflow fixed this for me before zipping as normal and deploying

- name: Make platform hook scripts executable 
  run: chmod +x .platform/hooks/**/*.sh

try
git add --chmod=+x -- .platform/*/*/*.sh