Last active
November 17, 2022 23:07
-
-
Save omenking/506054d219184edecfab46cb73101d8b to your computer and use it in GitHub Desktop.
Super High Value Plus Ruby on Rails Amazon Linux 2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
su ec2-user | |
sudo yum -y update | |
sudo yum install -y git redhat-rpm-config sqlite-devel | |
# Install RVM and Ruby | |
# KEY1 and KEY1 grab from: https://rvm.io/ | |
gpg --keyserver hkp://keys.gnupg.net --recv-keys KEY1 KEY2 | |
curl -sSL https://get.rvm.io | bash -s stable | |
export rvmsudo_secure_path=1 | |
source /home/ec2-user/.rvm/scripts/rvm | |
rvm install 2.4.4 | |
# Extra Packages for Enterprise Linux (EPEL) for NodeJs and Postgres | |
#sudo yum install -y https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm | |
sudo yum install -y https://mirror.csclub.uwaterloo.ca/fedora/epel/epel-release-latest-7.noarch.rpm | |
sudo yum-config-manager --enable epel | |
# Rails requires a Javascript Runtime because of of execjs | |
# Not in Amazon's repo so using epel to install | |
# https://github.com/rails/execjs | |
sudo yum install -y nodejs npm --enablerepo=epel | |
# Install CodeDeploy Agent | |
sudo yum install ruby -y | |
wget https://aws-codedeploy-us-east-1.s3.amazonaws.com/latest/install | |
chmod +x ./install | |
sudo ./install auto | |
rm install | |
# Install Postgres | |
sudo yum install -y https://download.postgresql.org/pub/repos/yum/10/redhat/rhel-7-x86_64/pgdg-redhat10-10-2.noarch.rpm | |
sudo sed -i "s/rhel-\$releasever-\$basearch/rhel-latest-x86_64/g" "/etc/yum.repos.d/pgdg-10-redhat.repo" | |
sudo yum install -y postgresql10-server postgresql10 postgresql10-devel --enablerepo=epel | |
# Configure Postgres | |
sudo /usr/pgsql-10/bin/postgresql-10-setup initdb | |
sudo systemctl start postgresql-10.service | |
sudo systemctl enable postgresql-10.service | |
# Install Gems | |
gem install bundler | |
gem install pg -v '1.1.4' -- --with-pg-config=/usr/pgsql-10/bin/pg_config | |
# Checkout Repo and Configure | |
git clone https://GITHUB-NAME:PERSONAL-ACCESS-TOKEN@github.com/GITHUB-REPO-ACCOUNT/GITHUB-REPO-NAME.git app | |
cd /home/ec2-user/app | |
bundle install --without development test | |
# !!!!Remove .git, dont want to leave behind our access token | |
rm -rf /home/ec2-user/app/.git | |
# Generate SECRET_KEY_BASE | |
bundle exec rake secret | |
# Add Configuration Script | |
aws s3 cp s3://BUCKET-NAME/config/application.production.yml /home/ec2-user/app/config/application.yml | |
#Precompile Assets | |
RAILS_ENV=production bundle exec rails assets:precompile | |
#Run Migrations | |
RAILS_ENV=production bundle exec rails db:migrate | |
# Test Server | |
rvmsudo bundle exec rails s -b 0.0.0.0 -p 80 -d -e production | |
# Install and Update Services | |
sudo cp /home/ec2-user/app/config/puma.service.example /lib/systemd/system/puma.service | |
sudo systemctl daemon-reload | |
# Start Services | |
sudo service puma start | |
sudo systemctl enable puma.service |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment