3

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 ?

2 Answers2

5

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.

rhetonik
  • 166
0

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/

Mokubai
  • 95,412
Oskar
  • 1