lib/meroku/infrastructure/node.rb in meroku-2.0.3 vs lib/meroku/infrastructure/node.rb in meroku-2.0.4

- old
+ new

@@ -1,14 +1,34 @@ module Meroku module Infrastructure class Node - include Meroku::Aws - attr_accessor :instance, :tunnel + attr_accessor :instance, :tunnel, :ec2_client - def initialize - result = ec2_client.try(:run_instances,Meroku::Aws::EC2_PARAMS) + def initialize(ec2_client) + @ec2_client = ec2_client + result = ec2_client.try( + :run_instances, + { + image_id: 'ami-841f46ff', #was xenial 'ami-cd0f5cb6', + min_count: 1, + max_count: 1, + key_name: 'meroku.id_rsa', + instance_type: 't2.micro', + tag_specifications: [ + { + resource_type: "instance", + tags: [ + { + key: "Name", + value: "node", + }, + ], + }, + ] + } + ) @instance = result.instances.first if result @tunnel = Meroku::Tunnel.new( ip: "34.239.241.218", username: "ubuntu", keys: "~/crypto/meroku/meroku.id_rsa", @@ -18,12 +38,11 @@ self end def associate_address retries ||= 0 - return self if !ec2_client - ec2_client.associate_address( + @ec2_client.associate_address( allocation_id: "eipalloc-139f7823", instance_id: @instance.try(:instance_id) ) self rescue ::Aws::EC2::Errors::InvalidInstanceID => e @@ -41,9 +60,15 @@ @tunnel.run "sudo apt-get install -y ruby2.4 ruby2.4-dev" @tunnel.run "sudo apt-get install -y nginx libsqlite3-dev nodejs" self end + def tweak_configuration + @tunnel.run 'sudo adduser --disabled-password --gecos "" git' + @tunnel.run 'sudo -u git mkdir /home/git/.ssh/' + @tunnel.run 'sudo -u git touch /home/git/.ssh/authorized_keys' + end + def install_frontend_app @tunnel.run 'mkdir /home/ubuntu/.meroku' @tunnel.run "cd ~\; git clone https://github.com/oystersauce8/meroku\;" @tunnel.run "sudo cp ~/meroku/frontend/etc_nginx_sites-available_default /etc/nginx/sites-available/default"