This README would normally document whatever steps are necessary to get the application up and running.
Things you may want to cover:
We're going to deploy to Elastic Beanstalk, so make sure you have your AWS account and Access Key ID/Secret ready
-
Clone this repo
git clone https://github.com/BenjaminBLi/e7-gear-optimizer.git
-
cd into directory and install everything
cd e7-gear-optimizer yarn install gem install bundler bundle install
-
Run rail server locally, check everything is fine
rails s
-
Create new secret key and store in config/secrets.yml (save this key for EB env var later)
export SECRET_KEY_BASE=$(rake secret) echo $SECRET_KEY_BASE
-
Precompile assets, run in production environment mode to double check its fine
rake assets:precompile rails s -e production
-
Download EB CLI
-
In root directory, run
eb init
and fill in any information.- If you have not provided your Access Key ID/Secret, it will ask for this information.
- Region is self explainatory
- Application does not matter the name, just a way to organize different versions
- Platform must be Ruby 2.7 running on 64bit Amazon Linux 2 (If you choose a existing application, this won't appear)
- SSH for you instances needs to be on, because we'll need it in step 6.
-
Run
eb create -s
to launch a single instance of the app. You can name the environment and DNS prefix anything you'd like.- Note: that
-s
just means it will launch on a single instance instead of with a load balancer. In production, we might need this later, but for right now, single instance should server us well (and save us cash)
- Note: that
-
Launch the instance. This will produce an Error code 1, which is fine.
-
Set the
SECRET_KEY_BASE
- use command line
eb setenv SECRET_KEY_BASE=$SECRET_KEY_BASE RAILS_SKIP_ASSET_COMPILATION=true RAILS_SKIP_MIGRATIONS=true
- might need
export RUBYOPT='-W:no-deprecated'
-
SSH into your instance using instance ec2-user and your Elastic Beanstalk DNS, Change the file in /etc/nginx/conf.d/elasticbeanstalk/webapp.conf
eb ssh
cd /etc/nginx/conf.d/elasticbeanstalk/ sudo vi webapp.conf
webapp.conf
server_name _ localhost; # need to listen to localhost for worker tier location / { proxy_pass http://my_app; # match the name of upstream directive which is defined above proxy_set_header Host $host; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } location /assets { alias /var/app/current/public/assets; gzip_static on; gzip on; expires max; add_header Cache-Control public; } location /packs { alias /var/app/current/public/packs; gzip_static on; gzip on; expires max; add_header Cache-Control public; } location /public { alias /var/app/current/public; gzip_static on; gzip on; expires max; add_header Cache-Control public; }
-
Restart nginx proxy server
sudo su service nginx restart
- Currently not sure if I can do this step automatically cause nginx overwrite my file I put here, and you might have to be in the nginx directory if you're having issues this restart