Elastic Beanstalk Ruby 3.0.2

52 0



Dec 14, 2021

Copy and paste this code into your terminal

Video showing how to use

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 [email protected]
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

DISCLAIMER: You should always review templates before running them. By running the template, you are agreeing to the terms of use.

The contents of this script as show. Any updates will be reflected in the below code and the snippet.

run "bundle install"
run "bundle add eb_deployer"
run "bundle add webrick"
run "bundle add rails-healthcheck"
run "bundle 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"

# 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 database you will need to deploy two times, the first time will create the database, then you need to set the database creds as ENV vars so your app can connect to it'"

A place where you can thank the author, post problems, give constructive feedback, etc. Be nice!

  • Dave Kimura
    This is a cool script. I haven't seen much of any beanstalk templates.
    by Dave Kimura at 8:25PM, 14 Dec 2021