Elastic Beanstalk Ruby 3.0.2

Adds elastic beanstalk config to your project
Icons/chart bar
Used 65 times
Created by
J Jeremiah Parrack

Usage
Video showing how to use
https://www.youtube.com/watch?v=zQPtMq2s7-w


64bit Amazon Linux 2 v3.4.0 running Ruby 3.0

This requires RAILS_ENV, and RAILS_MASTER_KEY and database creds to be set as env vars

If you havent already run 
`rails credentials:edit` to create your master key. Then `rails credentials:edit --environment=staging` to set your staging env creds. 


Now export:
```
export RAILS_MASTER_KEY="545b...530";
export ENVIRONMENT=staging;
export RAILS_ENV=staging;
export DATABASE_HOST=yourdbhost.us-east-1.rds.amazonaws.com;
export DATABASE=jumpstart;
export DATABASE_USERNAME=jumpstart;
export DATABASE_PASSWORD=jumpstarttest;
export AWS_ACCESS_KEY_ID=your_aws_key;
export AWS_SECRET_ACCESS_KEY=your_aws_secret_key;
```

zip up your app and deploy 

git ls-files | zip app.zip -@
eb_deploy -p app.zip -e dev


The aws solution stack version changes frequently so if this fails initially it will print out available stack names copy one of those then go to config/eb_deployer.yml and look for solution_stack and paste

Run this command in your Rails app directory in the terminal:

rails app:template LOCATION="https://railsbytes.com/script/zOvsLn"
Template Source

Review the code before running this template on your machine.

def do_bundle
  # Custom bundle command ensures dependencies are correctly installed
  Bundler.with_unbundled_env { run "bundle install" }
end

run "bundle add eb_deployer"
run "bundle add webrick"
run "bundle add rails-healthcheck"
do_bundle

run "rails generate healthcheck:install"
# generate eb_deployer config file
run "eb_deploy"

# clone beanstalk_dotfiles
run "git clone https://github.com/jeremiahlukus/beanstalk_dotfiles.git"
# move files into root project
run "mv beanstalk_dotfiles/.ebextensions/ ."
run "mv beanstalk_dotfiles/.platform/ ."

# add stack to line 8 on eb_deployer.yaml
run "sed -i -e '8r beanstalk_dotfiles/stack.yaml' config/eb_deployer.yml"
# add db and redis env vars and instance profile to beanstalk env
run "sed -i -e '117r beanstalk_dotfiles/standard_setup.yaml' config/eb_deployer.yml"

run "sed -i -e '18r beanstalk_dotfiles/puma_config.rb' config/puma.rb"
# change to a bigger ec2
run "sed -i -e 's/m1.small/c3.large/g' config/eb_deployer.yml"
# latest supported aws ruby version 
run "echo '3.0.2' > .ruby-version"

if yes?("Do you want to setup an RDS? [y/n]")
  run "mv beanstalk_dotfiles/cf_rds.json config/cf_rds.json"
  run "mv beanstalk_dotfiles/example_deploy.sh ."
  run "sed -i -e '166r beanstalk_dotfiles/rds.yml' config/eb_deployer.yml"
  run "sed -i -e 's/dev/staging/g' config/eb_deployer.yml"
  run "sed -i -e '67r beanstalk_dotfiles/database.yml' config/database.yml"
  run "rm -f config/database.yml-e"
end

# clean up
run "rm -f config/puma.rb-e"
run "rm -rf beanstalk_dotfiles/"
run "rm -f config/eb_deployer.yml-e"

run "echo 'If you chose to create a databaase you will need to deploy two times, the first time will creaate the dtabase, then you need to set the databaase creds as ENV vars so your app can connect to it'"
Comments

Sign up or Login to leave a comment.