-
Notifications
You must be signed in to change notification settings - Fork 3
/
provision.sh
executable file
·99 lines (81 loc) · 2.94 KB
/
provision.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#
# imgclass.com provisioning script
#
# Oct 15, 2017
#
# This script:
# * Installs dependencies
# * Installs Rails, Ruby, rbenv, nodejs, nginx, passenger
# * Configures nginx to serve this application
#
#
# Tested on Ubuntu 16.04 t2.micro instances.
#
#
# Before running this script, create a deploy user:
#
# >> sudo adduser deploy --gecos ""
# >> sudo adduser deploy sudo
# >> su deploy
# Store initial directory for use later
INITIAL_DIRECTORY="$PWD"
# Copy over the authorized public keys in the ubuntu user's .ssh directory
cd ~
mkdir .ssh
sudo cp /home/ubuntu/.ssh/authorized_keys .ssh/
chmod 700 .ssh
sudo chown deploy .ssh/authorized_keys
sudo chmod 600 .ssh/authorized_keys
# Create deployment folders for Capistrano/Rails
sudo mkdir /var/www
sudo chown deploy /var/www
sudo mkdir /var/db
sudo chown deploy /var/db
# Update and get dependencies
sudo apt-get update -y
sudo apt-get install git-core curl zlib1g-dev build-essential libssl-dev libreadline-dev libyaml-dev libsqlite3-dev sqlite3 libxml2-dev libxslt1-dev libcurl4-openssl-dev python-software-properties libffi-dev nodejs libpq-dev nginx -y
# Install rbenv
cd
git clone https://github.com/rbenv/rbenv.git ~/.rbenv
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bash_profile
echo 'eval "$(rbenv init -)"' >> ~/.bash_profile
source ~/.bash_profile
# Install rbenv plugin ruby-build
git clone https://github.com/rbenv/ruby-build.git ~/.rbenv/plugins/ruby-build
echo 'export PATH="$HOME/.rbenv/plugins/ruby-build/bin:$PATH"' >> ~/.bash_profile
source ~/.bash_profile
# Install ruby
rbenv install 2.4.1
rbenv global 2.4.1
ruby -v
# Install bundler
gem install bundler
rbenv rehash
# Install nodejs
curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash -
sudo apt-get install -y nodejs
# Install rbenv-sudo
git clone git://github.com/dcarley/rbenv-sudo.git ~/.rbenv/plugins/rbenv-sudo
# Install passenger and nginx
sudo apt-get install -y dirmngr gnupg
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 561F9B9CAC40B2F7
sudo apt-get install -y apt-transport-https ca-certificates
sudo sh -c 'echo deb https://oss-binaries.phusionpassenger.com/apt/passenger xenial main > /etc/apt/sources.list.d/passenger.list'
sudo apt-get update -y
sudo apt-get install -y nginx-extras passenger
# Configure passenger/nginx
sudo sed -i 's|# include /etc/nginx/passenger.conf|include /etc/nginx/passenger.conf|' /etc/nginx/nginx.conf
sudo sed -i 's|#include /etc/nginx/passenger.conf|include /etc/nginx/passenger.conf|' /etc/nginx/nginx.conf
cd $INITIAL_DIRECTORY
sudo cp ./accessory/imgclass.conf /etc/nginx/sites-enabled/
# Remove default NGINX page
sudo rm /etc/nginx/sites-enabled/default
# Restart
sudo service nginx restart
# At this point, on your workstation you may use:
# >> cap production deploy
# which will push the code to the server.
#bundle install --without development test
#RAILS_ENV=production rails db:create
#RAILS_ENV=production rails db:schema:load
#RAILS_ENV=production rails db:seed