Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I want to setup Elastic Beanstalk for my existing rails application.

I was successful in doing the sample foo app.

These are the questions I have

I need the deployment to happen from my git repository and not from my local path where I am deploying. How do I do that for the sample foo app.

The git aws.push command seems to deploy on the new ec2 instance. However, it did not push the changes to my git repository. Should I do a git push separately before doing a git aws.push ? Notice that my branch is ahead by 1 commit when I do a git status. Does aws maintain a separate git repository ? How can I get it to use my git repository instead ?

[mymac:~/Projects/new/foo(master)]$ git aws.push
Counting objects: 4949, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (1115/1115), done.
Writing objects: 100% (4949/4949), 14.11 MiB | 1.90 MiB/s, done.
Total 4949 (delta 3800), reused 4944 (delta 3798)
remote: 
To https://AKIAJZT3WFY2WLO6CHQQ:20121127T030627Zf56675b2f4c9c731ca6f51b11d36a438e8bcee25c5171061ce5ac681495318c9@git.elasticbeanstalk.ap-southeast-1.amazonaws.com/v1/repos/617069/commitid/39396162666436346439656465313537613561343561626465643931393366623762386265303138/environment/6170692d656e76
 * [new branch]      HEAD -> master


[mymac:~/Projects/new/foo(master)]$ git status
# On branch master
# Your branch is ahead of 'origin/master' by 1 commit.
#
nothing to commit (working directory clean)

Below is the result of just a git push.

[mymac:~/Projects/new/foo(master)]$ git push
Counting objects: 5, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 340 bytes, done.
Total 3 (delta 2), reused 0 (delta 0)
To git@github.com:xxxx/foo.git
   885cc33..99abfd6  master -> master

Separately, I need to have a before_symlink deploy hook. How can I do this ?

share|improve this question
add comment

2 Answers

up vote 4 down vote accepted

It wasn't clear from your question if you have already tried the git aws.push option. You could refer a blog post on AWSBlog for deploying Rack based applications to AWS Elastic Beanstalk. To summarize the same, you can do it in the following easy steps:

  1. eb init
  2. eb start
  3. git aws.push

This, of course, requires you to download AWS Elastic Beanstalk command line tools.

AFAIK, AWS Elastic Beanstalk does not have an integration with Git deploy hooks yet, but it's pretty simple if you are already using a CI Server like Jenkins. Github can very well integrate with most CI servers. You could achieve a git push triggering git aws.push from your CI server by adding a new Jenkins job with custom Shell commands. You may also want to execute a test harness before pushing a fresh build out there. Jenkins or Travis CI will do the job for you!

Regarding the execution of before_symlink type tasks, the way AWS Elastic Beanstalk works is different from a traditional Capistrano deployment. It bundles all your code into an executable archive and simply copies it over to load-balanced nodes. For executing before_symlink like tasks, you might want to write some custom configuration files and place them under .ebextensions in the root path of your Git repository. The way I did it is by adding a .ebextensions/symlink.config file. Here's a sample code for symlinking your database.yml file on the server.

container_commands:
  symlink-db:
    command: ln -sf /var/app/shared/database.yml $EB_CONFIG_APP_ONDECK/config/database.yml

Please note that I am running a custom AMI with a /var/app/shared/ directory which, otherwise, is not present when you launch a vanilla Ruby container. Further, $EB_CONFIG_APP_ONDECK environment variable holds the current deployment directory name (typically /var/app/ondeck) which is moved to /var/app/current once the deployment is through and before restarting the Rails (Passenger) server, thus making it available for serving requests. Read more on Customizing AWS Elastic Beanstalk containers.

Hope this helps.

share|improve this answer
    
Thanks a lot. I will try this out –  Divya Bhargov Nov 26 '12 at 16:08
    
Hi, I have edited my question regarding git aws.push. Could you please take a look at that and tell me –  Divya Bhargov Nov 27 '12 at 3:37
    
I'm not sure if this is the best way, but I always did a git push followed by a git aws.push. Since my environment was set up with Jenkins CI, git push happened on my development machine whereas git aws.push happened from the CI server. –  rhetonik Nov 27 '12 at 4:43
    
Regarding the ebextensions.. is there a way I can debug why my command is not being executed. I tried symbolic link for database.yml that you have given... for some reason the symbolic link was not created. Any debug guidelines would be useful. I tried to run the command after the deployment by replacing $EB_CONFIG_APP_ONDECK to /var/app/current and the command as such worked. –  Divya Bhargov Nov 27 '12 at 10:48
    
I'm not aware of any debugging technique at the moment. I even tried to look for some, but could not find standard guidelines to do so. About the symbolic link, just confirming, do you have a /var/app/shared directory on the instance? Manual symlinking will always work. Did you check the value of EB_CONFIG_APP_ONDECK environment variable? Can you paste the output of echo $EB_CONFIG_APP_ONDECK? –  rhetonik Nov 28 '12 at 7:32
show 3 more comments

I was able to integrate Travis CI test builds with Amazon Beanstalk deployments. In order to do this i had to automate eb tools, because the current version 2.5.1 only runs in an interactive way, so I edited EB tools code on some python files and then created a .travis.yml file with the appropriate instructions to deploy the app to AWS Beanstalk.

Here is a link to my blog that gives a complete description of the process:

http://www.sysadminops.com/amazon-beanstalk-and-travis-ci-integration/

share|improve this answer
2  
Welcome to Superuser. I implore you to not let touting your blog be your only contribution to this site, however valuable a solution it may be. –  Mokubai Aug 3 '13 at 18:05
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.