Class: StackCar::HammerOfTheGods
- Inherits:
-
Thor
- Object
- Thor
- StackCar::HammerOfTheGods
- Includes:
- Thor::Actions
- Defined in:
- lib/stack_car/cli.rb
Class Method Summary collapse
Instance Method Summary collapse
- #bundle_exec(*args) ⇒ Object
- #console(*args) ⇒ Object
- #deploy(environment) ⇒ Object
- #dockerize(dir = ".") ⇒ Object
- #exec(*args) ⇒ Object
- #provision(environment) ⇒ Object
- #release(environment) ⇒ Object
- #stop ⇒ Object
- #up ⇒ Object
- #walk(*args) ⇒ Object
Class Method Details
.source_root ⇒ Object
9 10 11 |
# File 'lib/stack_car/cli.rb', line 9 def self.source_root File.join(File.dirname(__FILE__), '..', '..', 'templates') end |
Instance Method Details
#bundle_exec(*args) ⇒ Object
54 55 56 |
# File 'lib/stack_car/cli.rb', line 54 def bundle_exec(*args) run("docker-compose exec #{options[:service]} bundle exec #{args.join(' ')}") end |
#console(*args) ⇒ Object
61 62 63 |
# File 'lib/stack_car/cli.rb', line 61 def console(*args) run("docker-compose exec #{options[:service]} bundle exec rails console #{args.join(' ')}") end |
#deploy(environment) ⇒ Object
82 83 84 |
# File 'lib/stack_car/cli.rb', line 82 def deploy(environment) run("cd ops && ansible-playbook -i hosts -l #{environment} deploy.yml") end |
#dockerize(dir = ".") ⇒ Object
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 |
# File 'lib/stack_car/cli.rb', line 104 def dockerize(dir=".") Dir.chdir(dir) @project_name = File.basename(File.(dir)) @db_libs = [] @db_libs << "libpq-dev postgresql-client" if [:postgres] @db_libs << "mysql-client" if [:mysql] @db_libs << "libc6-dev libreoffice imagemagick unzip" if [:fcrepo] @db_libs = @db_libs.join(' ') ['.dockerignore', 'Dockerfile', 'docker-compose.yml', 'docker-compose-prod.yml', '.gitlab-ci.yml', '.env'].each do |template_file| puts template_file template("#{template_file}.erb", template_file) end template("database.yml.erb", "config/database.yml") empty_directory('bundle') run("touch bundle/.gitkeep && git add bundle/.gitkeep") unless File.exists?('bundle/.gitkeep') insert_into_file ".gitignore", "/bundle", :after => "/.bundle" if File.exists?('README.md') prepend_to_file "README.md" do File.read("#{self.class.source_root}/README.md") end else create_file "README.md" do File.read("#{self.class.source_root}/README.md") end end if [:deploy] || [:rancher] directory('ops') ['hosts'].each do |template_file| template("#{template_file}.erb", "ops/#{template_file}") end say 'Please update ops/hosts with the correct server addresses' end end |
#exec(*args) ⇒ Object
47 48 49 |
# File 'lib/stack_car/cli.rb', line 47 def exec(*args) run("docker-compose exec #{options[:service]} #{args.join(' ')}") end |
#provision(environment) ⇒ Object
77 78 79 |
# File 'lib/stack_car/cli.rb', line 77 def provision(environment) run("cd ops && ansible-playbook -i hosts -l #{environment} provision.yml") end |
#release(environment) ⇒ Object
67 68 69 70 71 72 73 74 |
# File 'lib/stack_car/cli.rb', line 67 def release(environment) registry = "#{ENV['REGISTRY_HOST']}#{ENV['REGISTRY_URI']}" run("docker login #{ENV['REGISTRY_HOST']}") run("docker tag #{registry} #{registry}:#{environment}-#{Time.now.strftime("%Y%m%d%I%M%S")}") run("docker push #{registry}:#{environment}-#{Time.now.strftime("%Y%m%d%I%M%S")}") run("docker tag #{registry} #{registry}:#{environment}-latest") run("docker push #{registry}:#{environment}-latest") end |
#stop ⇒ Object
34 35 36 37 |
# File 'lib/stack_car/cli.rb', line 34 def stop run("docker-compose stop #{options[:service]}") run("rm -rf tmp/pids/server.pid") end |
#up ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/stack_car/cli.rb', line 18 def up args = ['--remove-orphans'] args << '--build' if [:build] args << '-d' if ![:foreground] run("rm -rf tmp/pids/server.pid") run("docker-compose up #{args.join(' ')} #{options[:service]}") if ![:foreground] @project_name = File.basename(File.('.')) say 'copying bundle to local, you can start using the app now.' run("docker cp #{@project_name}_#{options[:service]}_1:/bundle .") if [:build] run("docker-compose logs --tail --follow #{options[:service]}") if [:logs] end end |
#walk(*args) ⇒ Object
41 42 43 |
# File 'lib/stack_car/cli.rb', line 41 def walk(*args) run("docker-compose run #{options[:service]} #{args.join(' ')}") end |