-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
146 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#!/usr/bin/env ruby | ||
|
||
require 'infrataster/cli' | ||
|
||
Infrataster::CLI.start(ARGV) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
require 'thor' | ||
require 'fileutils' | ||
require 'erb' | ||
|
||
module Infrataster | ||
class CLI < Thor | ||
desc "init", "Initialize Infrataster specs." | ||
option :path, type: :string, default: '.' | ||
def init | ||
path = File.expand_path(options[:path]) | ||
FileUtils.mkdir_p(path) | ||
create_file_from_template(File.expand_path("Gemfile", path)) | ||
create_file_from_template(File.expand_path("Rakefile", path)) | ||
FileUtils.mkdir(File.expand_path("spec", path)) | ||
if ask_yes_or_no("Use Vagrant?") | ||
create_file_from_template(File.expand_path("spec/Vagrantfile", path)) | ||
end | ||
create_file_from_template(File.expand_path("spec/spec_helper.rb", path)) | ||
create_file_from_template(File.expand_path("spec/app_spec.rb", path)) | ||
end | ||
|
||
private | ||
def ask_yes_or_no(question) | ||
print "#{question} (y/N): " | ||
answer = $stdin.gets | ||
if answer =~ /^y/i | ||
true | ||
else | ||
false | ||
end | ||
end | ||
|
||
def create_file_from_template(path) | ||
basename = File.basename(path) | ||
|
||
if File.exist?(path) | ||
puts "#{basename} exists already. Skip." | ||
return | ||
end | ||
|
||
open(path, 'w') do |f| | ||
f.write(ERB.new(File.read(File.expand_path("../fixtures/#{basename}.erb", __FILE__))).result) | ||
end | ||
|
||
puts "Created: #{basename}" | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# Generated by `infrataster init` | ||
source "https://rubygems.org" | ||
|
||
gem "infrataster" | ||
|
||
# If you would like to test mysql, uncomment the next line. | ||
# gem "infrataster-plugin-mysql" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# Generated by `infrataster init` | ||
|
||
require "rspec/core/rake_task" | ||
|
||
def exec_and_abort_if_fail(cmd) | ||
system cmd | ||
unless $?.exitstatus == 0 | ||
$stderr.puts "'#{cmd}' failed." | ||
abort | ||
end | ||
end | ||
|
||
desc 'Run tests' | ||
task :spec => ['spec:integration'] | ||
|
||
namespace :spec do | ||
RSpec::Core::RakeTask.new("infrataster") do |task| | ||
task.pattern = "./spec/{,/*/**}/*_spec.rb" | ||
end | ||
|
||
desc 'Prepare' | ||
task :prepare do | ||
exec_and_abort_if_fail '/usr/bin/vagrant up' | ||
exec_and_abort_if_fail '/usr/bin/vagrant provision' | ||
end | ||
|
||
desc 'Provision' | ||
task :provision do | ||
exec_and_abort_if_fail '/usr/bin/vagrant provision' | ||
end | ||
|
||
desc 'Restart VMs' | ||
task :restart do | ||
exec_and_abort_if_fail '/usr/bin/vagrant reload --provision' | ||
end | ||
|
||
desc 'Clean' | ||
task :clean do | ||
exec_and_abort_if_fail '/usr/bin/vagrant destroy -f' | ||
end | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# -*- mode: ruby -*- | ||
# vi: set ft=ruby : | ||
# | ||
# Generated by `infrataster init` | ||
|
||
VAGRANTFILE_API_VERSION = "2" | ||
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| | ||
config.vm.box = "hashicorp/precise64" | ||
|
||
config.vm.define :app do |c| | ||
c.vm.network "private_network", ip: "192.168.44.10" | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# Generated by `infrataster init` | ||
require 'spec_helper' | ||
|
||
describe server(:app) do | ||
describe http('http://app') do | ||
it "responds OK 200" do | ||
expect(response.status).to eq(200) | ||
end | ||
end | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# Generated by `infrataster init` | ||
require 'infrataster/rspec' | ||
|
||
ENV['VAGRANT_CWD'] = File.dirname(__FILE__) | ||
|
||
Infrataster::Server.define( | ||
:app, | ||
'192.168.0.0/16', | ||
vagrant: true, | ||
) | ||
|
||
RSpec.configure do |config| | ||
config.treat_symbols_as_metadata_keys_with_true_values = true | ||
config.run_all_when_everything_filtered = true | ||
config.filter_run :focus | ||
|
||
config.order = 'random' | ||
end |