Class: StackCar::HammerOfTheGods

Inherits:
Thor
  • Object
show all
Includes:
Thor::Actions
Defined in:
lib/stack_car/cli.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.source_rootObject



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.expand_path(dir))
  @db_libs = []
  @db_libs << "libpq-dev postgresql-client" if options[:postgres]
  @db_libs << "mysql-client" if options[:mysql]
  @db_libs << "libc6-dev libreoffice imagemagick unzip" if options[: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 options[:deploy] || options[: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

#stopObject



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

#upObject



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 options[:build]
  args << '-d' if !options[:foreground]
  run("rm -rf tmp/pids/server.pid")
  run("docker-compose up #{args.join(' ')} #{options[:service]}")
  if !options[:foreground]
    @project_name = File.basename(File.expand_path('.'))
    say 'copying bundle to local, you can start using the app now.'
    run("docker cp #{@project_name}_#{options[:service]}_1:/bundle .") if options[:build]
    run("docker-compose logs --tail --follow #{options[:service]}") if options[: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