-
Notifications
You must be signed in to change notification settings - Fork 7
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
15 changed files
with
267 additions
and
72 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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
#!/usr/bin/env ruby | ||
|
||
require 'tape' | ||
require 'taperole' | ||
|
||
TapeBoxer::Tape.start(ARGV) | ||
Taperole::Commands::Tape.start(ARGV) |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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 @@ | ||
require 'thor' | ||
require 'taperole/helpers/string_color_monkeypatch' | ||
|
||
module Taperole | ||
autoload :VERSION, 'taperole/version' | ||
autoload :AnsibleRunner, 'taperole/core/ansible_runner' | ||
autoload :Installer, 'taperole/core/installer' | ||
|
||
module Commands | ||
autoload :Tape, 'taperole/commands/tape' | ||
autoload :Installer, 'taperole/commands/installer' | ||
autoload :Ansible, 'taperole/commands/ansible' | ||
end | ||
|
||
module Helpers | ||
autoload :Files, 'taperole/helpers/files' | ||
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,26 @@ | ||
module Taperole | ||
module Commands | ||
class Ansible < Thor | ||
include Taperole::AnsibleRunner | ||
|
||
class_option :limit, | ||
type: :string, | ||
aliases: :l, | ||
desc: "Limits ansible runs to hosts matching the given pattern" | ||
class_option :task, | ||
type: :string, | ||
aliases: :T, | ||
desc: "Name of the rake task to execute" | ||
|
||
desc 'everything', 'Initial setup of a server' | ||
def everything | ||
valid_preconfigs ? ansible : puts("Not a Rails or JS app") | ||
end | ||
|
||
desc 'deploy', 'Deploy the latest version of the app' | ||
def deploy | ||
puts 'deploying' | ||
end | ||
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,17 @@ | ||
module Taperole | ||
module Commands | ||
class Installer < Thor | ||
include Taperole::Installer | ||
|
||
desc 'install', 'Creates all necessary hosts and config files' | ||
def install | ||
install_tape | ||
end | ||
|
||
desc 'uninstall', 'Cleans up files generated by the installer' | ||
def uninstall | ||
uninstall_tape | ||
end | ||
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,22 @@ | ||
require 'thor' | ||
|
||
module Taperole | ||
module Commands | ||
class Tape < Thor | ||
class_option :verbose, type: :boolean | ||
|
||
map %w[--version -v] => :__print_version | ||
|
||
desc "--version, -v", "print the version" | ||
def __print_version | ||
puts Taperole::VERSION | ||
end | ||
|
||
desc 'ansible [COMMAND]', 'run tapes ansible commands' | ||
subcommand 'ansible', Ansible | ||
|
||
desc 'installer [COMMAND]', 'install and uninstall tape' | ||
subcommand 'installer', Installer | ||
end | ||
end | ||
end |
6 changes: 2 additions & 4 deletions
6
lib/tape/ansible_runner.rb → lib/taperole/core/ansible_runner.rb
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,116 @@ | ||
require 'pry-byebug' | ||
|
||
module Taperole | ||
module Installer | ||
include Helpers::Files | ||
include Thor::Actions | ||
|
||
protected | ||
|
||
def install_tape | ||
File.open('.gitignore', 'r+') { |f| f.puts '.tape' unless f.read =~ /^\.tape$/ } | ||
mkdir tapefiles_dir | ||
if fe_app? && !rails_app? | ||
puts '🔎 JS/HTML app detected'.pink | ||
copy_static_app_examples | ||
elsif rails_app? | ||
puts '🔎 Rails app detected'.pink | ||
copy_basic_examples | ||
end | ||
create_roles_dir | ||
create_inventory_file | ||
create_ssh_keys_dir | ||
if ask 'Are you going to use vagrant? (y/n): ' | ||
copy_example 'Vagrantfile', 'Vagrantfile' | ||
end | ||
end | ||
|
||
def create_roles_dir | ||
mkdir "#{tapefiles_dir}/roles" | ||
`touch #{tapefiles_dir}/roles/.keep` | ||
end | ||
|
||
def create_ssh_keys_dir | ||
mkdir "#{tapefiles_dir}/dev_keys" | ||
end | ||
|
||
def create_inventory_file | ||
copy_example 'templates/base/hosts.example', "#{tapefiles_dir}/hosts" | ||
end | ||
|
||
def copy_static_app_examples | ||
%w(omnibox deploy tape_vars).each do |base_filename| | ||
copy_example( | ||
"templates/static_html/#{base_filename}.example.yml", | ||
"#{tapefiles_dir}/#{base_filename}.yml" | ||
) | ||
end | ||
end | ||
|
||
def copy_basic_examples | ||
%w(omnibox deploy tape_vars rake).each do |base_filename| | ||
copy_example( | ||
"templates/base/#{base_filename}.example.yml", | ||
"#{tapefiles_dir}/#{base_filename}.yml" | ||
) | ||
end | ||
end | ||
|
||
def uninstall_tape | ||
rm "#{tapefiles_dir}/omnibox.yml" | ||
rm "#{tapefiles_dir}/deploy.yml" | ||
rm "#{tapefiles_dir}/tape_vars.yml" | ||
rm "#{tapefiles_dir}/rake.yml" | ||
rm "#{tapefiles_dir}/roles" | ||
rm "#{tapefiles_dir}/hosts" | ||
rm "#{tapefiles_dir}/dev_keys" | ||
rm "#{local_dir}/Vagrantfile" | ||
end | ||
|
||
def rm(file) | ||
print 'Deleting '.red | ||
puts file | ||
FileUtils.rm_r file | ||
end | ||
|
||
def mkdir(name) | ||
print "#{::Pathname.new(name).basename}: " | ||
begin | ||
FileUtils.mkdir name | ||
success | ||
rescue Errno::EEXIST | ||
exists | ||
rescue StandardError => e | ||
error | ||
raise e | ||
end | ||
end | ||
|
||
def copy_example(file, cp_file) | ||
print "#{::Pathname.new(cp_file).basename}: " | ||
begin | ||
if File.exist?(cp_file.to_s) | ||
exists | ||
else | ||
FileUtils.cp("#{tape_dir}/#{file}", cp_file.to_s) | ||
success | ||
end | ||
rescue StandardError => e | ||
error | ||
raise e | ||
end | ||
end | ||
|
||
def success | ||
puts '✔'.green | ||
end | ||
|
||
def error | ||
puts '✘'.red | ||
end | ||
|
||
def exists | ||
puts '✘ (Exists)'.yellow | ||
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,31 @@ | ||
require 'pry-byebug' | ||
|
||
module Taperole | ||
module Helpers | ||
module Files | ||
def fe_app? | ||
!Dir["#{local_dir}/package.json"].empty? | ||
end | ||
|
||
def rails_app? | ||
!Dir["#{local_dir}/config.ru"].empty? | ||
end | ||
|
||
def tape_dir | ||
File.realpath(File.join(__dir__, '../../../')) | ||
end | ||
|
||
def local_dir | ||
Dir.pwd | ||
end | ||
|
||
def tapefiles_dir | ||
local_dir + '/taperole' | ||
end | ||
|
||
def tapecfg_dir | ||
local_dir + '/.tape' | ||
end | ||
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,25 @@ | ||
class String | ||
def initialize(string) | ||
@string = string | ||
end | ||
|
||
def colorize(color_code) | ||
"\e[#{color_code}m#{self}\e[0m" | ||
end | ||
|
||
def red | ||
colorize(31) | ||
end | ||
|
||
def green | ||
colorize(32) | ||
end | ||
|
||
def yellow | ||
colorize(33) | ||
end | ||
|
||
def pink | ||
colorize(35) | ||
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,3 @@ | ||
module Taperole | ||
VERSION = '1.7.0'.freeze | ||
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