meroku 2.0.8 → 2.0.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (81) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +9 -5
  3. data/bin/meroku +1 -1
  4. data/circle.yml +23 -0
  5. data/frontend/Gemfile +5 -2
  6. data/frontend/Gemfile.lock +5 -2
  7. data/frontend/app/controllers/application_controller.rb +1 -0
  8. data/frontend/app/controllers/apps_controller.rb +46 -48
  9. data/frontend/app/controllers/publickeys_controller.rb +45 -46
  10. data/frontend/app/controllers/users/registrations_controller.rb +0 -15
  11. data/frontend/app/controllers/users/sessions_controller.rb +12 -3
  12. data/frontend/app/lib/cmd.rb +11 -0
  13. data/frontend/app/models/app.rb +18 -11
  14. data/frontend/app/models/publickey.rb +1 -1
  15. data/frontend/app/models/user.rb +5 -4
  16. data/frontend/app/policies/application_policy.rb +53 -0
  17. data/frontend/app/policies/publickey_policy.rb +7 -0
  18. data/frontend/app/serializable/serializable_user.rb +2 -1
  19. data/frontend/app/views/layouts/application.html.erb +1 -1
  20. data/frontend/config/database.yml +72 -10
  21. data/frontend/config/routes.rb +6 -14
  22. data/frontend/db/migrate/20171028150506_add_apisecret_to_users.rb +6 -0
  23. data/frontend/etc_nginx_sites-enabled_default +1 -1
  24. data/frontend/public/Meroku.html +140 -0
  25. data/frontend/public/Meroku/Api.html +129 -0
  26. data/frontend/public/Meroku/Api/Request.html +221 -0
  27. data/frontend/public/Meroku/Aws.html +212 -0
  28. data/frontend/public/Meroku/Aws/Ec2.html +477 -0
  29. data/frontend/public/Meroku/CLI.html +784 -0
  30. data/frontend/public/Meroku/CLI/AdminUser.html +192 -0
  31. data/frontend/public/Meroku/CLI/Help.html +224 -0
  32. data/frontend/public/Meroku/CLI/Secrets.html +191 -0
  33. data/frontend/public/Meroku/CLI/Session.html +460 -0
  34. data/frontend/public/Meroku/CLI/User.html +182 -0
  35. data/frontend/public/Meroku/Extensions.html +405 -0
  36. data/frontend/public/Meroku/Infrastructure.html +279 -0
  37. data/frontend/public/Meroku/Infrastructure/Node.html +785 -0
  38. data/frontend/public/Meroku/Infrastructure/Server.html +373 -0
  39. data/frontend/public/Meroku/Node.html +845 -0
  40. data/frontend/public/Meroku/Tunnel.html +701 -0
  41. data/frontend/public/Meroku/Tunnelable.html +243 -0
  42. data/frontend/public/_index.html +273 -0
  43. data/frontend/public/class_list.html +51 -0
  44. data/frontend/public/css/common.css +1 -0
  45. data/frontend/public/css/full_list.css +58 -0
  46. data/frontend/public/css/style.css +492 -0
  47. data/frontend/public/file.README.html +181 -0
  48. data/frontend/public/file_list.html +56 -0
  49. data/frontend/public/frames.html +17 -0
  50. data/frontend/public/index.html +181 -0
  51. data/frontend/public/js/app.js +248 -0
  52. data/frontend/public/js/full_list.js +216 -0
  53. data/frontend/public/js/jquery.js +4 -0
  54. data/frontend/public/method_list.html +395 -0
  55. data/frontend/public/robots.txt +2 -1
  56. data/frontend/public/top-level-namespace.html +110 -0
  57. data/frontend/test/policies/publickey_policy_test.rb +19 -0
  58. data/lib/meroku.rb +9 -7
  59. data/lib/meroku/api.rb +8 -0
  60. data/lib/meroku/api/request.rb +17 -0
  61. data/lib/meroku/aws.rb +14 -0
  62. data/lib/meroku/aws/ec2.rb +59 -0
  63. data/lib/meroku/cli.rb +80 -81
  64. data/lib/meroku/cli/help.rb +27 -0
  65. data/lib/meroku/cli/secrets.rb +13 -0
  66. data/lib/meroku/cli/session.rb +32 -51
  67. data/lib/meroku/extensions.rb +32 -0
  68. data/lib/meroku/infrastructure.rb +14 -17
  69. data/lib/meroku/infrastructure/server.rb +20 -0
  70. data/lib/meroku/node.rb +113 -0
  71. data/lib/meroku/tunnelable.rb +31 -0
  72. data/lib/meroku/version.rb +1 -1
  73. data/modified-cedar-14.sh +0 -4
  74. metadata +50 -9
  75. data/frontend/app/controllers/pages_controller.rb +0 -4
  76. data/frontend/app/views/pages/landing.html.erb +0 -2
  77. data/frontend/db/migrate/20171025193627_add_token_to_users.rb +0 -5
  78. data/lib/meroku/cli/admin_user.rb +0 -20
  79. data/lib/meroku/cli/user.rb +0 -14
  80. data/lib/meroku/infrastructure/node.rb +0 -102
  81. data/lib/meroku/tunnel.rb +0 -56
