WhyAyala
WhyAyala

Reputation: 675

Rails app fails to deploy on elastic beanstalk

I have a Rails 4 app using ruby 2.3 that I want to deploy using AWS Ebs. I'm pointing the db connection to an existing db, I'm using the cli to initialize and create. When I get to the create part i keep getting an error message that says:

Hook /opt/elasticbeanstalk/hooks/appdeploy/pre/12_db_migration.sh failed. For more detail, check /var/log/eb-activity.log using console or EB CLI.

Which of course means the migration failed. When i checked the logs it says tables already exist, I did some research and found you can include settings in .ebextensions/ to specify not to run migrations or run bundle on test and dev. Here is my .ebextensions/ruby-settings.config:

option_settings: BUNDLE_WITHOUT: "test:development" RAILS_ENV: production RACK_ENV: production RAILS_SKIP_MIGRATIONS: true

However it still fails to deploy and gives the same error message. Question is, what am i doing wrong here? I've tried rewriting this config file different ways based on tutorials i found on this blog and the AWS docs page here.

Any thoughts on what I'm doing wrong are helpful as i am at a loss currently.

Upvotes: 1

Views: 1270

Answers (3)

Inx Maurya
Inx Maurya

Reputation: 1155

filename: 0000.config

files:
  "/opt/elasticbeanstalk/hooks/appdeploy/pre/02b_set_env_vars.sh":
    mode: "000755"
    owner: root
    group: root
    content: |
      #!/bin/bash
      EB_APP_STAGING_DIR=$(/opt/elasticbeanstalk/bin/get-config container -k app_staging_dir)
      cd $EB_APP_STAGING_DIR
      ./set-env.sh

and there are some errors like -

  1. Hook /opt/elasticbeanstalk/hooks/appdeploy/pre/12_db_migration.sh failed
  2. ./set-env.sh not found

go inside /opt/elasticbeanstalk/hooks/configdeploy/pre/<>_setup_envvars.sh

Copy last two lines -

EB_SUPPORT_DIR=$(/opt/elasticbeanstalk/bin/get-config container -k support_dir) $EB_SUPPORT_DIR/export_envvars

and Paste into 0000.config - now the file look like-

filename: 0000.config

files:
  "/opt/elasticbeanstalk/hooks/appdeploy/pre/02b_set_env_vars.sh":
    mode: "000755"
    owner: root
    group: root
    content: |
      #!/bin/bash
      EB_SUPPORT_DIR=$(/opt/elasticbeanstalk/bin/get-config container -k support_dir)
      $EB_SUPPORT_DIR/export_envvars

Upvotes: 0

WhyAyala
WhyAyala

Reputation: 675

I found that the answer to my problem was that i had added .ebextensions to my .gitignore. Early in the process of deployment .elasticbeanstalk had been added to ignore and I assumed the same needed to be done to .ebextensions. A minor oversight that led to a lot of frustration.

It is worth noting that when I did have a spacing issue in my config files, the ebcli threw an error at me. I believe that what error2007s posted was valid, however other formats are acceptable. For example, here is my current format for one of my config files:

option_settings:
  aws:ec2:vpc:
    VPCId: vpc-xxxxxxxx
    Subnets: subnet-yyyyyyy,subnet-zzzzzzzz,subnet-wwwwwww,subnet-eeeeeeeee
  aws:autoscaling:launchconfiguration:
    SecurityGroups: sg-00000000

etc...

I would also recommend using .ebextensions to set your environment variables, as I did:

option_settings:
  aws:elasticbeanstalk:application:environment:
    RAILS_SKIP_MIGRATIONS: true
    RAILS_ENV: production

Upvotes: 0

Piyush Patil
Piyush Patil

Reputation: 14543

Change your ruby-settings.config to below and then try the migration.

option_settings:
        - option_name: BUNDLE_WITHOUT
          value: "test:development"
        - option_name: RAILS_ENV
          value: "production"
        - option_name: RACK_ENV
          value: "production"
        - option_name: RAILS_SKIP_MIGRATIONS
          value: "true"

Upvotes: 3

Related Questions