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
- #build ⇒ Object
- #bundle_exec(*args) ⇒ Object
- #console(*args) ⇒ Object
- #deploy(environment) ⇒ Object
- #dockerize(dir = nil) ⇒ 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
#build ⇒ Object
32 33 34 35 36 |
# File 'lib/stack_car/cli.rb', line 32 def build @project_name = File.basename(File.('.')) run("docker-compose build #{options[:service]}") run("docker cp #{@project_name}_#{options[:service]}_1:/bundle .") end |
#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 = nil) ⇒ Object
103 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 |
# File 'lib/stack_car/cli.rb', line 103 def dockerize(dir=nil) if dir Dir.chdir(dir) else dir = '.' end @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| template("#{template_file}.erb", template_file) end empty_directory('bundle') 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
25 26 27 28 |
# File 'lib/stack_car/cli.rb', line 25 def stop run("docker-compose stop #{options[:service]}") run("rm -rf tmp/pids/server.pid") end |
#up ⇒ Object
16 17 18 19 20 21 |
# File 'lib/stack_car/cli.rb', line 16 def up args = ['--remove-orphans'] args << '--build' if [:build] run("rm -rf tmp/pids/server.pid") run("docker-compose up #{args.join(' ')} #{options[:service]}") 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 |