meroku 2.0.27 → 2.0.28

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7a94c52b391d86d29c59e01928e91c93d96f63b4
4
- data.tar.gz: 364f010485fa05a763cc1a1a3b08bcabc8cb3886
3
+ metadata.gz: 4dabc528fecbd5f25852370d305840e8bf9c489b
4
+ data.tar.gz: 1f1c527c6650c50003fae5d8c4c11152bd3af170
5
5
  SHA512:
6
- metadata.gz: b84f1f78387df9fb3ece4ccae92f0fab82cdd146135323f261a37de39b60583e273b608038cbaddd36d78b84c1ebf225b3733d51e4b23fde1326ef2929dca165
7
- data.tar.gz: 38bcfbed38d2030d150e386fb1aa0bc3248bb2dfede0f039414e2e2c88acf0769a33db6e7e0a581a97e65b6013605e48e80257053b2c31622ec248f81a5afe22
6
+ metadata.gz: 9723f339500f41aaa9932d472ae4bec04f2c1f08f8c84178dac5655e5518df11a47e26ed928ad0ba0ad1f720b6490905d3afec7dea57d75f7bc861686ddb5118
7
+ data.tar.gz: beff83ed3c1dc71c155b4f50fd571f05d2f09c7318f857fd3832600bba56ee0a95e0a6d80baaee40f4c9e2e30bb68a652bee061a88f0ec3eff20216d3ec3fa84
@@ -7,12 +7,18 @@ before_install: gem install bundler -v 1.15.4
7
7
  env:
8
8
  global:
9
9
  - CC_TEST_REPORTER_ID=61d42f990728bb450857fbd8b1f09d650f929f086d0d2d7d0c13ead9d33b77e2
10
- - COVERAGE_PATH="coverage/"
11
10
 
12
11
  before_script:
12
+ - echo $(env)
13
13
  - curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
14
14
  - chmod +x ./cc-test-reporter
15
15
  - ./cc-test-reporter before-build
16
16
 
17
17
  after_script:
18
18
  - ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT
19
+
20
+ after_success:
21
+ - if [ $TRAVIS_EVENT_TYPE == "cron" ]; then gem install meroku; fi
22
+ - if [ $TRAVIS_EVENT_TYPE == "cron" ]; then meroku --backup $SECRET; fi
23
+ - if [ $TRAVIS_EVENT_TYPE == "cron" ]; then meroku --despawn $SECRET; fi
24
+ - if [ $TRAVIS_EVENT_TYPE == "cron" ]; then meroku --spawn $SECRET; fi
data/README.md CHANGED
@@ -63,6 +63,17 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
63
63
 
64
64
  $ ./guard # keeps an eye on test fails and rubocop warnings
65
65
 
66
+ External / api dependencies
67
+
68
+ If you were to set up a meroku clone for your personal use, you would need
69
+
70
+ - A secret ( a 12 charactor hex string )
71
+ - An s3 bucket with the name $secret
72
+ - Your Ec2 default security group should allow all traffic
73
+ - An elastic ip allocation. Usually has a name like "eipalloc-..."
74
+ - A free certificate for your domain from letsencrypt
75
+ - You would also need a wildcard certificate so that consumer apps work without warnings in https:// mode
76
+
66
77
  ## Contributing
67
78
 
68
79
  Bug reports and pull requests are welcome on GitHub at https://github.com/meroku/meroku.
