Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reorganized templates #1

Merged
merged 2 commits into from
Aug 28, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 20 additions & 4 deletions lib/kite/core.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,6 @@ def generate()

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")
Expand All @@ -52,5 +48,25 @@ def generate()

end
end

method_option :manifest, type: :string, desc: "Manifest type", enum: %w{bosh concourse}, required: true
desc "render-manifest", "Render manifest file from configuration and Terraform output"
def render_manifest
say "Rendering #{ options[:manifest] } manifest", :green
@values = YAML.load(File.read('config/cloud.yml'))
@tf_output = parse_tf_state('terraform/terraform.tfstate')

case options[:manifest]
when "bosh"
template("aws/bosh/bosh_director.yml.erb", "bosh_director.yml")

when "concourse"
template("aws/concourse/aws_cloud.yml.erb", "aws_cloud.yml")
template("aws/concourse/concourse.yml.erb", "concourse.yml")
else
say "Manifest type not specified"

end
end
end
end
7 changes: 7 additions & 0 deletions lib/kite/helpers.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,9 @@
module Kite::Helpers
# Parse Terraform .tfstate file, returning the output hash
def parse_tf_state(path)
tf_state = YAML.load(File.open(path))
tf_output = tf_state["modules"].first["outputs"]
tf_output.map { |k, v| tf_output[k] = v["value"] }
tf_output
end
end
Original file line number Diff line number Diff line change
@@ -1,31 +1,3 @@
#!/bin/bash
#
# Please set the following environment variables:
# $AWS_ACCESS_KEY_ID
# $AWS_SECRET_ACCESS_KEY
# $AWS_REGION
# $AWS_AZ
# $BOSH_PASSWORD
# $AWS_KEYPAIR_KEY_NAME
# $PRIVATE_KEY_PATH

function getvars() {
cd terraform/
EIP=$(terraform output eip)
SUBNET=$(terraform output default_subnet_id)
SECURITY_GROUP=$(terraform output security_group_id)
cd ../
}

getvars

echo "Subnet = $SUBNET"
echo "Security Group = $SECURITY_GROUP"
echo "EIP = $EIP"
echo "AWS REGION = $AWS_REGION"
echo "AWS AZ = $AWS_AZ"

cat >bosh-director.yml <<YAML
---
name: bosh

Expand All @@ -46,7 +18,7 @@ resource_pools:
cloud_properties:
instance_type: m3.large
ephemeral_disk: {size: 25_000, type: gp2}
availability_zone: $AWS_AZ
availability_zone: <%= @values['aws']['az'] %>

disk_pools:
- name: disks
Expand All @@ -60,7 +32,7 @@ networks:
- range: 10.0.0.0/24
gateway: 10.0.0.1
dns: [10.0.0.2]
cloud_properties: {subnet: $SUBNET}
cloud_properties: {subnet: <%= @tf_output['default_subnet_id'] %>}
- name: public
type: vip

Expand All @@ -85,37 +57,37 @@ jobs:
static_ips: [10.0.0.6]
default: [dns, gateway]
- name: public
static_ips: [$EIP]
static_ips: [<%= @tf_output['eip'] %>]

properties:
nats:
address: 127.0.0.1
user: nats
password: $BOSH_PASSWORD
password: <%= @values['aws']['bosh_password'] %>

postgres: &db
listen_address: 127.0.0.1
host: 127.0.0.1
user: postgres
password: $BOSH_PASSWORD
password: <%= @values['aws']['bosh_password'] %>
database: bosh
adapter: postgres

registry:
address: 10.0.0.6
host: 10.0.0.6
db: *db
http: {user: admin, password: $BOSH_PASSWORD, port: 25777}
http: {user: admin, password: <%= @values['aws']['bosh_password'] %>, port: 25777}
username: admin
password: $BOSH_PASSWORD
password: <%= @values['aws']['bosh_password'] %>
port: 25777

blobstore:
address: 10.0.0.6
port: 25250
provider: dav
director: {user: director, password: $BOSH_PASSWORD}
agent: {user: agent, password: $BOSH_PASSWORD}
director: {user: director, password: <%= @values['aws']['bosh_password'] %>}
agent: {user: agent, password: <%= @values['aws']['bosh_password'] %>}

director:
address: 127.0.0.1
Expand All @@ -127,38 +99,37 @@ jobs:
provider: local
local:
users:
- {name: admin, password: $BOSH_PASSWORD}
- {name: hm, password: $BOSH_PASSWORD}
- {name: admin, password: <%= @values['aws']['bosh_password'] %>}
- {name: hm, password: <%= @values['aws']['bosh_password'] %>}

hm:
director_account: {user: hm, password: $BOSH_PASSWORD}
director_account: {user: hm, password: <%= @values['aws']['bosh_password'] %>}
resurrector_enabled: true

