Skip to content
This repository has been archived by the owner on Apr 7, 2022. It is now read-only.

Commit

Permalink
change provisioner to just wait for now
Browse files Browse the repository at this point in the history
  • Loading branch information
manveru committed Jul 12, 2020
1 parent 656494e commit b3456b3
Showing 1 changed file with 12 additions and 30 deletions.
42 changes: 12 additions & 30 deletions src/bitte/cli/provision.cr
Original file line number Diff line number Diff line change
Expand Up @@ -14,47 +14,29 @@ module Bitte
define_flag cluster : String, description: "name of the cluster", required: true

def run
log.info { "Provisioning" }
logger = Log.for(name)
logger.info { "Waiting for user_data to be applied..." }

set_ssh_config

# TODO: add the encrypt key here
create_secrets
wait_for_ssh(ip)
copy_secrets
end
ready = false

until ready
sleep 1

def create_secrets
unless File.exists?("./secrets/consul.master.token.json")
json = {
acl: {tokens: {master: UUID.random.to_s}},
encrypt: `consul keygen`.strip,
}.to_pretty_json
raise "Couldn't create consul encrypt key" unless $?.success?
File.write("./secrets/consul.master.token.json", json)
begin
output = IO::Memory.new
sh! "ssh", args: SSH::COMMON_ARGS + ssh_key + ["root@#{ip}", "cat", "/etc/ready"], logger: logger, output: output
ready = output.to_s =~ /true/
rescue RetryableError
end
end
end

def set_ssh_config
ENV["NIX_SSHOPTS"] ||= (SSH::COMMON_ARGS + ssh_key).join(" ")
end

# TODO: replace with rsync
def copy_secrets
logger = Log.for(name)
dst = "root@#{ip}"
sh! "ssh", args: SSH::COMMON_ARGS + ssh_key + [dst, "mkdir", "-p", "/etc/consul.d"], logger: logger
sh! "scp", (secrets/"consul.master.token.json").to_s, "#{dst}:/etc/consul.d/master-token.json", logger: logger
end

def skip?(name)
if flags.only.any?
!flags.only.includes?(name)
else
false
end
end

def ip
flags.ip
end
Expand Down

0 comments on commit b3456b3

Please sign in to comment.