Class: Meroku::Node
Overview
At the moment we run on one ec2 node This class represents that node
Instance Method Summary
collapse
Methods included from Tunnelable
#tunnel_run
Methods included from Aws::Ec2
associate_address, #ec2_client, ec2_client, #make_instance, #tag
Constructor Details
#initialize ⇒ Node
Returns a new instance of Node
8
9
10
11
12
13
14
15
16
17
18
|
# File 'lib/meroku/node.rb', line 8
def initialize
puts "run_instances()"
@instance = make_instance
@tunnel_ip = Meroku::Aws::IP
@tunnel_username = "ubuntu"
@tunnel_password = "password"
@tunnel_key_name = Meroku::Aws::KEY_NAME
print "sleep "
30.times { print sleep(1) }
print "\n"
end
|
Instance Method Details
#add_sources ⇒ Object
39
40
41
42
43
44
45
46
47
48
49
50
|
# File 'lib/meroku/node.rb', line 39
def add_sources
str = <<~HEREDOC
echo "Dpkg::Use-Pty "0";" | sudo tee /etc/apt/apt.conf.d/00usepty
sudo apt-add-repository ppa:brightbox/ruby-ng --yes 2>/dev/null >/dev/null
echo "deb http://archive.ubuntu.com/ubuntu/ trusty main universe" | sudo tee -a /etc/apt/sources.list
echo "deb http://archive.ubuntu.com/ubuntu/ trusty-security main universe" | sudo tee -a /etc/apt/sources.list
echo "deb http://archive.ubuntu.com/ubuntu/ trusty-updates main universe" | sudo tee -a /etc/apt/sources.list
echo "deb http://apt.postgresql.org/pub/repos/apt/ trusty-pgdg main" | sudo tee -a /etc/apt/sources.list
HEREDOC
str.split("\n").each { |cmd| tunnel_run(cmd) }
self
end
|
#associate_address ⇒ Object
20
21
22
23
24
|
# File 'lib/meroku/node.rb', line 20
def associate_address
ip = "eipalloc-139f7823"
Meroku::Aws::Ec2.associate_address(ip, @instance.instance_id)
self
end
|
26
27
28
29
30
31
32
33
34
35
36
37
|
# File 'lib/meroku/node.rb', line 26
def configure_keys
str = <<~HEREDOC
mkdir /home/ubuntu/.meroku
sudo curl -s -o /etc/ssh/ssh_host_ecdsa_key #{Meroku::Aws.bucket_url}/ssh_host_ecdsa_key
sudo curl -s -o /etc/ssh/ssh_host_ecdsa_key.pub #{Meroku::Aws.bucket_url}/ssh_host_ecdsa_key.pub
curl -s -o /home/ubuntu/.meroku/letsencrypt_fullchain.pem #{Meroku::Aws.bucket_url}/letsencrypt_fullchain.pem
curl -s -o /home/ubuntu/.meroku/letsencrypt_privkey.pem #{Meroku::Aws.bucket_url}/letsencrypt_privkey.pem
curl -s https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
HEREDOC
str.split("\n").each { |cmd| tunnel_run(cmd) }
self
end
|
#database_inits ⇒ Object
69
70
71
72
73
74
75
76
77
78
79
|
# File 'lib/meroku/node.rb', line 69
def database_inits
str = <<~HEREDOC
sudo -u postgres createuser -e meroku
sudo -u postgres createdb meroku
sudo -u postgres psql -c "ALTER ROLE meroku WITH PASSWORD '#{ENV['SECRET']}';"
sudo perl -pi -e "s#local.*all.*all.*peer#local all all md5#" /etc/postgresql/9.6/main/pg_hba.conf
sudo service postgresql restart
HEREDOC
str.split("\n").each { |cmd| tunnel_run(cmd) }
self
end
|
#git_clone ⇒ Object
81
82
83
84
85
86
87
|
# File 'lib/meroku/node.rb', line 81
def git_clone
str = <<~HEREDOC
cd ~; git clone https://github.com/meroku/meroku;
HEREDOC
str.split("\n").each { |cmd| tunnel_run(cmd) }
self
end
|
#install_packages ⇒ Object
61
62
63
64
65
66
67
|
# File 'lib/meroku/node.rb', line 61
def install_packages
str = <<~HEREDOC
DEBIAN_PRIORITY=critical DEBIAN_FRONTEND=noninteractive sudo apt-get install -q -y -o "Dpkg::Options::=--force-confdef" -o "Dpkg::Options::=--force-confold" autoconf bind9-host bison build-essential coreutils curl daemontools dnsutils ed git imagemagick iputils-tracepath language-pack-en libbz2-dev libcurl4-openssl-dev libev-dev libevent-dev libglib2.0-dev libjpeg-dev libmagickwand-dev libmysqlclient-dev libncurses5-dev librdkafka-dev libreadline6-dev libssl-dev libuv-dev libxml2-dev libxslt-dev netcat-openbsd openjdk-7-jdk openjdk-7-jre-headless openssh-client openssh-server python python-dev socat stunnel syslinux tar telnet zip zlib1g-dev ruby2.4 ruby2.4-dev nginx libsqlite3-dev nodejs libpq-dev postgresql-9.6 2>/dev/null >/dev/null
HEREDOC
str.split("\n").each { |cmd| tunnel_run(cmd) }
self
end
|
#nginx_configs ⇒ Object
89
90
91
92
93
94
95
96
97
98
99
|
# File 'lib/meroku/node.rb', line 89
def nginx_configs
str = <<~HEREDOC
sudo rm -f /etc/nginx/sites-enabled/* /etc/nginx/sites-available/*
sudo cp ~/meroku/frontend/etc_nginx_sites-enabled_default /etc/nginx/sites-enabled/default
sudo mkdir /sharedro && sudo chmod 777 /sharedro
sudo cp /home/ubuntu/meroku/frontend/etc_nginx_sites-enabled_template /sharedro
sudo chmod a+r /sharedro/etc_nginx_sites-enabled_template
HEREDOC
str.split("\n").each { |cmd| tunnel_run(cmd) }
self
end
|
#start_rails ⇒ Object
101
102
103
104
105
106
107
108
109
110
111
|
# File 'lib/meroku/node.rb', line 101
def start_rails
str = <<~HEREDOC
cd ~/meroku/frontend; sudo gem install bundler; bundle;
cd ~/meroku/frontend; SECRET=#{ENV['SECRET']} RAILS_ENV=production bundle exec rails assets:precompile
cd ~/meroku/frontend; SECRET=#{ENV['SECRET']} RAILS_ENV=production bundle exec rake db:migrate
cd ~/meroku/frontend; SECRET=#{ENV['SECRET']} bundle exec puma -d -b unix:///home/ubuntu/meroku.sock
sudo /usr/sbin/nginx -s reload
HEREDOC
str.split("\n").each { |cmd| tunnel_run(cmd) }
self
end
|
#ubuntu_updates ⇒ Object
52
53
54
55
56
57
58
59
|
# File 'lib/meroku/node.rb', line 52
def ubuntu_updates
str = <<~HEREDOC
DEBIAN_FRONTEND=noninteractive sudo apt-get update -qq
DEBIAN_FRONTEND=noninteractive sudo apt-get upgrade -yqq --force-yes 2>/dev/null >/dev/null
HEREDOC
str.split("\n").each { |cmd| tunnel_run(cmd) }
self
end
|