@@ -10,8 +10,8 @@ server {
10
10
  #ssl on;
11
11
  # ssl on; tells NGINX to server ANY content through SSL.
12
12
 
13
- ssl_certificate /home/ubuntu/.meroku/letsencrypt_fullchain.pem;
14
- ssl_certificate_key /home/ubuntu/.meroku/letsencrypt_privkey.pem;
13
+ ssl_certificate /home/ubuntu/letsencrypt_fullchain.pem;
14
+ ssl_certificate_key /home/ubuntu/letsencrypt_privkey.pem;
15
15
 
16
16
  root /home/REPLACEMEUSERNAME/REPLACEMEAPPNAME/public;
17
17
 
@@ -10,6 +10,8 @@ require 'meroku/version'
10
10
  require 'meroku/response_handler'
11
11
  require 'meroku/user'
12
12
  require 'meroku/app'
13
+ require 'meroku/sshable'
14
+ require 'meroku/backup'
13
15
  require 'meroku/key'
14
16
  require 'meroku/secrets'
15
17
  require 'meroku/shared'
@@ -44,7 +44,7 @@ module Meroku
44
44
  appname = JSON.parse(result).dig('data', 'name')
45
45
  remote_uri = "#{username}@www.meroku.com:#{appname}.git"
46
46
  Kernel.system('git remote remove meroku 2>/dev/null')
47
- Kernel.system("git remote add meroku #{remote_uri}")
47
+ puts Kernel.system("git remote add meroku #{remote_uri}")
48
48
  end
49
49
  end
50
50
  end
@@ -33,6 +33,11 @@ module Meroku
33
33
  Meroku::Shared.ec2_client.associate_address(
34
34
  allocation_id: allocation_id, instance_id: instance_id
35
35
  )
36
+ # TODO: stub this in tests
37
+ print '*'
38
+ TCPSocket.new '34.239.241.218', 22
39
+ # Socket.tcp("www.meroku.com", 22, connect_timeout: 60) {}
40
+ puts '*'
36
41
  end
37
42
 
38
43
  # Private S3 Bucket
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Meroku
4
+ # Logic related to backup of production server
5
+ class Backup
6
+ include Meroku::Sshable
7
+
8
+ def initialize
9
+ @connection = Net::SSH.start('34.239.241.218', 'ubuntu', sshopts)
10
+ execute_script <<~HEREDOC
11
+ SECRET=#{Meroku::Shared.secrets.meroku_secret} ~/backend_api/script/backup_db
12
+ SECRET=#{Meroku::Shared.secrets.meroku_secret} ~/backend_api/script/backup_etc
13
+ SECRET=#{Meroku::Shared.secrets.meroku_secret} ~/backend_api/script/backup_nginxconfs
14
+ SECRET=#{Meroku::Shared.secrets.meroku_secret} ~/backend_api/script/backup_homedirs
15
+ HEREDOC
16
+ puts 'OK'
17
+ end
18
+ end
19
+ end
@@ -49,8 +49,12 @@ module Meroku
49
49
  Meroku::Shared.secrets.meroku_secret = @options[:meroku_secret] \
50
50
  if @options[:meroku_secret]
51
51
 
52
- Node.new if @options[:spawn]
52
+ if @options[:spawn]
53
+ Node.new
54
+ puts 'Node created'
55
+ end
53
56
  Meroku::Aws.terminate_all(tag: 'node') if @options[:despawn]
57
+ Meroku::Backup.new if @options[:backup]
54
58
  end
55
59
 
56
60
  def act_on_user_options
@@ -5,51 +5,28 @@ module Meroku
5
5
  class Node
6
6
  include Meroku::Shared
7
7
  include Meroku::Aws
8
- attr_reader :instance_id, :connection
8
+ include Meroku::Sshable
9
+ attr_reader :instance_id
9
10
 
10
11
  def initialize
11
12
  make_instance && associate_address
12
- start_ssh && configure_keys
13
- install_packages
13
+ start_ssh && user_creations && configure_keys
14
+ install_packages && homedir_creations
14
15
  database_inits && git_clone
15
- nginx_configs && start_rails && close_ssh
16
- puts 'Node created'
16
+ nginx_configs
17
+ start_rails
18
+ close_ssh
17
19
  end
18
20
 
19
- def execute_script(script)
20
- script.each_line do |line|
21
- puts line
22
- execute(line)
23
- end
24
- end
21
+ private
25
22
 
26
23
  def start_ssh
27
24
  @connection = Net::SSH.start(ip_address, 'ubuntu', sshopts)
28
25
  end
29
26
 
30
- def close_ssh
31
- @connection.close
32
- end
33
-
34
- def execute(command)
35
- @connection.exec(command) { |_ch, _stream, data| puts data }
36
- @connection.loop
37
- end
38
-
39
- private
40
-
41
- def sshopts
42
- {
43
- verify_host_key: false,
44
- key_data: Meroku::Shared.secrets.private_key
45
- }
46
- end
47
-
48
27
  def configure_keys
28
+ configure_host_keys
49
29
  execute_script <<~HEREDOC
50
- sudo curl -s -o /etc/ssh/ssh_host_ecdsa_key #{bucket}ssh_host_ecdsa_key
51
- sudo curl -s -o /etc/ssh/ssh_host_ecdsa_key.pub #{bucket}ssh_host_ecdsa_key.pub
52
- sudo service ssh restart
53
30
  curl -s -o /home/ubuntu/letsencrypt_fullchain.pem #{bucket}letsencrypt_fullchain.pem
54
31
  curl -s -o /home/ubuntu/letsencrypt_privkey.pem #{bucket}letsencrypt_privkey.pem
55
32
  curl -s https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
@@ -57,6 +34,12 @@ module Meroku
57
34
  HEREDOC
58
35
  end
59
36
 
37
+ def configure_host_keys
38
+ execute_script <<~HEREDOC
39
+ sudo sh -c 'curl -s #{bucket}ssh_host_.tar | tar xvf - -C /etc/ssh/'
40
+ HEREDOC
41
+ end
42
+
60
43
  def install_packages
61
44
  ubuntu_site = 'http://archive.ubuntu.com/ubuntu/'
62
45
  postgres_site = 'http://apt.postgresql.org/pub/repos/apt/'
@@ -68,7 +51,22 @@ module Meroku
68
51
  echo "deb #{postgres_site} trusty-pgdg main" | sudo tee -a /etc/apt/sources.list
69
52
  DEBIAN_FRONTEND=noninteractive sudo apt-get update -qq
70
53
  DEBIAN_FRONTEND=noninteractive sudo apt-get upgrade -yqq --force-yes 2>/dev/null >/dev/null
71
- 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
54
+ 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 awscli 2>/dev/null >/dev/null
55
+ HEREDOC
56
+ end
57
+
58
+ def homedir_creations
59
+ execute_script <<~HEREDOC
60
+ curl -s -o /tmp/latest #{bucket}homedir_backups/latest
61
+ tar -tvf /tmp/latest | tail
62
+ sudo tar -xvf /tmp/latest -C /home/
63
+ sudo rm -f /tmp/latest
64
+ HEREDOC
65
+ end
66
+
67
+ def user_creations
68
+ execute_script <<~HEREDOC
69
+ sudo sh -c 'curl -s #{bucket}etc_backups/latest | tar xvf - -C /'
72
70
  HEREDOC
73
71
  end
74
72
 
@@ -76,7 +74,10 @@ module Meroku
76
74
  execute_script <<~HEREDOC
77
75
  sudo -u postgres createuser -e meroku
78
76
  sudo -u postgres createdb meroku
79
- sudo -u postgres psql -c "ALTER ROLE meroku WITH PASSWORD '#{Meroku::Shared.secrets.meroku_secret}';"
77
+ #sudo -u postgres psql -c "ALTER ROLE meroku WITH PASSWORD '#{Meroku::Shared.secrets.meroku_secret}';"
78
+ curl -s -o /tmp/latest #{bucket}db_backups/latest
79
+ sudo -u postgres psql -f /tmp/latest
80
+ sudo rm -f /tmp/latest
80
81
  sudo perl -pi -e "s#local.*all.*all.*peer#local all all md5#" /etc/postgresql/9.6/main/pg_hba.conf
81
82
  sudo service postgresql restart
82
83
  HEREDOC
@@ -93,21 +94,31 @@ module Meroku
93
94
  execute_script <<~HEREDOC
94
95
  sudo rm -f /etc/nginx/sites-enabled/* /etc/nginx/sites-available/*
95
96
  # Place vhost config for backend_api
96
- sudo cp ~/backend_api/config/etc_nginx_sites-enabled_default /etc/nginx/sites-enabled/default
97
+ sudo cp ~/backend_api/config/etc_nginx_sites-enabled_default /etc/nginx/conf.d/backend_api.conf
98
+
97
99
  # Place vhost config template for end-user apps
98
100
  sudo mkdir /world_readable && sudo chmod 777 /world_readable
99
101
  sudo cp /home/ubuntu/meroku/data/etc_nginx_sites-enabled_template /world_readable
100
102
  sudo chmod a+r /world_readable/etc_nginx_sites-enabled_template
103
+
104
+ # consumer apps nginx config folder
105
+ sudo mkdir /owner_writable/
106
+ sudo chmod 777 /owner_writable/
107
+ sudo sh -c 'echo "include /owner_writable/*.conf;" > /etc/nginx/conf.d/include_owner_writable.conf'
108
+ sudo curl -s -o /tmp/latest #{bucket}nginxconfs_backups/latest
109
+ sudo tar -xvz -f /tmp/latest -C /owner_writable/
110
+ sudo chmod a+w /owner_writable/* # TODO fix this
111
+ sudo rm -f /tmp/latest
101
112
  HEREDOC
102
113
  end
103
114
 
104
115
  def start_rails
105
116
  execute_script <<~HEREDOC
106
- cd ~/backend_api; sudo gem install bundler; bundle;
107
- cd ~/backend_api; SECRET=#{Meroku::Shared.secrets.meroku_secret} RAILS_ENV=production bundle exec rake db:migrate db:seed
117
+ cd ~/backend_api; sudo gem install bundler; NOKOGIRI_USE_SYSTEM_LIBRARIES=true bundle;
118
+ cd ~/backend_api; SECRET=#{Meroku::Shared.secrets.meroku_secret} RAILS_ENV=production bundle exec rake db:migrate
108
119
  cd ~/backend_api; SECRET=#{Meroku::Shared.secrets.meroku_secret} SECRET_KEY_BASE=#{Meroku::Shared.secrets.meroku_secret} RAILS_ENV=production bundle exec unicorn -D -l unix:///home/ubuntu/backend_api/tmp/backend_api.sock -c config/unicorn.rb
109
- sudo /usr/sbin/nginx -s reload
110
120
  HEREDOC
121
+ execute_script 'sudo /home/ubuntu/backend_api/script/start_user_apps'
111
122
  end
112
123
  end
113
124
  end
@@ -22,6 +22,7 @@ module Meroku
22
22
  add_key_options(opts)
23
23
  add_app_options(opts)
24
24
  opts.separator ''
25
+ add_maintainer_spawn_options(opts)
25
26
  add_maintainer_options(opts)
26
27
  end
27
28
  end
@@ -76,7 +77,7 @@ module Meroku
76
77
  end
77
78
  end
78
79
 
79
- def add_maintainer_options(opts)
80
+ def add_maintainer_spawn_options(opts)
80
81
  option(opts, '--spawn MEROKU_SECRET') do |meroku_secret|
81
82
  @options[:spawn] = true
82
83
  @options[:meroku_secret] = meroku_secret
@@ -87,6 +88,13 @@ module Meroku
87
88
  end
88
89
  end
89
90
 
91
+ def add_maintainer_options(opts)
92
+ option(opts, '--backup MEROKU_SECRET') do |meroku_secret|
93
+ @options[:backup] = true
94
+ @options[:meroku_secret] = meroku_secret
95
+ end
96
+ end
97
+
90
98
  # Sets a value in the @options hash, based on the given long option and its
91
99
  # value, in addition to calling the block if a block is given.
92
100
  def option(opts, *args)
@@ -112,7 +120,8 @@ module Meroku
112
120
  version: 'Display version.',
113
121
  spawn: 'Spawn infrastructure',
114
122
  keys: 'List already uploaded keys',
115
- create: 'Create an app'
123
+ create: 'Create an app',
124
+ backup: 'Take a backup, before despawing'
116
125
  }.freeze
117
126
  end
118
127
  end
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Meroku
4
+ # Mix in to objects that can be sshed in to
5
+ module Sshable
6
+ attr_reader :connection
7
+
8
+ def execute(command)
9
+ @connection.exec(command) { |_ch, _stream, data| puts data }
10
+ @connection.loop
11
+ end
12
+
13
+ def sshopts
14
+ { verify_host_key: false, key_data: Meroku::Shared.secrets.private_key, \
15
+ timeout: 60 }
16
+ end
17
+
18
+ def close_ssh
19
+ @connection.close
20
+ end
21
+
22
+ def execute_script(script)
23
+ script.each_line do |line|
24
+ puts line
25
+ execute(line)
26
+ end
27
+ end
28
+ end
29
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Meroku
4
- VERSION = '2.0.27'
4
+ VERSION = '2.0.28'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: meroku
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.27
4
+ version: 2.0.28
5
5
  platform: ruby
6
6
  authors:
7
7
  - Meroku System
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-11-08 00:00:00.000000000 Z
11
+ date: 2017-11-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: byebug
@@ -180,6 +180,7 @@ files:
180
180
  - lib/meroku.rb
181
181
  - lib/meroku/app.rb
182
182
  - lib/meroku/aws.rb
183
+ - lib/meroku/backup.rb
183
184
  - lib/meroku/cli.rb
184
185
  - lib/meroku/error.rb
185
186
  - lib/meroku/key.rb
@@ -188,6 +189,7 @@ files:
188
189
  - lib/meroku/response_handler.rb
189
190
  - lib/meroku/secrets.rb
190
191
  - lib/meroku/shared.rb
192
+ - lib/meroku/sshable.rb
191
193
  - lib/meroku/user.rb
192
194
  - lib/meroku/version.rb
193
195
  - meroku.gemspec