Skip to content

Commit

Permalink
kite new; now render a generic project skeleton
Browse files Browse the repository at this point in the history
Moved code into a genrate commands, next should be made modular
Louis Bellet committed Aug 25, 2017
1 parent 08b0ccc commit 9229e67
Showing 15 changed files with 149 additions and 53 deletions.
2 changes: 1 addition & 1 deletion bin/kite
Original file line number Diff line number Diff line change
@@ -4,4 +4,4 @@ require "thor"
$: << File.join(File.dirname(__FILE__), "../lib")
require 'kite'

Kite::Commands.start
Kite::Core.start
15 changes: 9 additions & 6 deletions lib/kite.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
require "erb"
require "yaml"
require "thor"
require 'erb'
require 'yaml'
require 'thor'

require "kite/version"
require "kite/helpers"
require "kite/commands"
require 'kite/version'
require 'kite/helpers'

require 'kite/base'
require 'kite/core'
require 'kite/cloud'
5 changes: 5 additions & 0 deletions lib/kite/base.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class Kite::Base < Thor

include Thor::Actions

end
24 changes: 24 additions & 0 deletions lib/kite/cloud.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
class Kite::Cloud

def initialize(core, cloud_name)
@core = core
@name = cloud_name
@core.destination_root = nil
end

def name
@name
end

def core
@core
end

def prepare
core.directory('skel', name)
core.inside(name) do
core.chmod('bin/kite', 0755)
end
end

end
46 changes: 0 additions & 46 deletions lib/kite/commands.rb

This file was deleted.

56 changes: 56 additions & 0 deletions lib/kite/core.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
module Kite
class Core < Base

include Kite::Helpers

def self.source_root
File.expand_path(File.join(File.dirname(__FILE__), "../../tpl"))
end

method_option :cloud, type: :string, desc: "Cloud provider", enum: %w{aws gcp}
desc "new CLOUD_PATH", "Generate Cloud infrastructure skeleton from configuration"
def new(cloud_name)
target = Kite::Cloud.new(self, cloud_name)
target.prepare
end

method_option :cloud, type: :string, desc: "Cloud provider", enum: %w{aws gcp}, required: true
desc "generate", "Generate Cloud IaC from configuration"
def generate()
say "Generating Cloud #{ options[:cloud] } IaC", :green
@values = YAML.load(File.read('config/cloud.yml'))

case options[:cloud]
when "aws"
copy_file("aws/bin/make_cloud_config.sh", "bin/make_cloud_config.sh")
copy_file("aws/bin/make_manifest_bosh-init.sh", "bin/make_manifest_bosh-init.sh")
copy_file("aws/bin/make_manifest_concourse-cluster.sh", "bin/make_manifest_concourse-cluster.sh")

copy_file("aws/terraform/aws-concourse.tf", "terraform/aws-concourse.tf")
copy_file("aws/terraform/aws-vault.tf", "terraform/aws-vault.tf")
copy_file("aws/terraform/bosh-aws-base.tf", "terraform/bosh-aws-base.tf")
copy_file("aws/terraform/outputs.tf", "terraform/outputs.tf")
copy_file("aws/terraform/variables.tf", "terraform/variables.tf")
copy_file("aws/terraform/variables.tf", "terraform/variables.tf")

template("aws/env.example.erb", ".env")
copy_file("aws/README.md", "README.md")
copy_file("aws/bootstrap.sh", "bootstrap.sh")

when "gcp"
template("gcp/manifest.yml.erb", "manifest.yml")
template("gcp/cloud-config.yml.erb", "cloud-config.yml")
copy_file("gcp/concourse.yml.erb", "concourse.yml")
copy_file("gcp/README.md", "README.md")
directory("gcp/scripts", "scripts")
copy_file("gcp/INSTALL.md", "INSTALL.md")
template("gcp/env.example.erb", ".env")
copy_file("gcp/main.tf", "main.tf")
copy_file("gcp/concourse.tf", "concourse.tf")
else
say "Cloud provider not specified"

end
end
end
end
12 changes: 12 additions & 0 deletions tpl/skel/Gemfile.tt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
source 'https://rubygems.org'

gem 'kite', '~> <%= Kite::VERSION %>'

# Use AWS
# gem 'aws-sdk', '~> 2'

# Use GCP
# gem 'google-cloud'

# Use Jekyll
# gem 'jekyll'
1 change: 1 addition & 0 deletions tpl/skel/README.md.tt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# <%=@cloud_name %>
7 changes: 7 additions & 0 deletions tpl/skel/bin/kite
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/usr/bin/env ruby
require "thor"

$: << File.join(File.dirname(__FILE__), "../lib")
require 'kite'

Kite::Core.start
34 changes: 34 additions & 0 deletions tpl/skel/config/cloud.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
aws:
access_key_id: "XXXXXXXXXXXXXX"
secret_access_key: "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
region: "us-east-1"
az: "us-east-1a"
bosh_password: "bosh_password"
keypair_name: "bosh"
private_key_path: "~/Downloads/bosh.pem"
db_password: "database_password"
ci_dns_zone_id: "XXXXXXXXXXXXX"
ci_hostname: "ci.example.com"
concourse_url: "http://ci.example.com"
concourse_auth_username: "concourse"
concourse_auth_password: "concourse"

gcp:
project_id: gcp-project
region: europe-west1
zone: europe-west1-b
service_account: bosh
ssh_key_path: ~/.ssh/bosh

bosh:
bosh_password: "bosh_password"
keypair_name: "bosh"
private_key_path: "~/Downloads/bosh.pem"
db_password: "database_password"

concourse:
hostname: "ci.domain.io"
dns_zone: "your_dns_zone_id"
url: "http://ci.example.com"
auth_username: "concourse"
auth_password: "concourse"
Empty file added tpl/skel/docs/index.md.tt
Empty file.
Empty file added tpl/skel/docs/quickstart.md.tt
Empty file.
Empty file added tpl/skel/lib/tasks/.keep
Empty file.
Empty file added tpl/skel/log/.keep
Empty file.
Empty file added tpl/skel/tmp/.keep
Empty file.

0 comments on commit 9229e67

Please sign in to comment.