@@ -1,4 +0,0 @@
1
- class PagesController < ApplicationController
2
- def landing
3
- end
4
- end
@@ -1,2 +0,0 @@
1
- <h1>Pages#landing</h1>
2
- <p>Find me in app/views/pages/landing.html.erb</p>
@@ -1,5 +0,0 @@
1
- class AddTokenToUsers < ActiveRecord::Migration[5.1]
2
- def change
3
- add_column :users, :token, :string
4
- end
5
- end
@@ -1,20 +0,0 @@
1
- module Meroku
2
- module CLI
3
-
4
- module AdminUser
5
-
6
- def self.load_secrets(obj)
7
- env_file = Dir.home+'/.meroku/meroku.env'
8
- if !File.exist?(env_file)
9
- puts "error: File not found (#{Dir.home}/.meroku/meroku.env)"
10
- return nil
11
- end
12
- Dotenv.load(env_file)
13
- obj.ec2_client = ::Aws::EC2::Client.new(
14
- region: 'us-east-1',
15
- credentials: ::Aws::Credentials.new(ENV['AWS_ACCESS_KEY'], ENV['AWS_SECRET'])
16
- )
17
- end
18
- end
19
- end
20
- end
@@ -1,14 +0,0 @@
1
- module Meroku
2
- module CLI
3
- module User
4
- def self.load_secrets(obj)
5
- if !File.exist? "#{Dir.home}/.meroku/.token"
6
- puts "error: Have you logged in yet?"
7
- return nil
8
- end
9
- obj.token = `cat ~/.meroku/.token`.chomp
10
- end
11
-
12
- end
13
- end
14
- end
@@ -1,102 +0,0 @@
1
-
2
- module Meroku
3
- module Infrastructure
4
- class Node
5
- attr_accessor :instance, :tunnel, :ec2_client
6
-
7
- def initialize(ec2_client)
8
- @ec2_client = ec2_client
9
- result = ec2_client.try(
10
- :run_instances,
11
- {
12
- image_id: 'ami-841f46ff', #was xenial 'ami-cd0f5cb6',
13
- min_count: 1,
14
- max_count: 1,
15
- key_name: 'meroku.id_rsa',
16
- instance_type: 't2.micro',
17
- tag_specifications: [
18
- {
19
- resource_type: "instance",
20
- tags: [
21
- {
22
- key: "Name",
23
- value: "node",
24
- },
25
- ],
26
- },
27
- ]
28
- }
29
- )
30
- @instance = result.instances.first if result
31
- @tunnel = Meroku::Tunnel.new(
32
- ip: "34.239.241.218",
33
- username: "ubuntu",
34
- keys: "~/crypto/meroku/meroku.id_rsa",
35
- verify_host_key: false,
36
- verbose: false
37
- )
38
- self
39
- end
40
-
41
- def associate_address
42
- retries ||= 0
43
- @ec2_client.associate_address(
44
- allocation_id: "eipalloc-139f7823",
45
- instance_id: @instance.try(:instance_id)
46
- )
47
- self
48
- rescue ::Aws::EC2::Errors::InvalidInstanceID => e
49
- print STDERR.print "."
50
- sleep 2
51
- retry if (retries += 1) < 15
52
- end
53
-
54
- def install_packages
55
- @tunnel.run "sudo apt-add-repository ppa:brightbox/ruby-ng\;"
56
- @tunnel.run "curl -s -o /tmp/modified-cedar-14.sh https://raw.githubusercontent.com/oystersauce8/meroku/master/modified-cedar-14.sh"
57
- @tunnel.run "sudo chmod 755 /tmp/modified-cedar-14.sh"
58
- @tunnel.run "/bin/bash -lc 'sudo /tmp/modified-cedar-14.sh'"
59
- @tunnel.run "sudo apt-get install -y ruby2.4 ruby2.4-dev"
60
- @tunnel.run "sudo apt-get install -y nginx libsqlite3-dev nodejs"
61
- self
62
- end
63
-
64
- def tweak_configuration
65
- #@tunnel.run 'sudo adduser --disabled-password --shell /usr/bin/git-shell --gecos "" git'
66
- #@tunnel.run 'sudo -u git mkdir /home/git/.ssh/'
67
- #@tunnel.run 'sudo -u git touch /home/git/.ssh/authorized_keys'
68
- @tunnel.run 'sudo mkdir /sharedro && sudo chmod 777 /sharedro'
69
- end
70
-
71
- def install_frontend_app
72
- @tunnel.run 'mkdir /home/ubuntu/.meroku'
73
- @tunnel.run "cd ~\; git clone https://github.com/oystersauce8/meroku\;"
74
- @tunnel.run "sudo rm -f /etc/nginx/sites-enabled/*"
75
- @tunnel.run "sudo cp ~/meroku/frontend/etc_nginx_sites-enabled_default /etc/nginx/sites-enabled/default"
76
- @tunnel.run 'sudo cp /home/ubuntu/meroku/frontend/etc_nginx_sites-enabled_template /sharedro'
77
- @tunnel.run 'sudo chmod a+r /sharedro/etc_nginx_sites-enabled_template'
78
-
79
- @tunnel.run "curl -o /home/ubuntu/.meroku/letsencrypt_fullchain.pem http://www.sam-we.com/dropbox/meroku-#{ENV['SECRET']}/letsencrypt_fullchain.pem"
80
- @tunnel.run "curl -o /home/ubuntu/.meroku/letsencrypt_privkey.pem http://www.sam-we.com/dropbox/meroku-#{ENV['SECRET']}/letsencrypt_privkey.pem"
81
-
82
-
83
-
84
- @tunnel.run "cd ~/meroku/frontend/\; sudo gem install bundler\; bundle\;"
85
- @tunnel.run "(cd ~/meroku/frontend && RAILS_ENV=production bundle exec rails assets:precompile)"
86
-
87
- @tunnel.run "(cd ~/meroku/frontend && RAILS_ENV=production bundle exec rake db:migrate)"
88
- @tunnel.run "cd ~/meroku/frontend/\; bundle exec puma -d -b unix:///tmp/meroku.sock"
89
- @tunnel.run "sudo service nginx restart"
90
- @tunnel.run %Q[sudo sh -c 'echo "-----BEGIN EC PRIVATE KEY-----\nMHcCAQEEIPWJQU+TkDu9uyVzHQcVnKklRhQvIBdXHkA/7zAQG8XuoAoGCCqGSM49\nAwEHoUQDQgAEI1lm18nECH4jH+6p80jhn8WgZRDOC1ufVVtoPUnUgEvslfV3xzWl\nDXZKof765EiCOYyt2TZ7pKClMexhHWhMtA==\n-----END EC PRIVATE KEY-----" > /etc/ssh/ssh_host_ecdsa_key']
91
- @tunnel.run %Q[sudo sh -c 'echo "ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBCNZZtfJxAh+Ix/uqfNI4Z/FoGUQzgtbn1VbaD1J1IBL7JX1d8c1pQ12SqH++uRIgjmMrdk2e6SgpTHsYR1oTLQ= root@ip-172-31-64-77" > /etc/ssh/ssh_host_ecdsa_key.pub']
92
- #@tunnel.run "cd ~/.meroku/\; curl -O http://www.sam-we.com/dropbox/meroku-#{ENV['SECRET']}/ssh_host_keys.tgz"
93
- #@tunnel.run "cd ~/.meroku/\; sudo tar xf ssh_host_keys.tgz -C /etc/ssh/ --overwrite && sudo service ssh restart"
94
-
95
- self
96
- rescue
97
- byebug
98
- end
99
-
100
- end
101
- end
102
- end
data/lib/meroku/tunnel.rb DELETED
@@ -1,56 +0,0 @@
1
- module Meroku
2
- class Tunnel
3
-
4
- attr_accessor :ip, :username, :keys, :verify_host_key, :verbose
5
-
6
- def initialize(ip:,username:,keys:,verify_host_key:,verbose:)
7
- @ip = ip
8
- @username = username
9
- @keys = keys
10
- @verify_host_key = verify_host_key
11
- @verbose = verbose
12
- end
13
-
14
- def run(cmd)
15
- @verbose=true
16
- retries ||= 0
17
- exit_code=nil
18
- Net::SSH.start(@ip,
19
- @username,
20
- password: 'password',
21
- keys: @keys,
22
- verify_host_key: @verify_host_key,
23
- timeout: 90) do |ssh|
24
- channel = ssh.open_channel do |ch|
25
- STDERR.print "#{cmd}\n"
26
- ch.exec cmd do |ch, success|
27
- raise "could not execute command" unless success
28
- ch.on_data do |c, data|
29
- if @verbose
30
- $stdout.print data
31
- else
32
- $stdout.print "."
33
- end
34
- end
35
- ch.on_extended_data do |c, type, data|
36
- if @verbose
37
- $stderr.print data
38
- else
39
- $stderr.print "."
40
- end
41
- end
42
- ch.on_request("exit-status") do |ch, data|
43
- exit_code = data.read_long
44
- end
45
-
46
- ch.on_close { print "\n" }
47
- end
48
- end
49
- channel.wait
50
- end
51
- fail "Ssh command returned non-zero" if status != 0
52
- rescue Errno::ECONNREFUSED => e
53
- retry if (retries += 1) < 10
54
- end
55
- end
56
- end