Elastic Beanstalk “git aws.push” only commited difference?

左心房为你撑大大i 提交于 2019-11-28 04:56:50

问题


We are storing our PHP project on github.

For fast deployment we are using .bat file for git pushing changes to AWS Elastic Beanstalk cloud:

"C:\Program Files (x86)\Git\bin\sh.exe" --login -i -c "git aws.push --environment envname"

We are making commit every time before push, and it's working just perfect, as expected.

Unfortunately, for some reason, sometime it is pushing really quick (just pushing difference in PHP Code changes), but sometimes it is sending whole 300mb project (with all media).

Is there any way to git push only changed diference? Maybe there is any additional parameters on push or preparation git commands before send? Or maybe there is some way to tell AWS EB to pull last commit from github repository?

Thanks for any help.


回答1:


When you issue git aws.push your entire git repository is zipped and uploaded to Elastic Beanstalk, hence the long push time. That's the way this command is implemented. There's a nice discussion and request for change in this thread.
I'm not sure what files weigh so much in your code, but in general it's best not to store them in the application git.
If these are media files, store them in S3 (or any other web accessible place). If the majority of files are external libs sitting in your git, you can pre-install them by an EB pre-deploy script.




回答2:


I implemented a workaround because this is a bug of Amazon.

I setup a git account in a server (I used Gitlab, free private repositories and unlimited collaborators), you can use any that you want (github, gitlab, your server).

The process between you and the git server is reliable, you only push the changes, always. In the EC2 server, I setup a git repository (you can use the configuration file .ebextensions/*.config or do manual, I suggest manual to not setup in all your instances) which is connected to my git server and from EC2 server execute git pull and a git aws.push.

You are able to setup for example a Web Hook to notify when you do a git push and then do the git pull and git aws.push automatically. in my case I prefer decide when deploy using SSH, and this is not always when I push commits to my git server.

In this way, do the git aws.push from EC2 server to Elastic Beanstalk server is very fast, doesn't matter if it push everything or only the changes.




回答3:


OK, after months of troubles I resolved the reason of the problem.

The problem is that on

aws.push

command Elastic Beanstalk is checking if your current files are committed to the git or they are ahead of the repository. If your files are identical to a last git commit, then EB pulls only difference, but if your files are ahead of the last git commit, then it pulls whole folder!

To avoid problem I made a deploy.bat file for windows that tries to commit changes before aws.push command:

cls
git add .
git commit -a
git aws.push --environment myenvironment
pause

Now, if you already did commit before running this .bat file then you will upload only difference. Otherwise, you will be asked for a git commit message before uploading difference.

PS - Please note that if you will try to push version that is already on EB one more time, it will also try to upload entire folder.

PSS - If by any reason you will see that EB tries to pull entire folder, just close the window, make small changes to a source code (like adding new line or a comment), save, commit changes to git and run deploy.bat file again.

Works like a charm!

Edit:

For those who are using new standalone eb cli, the code will be:

cls
git add .
git commit -a
eb deploy your_environment_name
pause


来源:https://stackoverflow.com/questions/26941775/elastic-beanstalk-git-aws-push-only-commited-difference

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!