aws: &aws
access_key_id: $AWS_ACCESS_KEY_ID
secret_access_key: $AWS_SECRET_ACCESS_KEY
default_key_name: $AWS_KEYPAIR_KEY_NAME
default_security_groups: [$SECURITY_GROUP]
region: $AWS_REGION
access_key_id: <%= @values['aws']['access_key_id'] %>
secret_access_key: <%= @values['aws']['secret_access_key'] %>
default_key_name: <%= @values['aws']['keypair_name'] %>
default_security_groups: [<%= @tf_output['security_group_id'] %>]
region: <%= @values['aws']['region'] %>

agent: {mbus: "nats://nats:$BOSH_PASSWORD@10.0.0.6:4222"}
agent: {mbus: "nats://nats:<%= @values['aws']['bosh_password'] %>@10.0.0.6:4222"}

ntp: &ntp [0.pool.ntp.org, 1.pool.ntp.org]

cloud_provider:
template: {name: aws_cpi, release: bosh-aws-cpi}

ssh_tunnel:
host: $EIP # <--- Replace with your Elastic IP address
host: <%= @tf_output['eip'] %> # <--- Replace with your Elastic IP address
port: 22
user: vcap
private_key: $PRIVATE_KEY_PATH # Path relative to this manifest file
private_key: <%= @values['aws']['private_key_path'] %> # Path relative to this manifest file

mbus: "https://mbus:$BOSH_PASSWORD@$EIP:6868" # <--- Replace with Elastic IP
mbus: "https://mbus:<%= @values['aws']['bosh_password'] %>@<%= @tf_output['eip'] %>:6868" # <--- Replace with Elastic IP

properties:
aws: *aws
agent: {mbus: "https://mbus:$BOSH_PASSWORD@0.0.0.0:6868"}
agent: {mbus: "https://mbus:<%= @values['aws']['bosh_password'] %>@0.0.0.0:6868"}
blobstore: {provider: local, path: /var/vcap/micro_bosh/data/cache}
ntp: *ntp
YAML
Original file line number Diff line number Diff line change
@@ -1,28 +1,7 @@
#!/bin/bash
#
# Please set the following environment variables:
# $AWS_AZ


function getvars() {
cd terraform/
DEFAULT_SUBNET=$(terraform output default_subnet_id)
OPS_SUBNET=$(terraform output ops_services_subnet_id)
cd ../
}

getvars

echo "Default Subnet = $DEFAULT_SUBNET"
echo "Ops Services Subnet = $OPS_SUBNET"
echo "AWS AZ" = $AWS_AZ


cat >aws-cloud.yml <<YAML
---
azs:
- name: z1
cloud_properties: {availability_zone: $AWS_AZ}
cloud_properties: {availability_zone: <%= @values['aws']['az'] %>}

vm_types:
- name: concourse_standalone
Expand Down Expand Up @@ -81,7 +60,7 @@ networks:
static: [10.0.0.6]
reserved: [10.0.0.1-10.0.0.5]
dns: [10.0.0.2]
cloud_properties: {subnet: $DEFAULT_SUBNET}
cloud_properties: {subnet: <%= @tf_output['default_subnet_id'] %>}
- name: ops_services
type: manual
subnets:
Expand All @@ -90,7 +69,7 @@ networks:
az: z1
reserved: [10.0.10.1-10.0.10.5]
dns: [10.0.0.2]
cloud_properties: {subnet: $OPS_SUBNET}
cloud_properties: {subnet: <%= @tf_output['ops_services_subnet_id'] %>}
- name: vip
type: vip

Expand All @@ -100,5 +79,3 @@ compilation:
az: z1
vm_type: large
network: default

YAML
Original file line number Diff line number Diff line change
@@ -1,21 +1,7 @@
#!/bin/bash
#
# Please set the following environment variables:
# $DB_PASSWORD
# $CONCOURSE_URL
# $CONCOURSE_AUTH_USERNAME
# $CONCOURSE_AUTH_PASSWORD

DIRECTOR_UUID=`bosh status --uuid`

echo "director_uuid = $DIRECTOR_UUID"
echo "concourse url = $CONCOURSE_URL"

cat >concourse.yml <<YAML
---
name: concourse

director_uuid: $DIRECTOR_UUID
director_uuid: <%= %x(bosh status --uuid) %>

releases:
- name: concourse
Expand All @@ -40,10 +26,10 @@ instance_groups:
release: concourse
properties:
# replace with your CI's externally reachable URL e.g https://blah
external_url: $CONCOURSE_URL
external_url: <%= @values['aws']['concourse_url'] %>

basic_auth_username: $CONCOURSE_AUTH_USERNAME
basic_auth_password: $CONCOURSE_AUTH_PASSWORD
basic_auth_username: <%= @values['aws']['concourse_auth_username'] %>
basic_auth_password: <%= @values['aws']['concourse_auth_password'] %>

postgresql_database: &atc_db atc
- name: tsa
Expand All @@ -65,7 +51,7 @@ instance_groups:
- name: *atc_db
# make up a role and password
role: dbrole
password: $DB_PASSWORD
password: <%= @values['aws']['db_password'] %>

- name: worker
instances: 1
Expand Down Expand Up @@ -93,4 +79,3 @@ update:
serial: false
canary_watch_time: 1000-60000
update_watch_time: 1000-60000
YAML