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(*args) ⇒ Object



64
65
66
67
68
# File 'lib/stack_car/cli.rb', line 64

def bundle(*args)
  run("docker-compose exec #{options[:service]} bundle")
  @project_name = File.basename(File.expand_path('.'))
  run("docker cp #{@project_name}_#{options[:service]}_1:/bundle .")
end

#bundle_exec(*args) ⇒ Object



85
86
87
# File 'lib/stack_car/cli.rb', line 85

def bundle_exec(*args)
  run("docker-compose exec #{options[:service]} bundle exec #{args.join(' ')}")
end

#console(*args) ⇒ Object



92
93
94
# File 'lib/stack_car/cli.rb', line 92

def console(*args)
  run("docker-compose exec #{options[:service]} bundle exec rails console #{args.join(' ')}")
end

#deploy(environment) ⇒ Object



113
114
115
# File 'lib/stack_car/cli.rb', line 113

def deploy(environment)
  run("cd ops && ansible-playbook -i hosts -l #{environment} deploy.yml")
end

#dockerize(dir = ".") ⇒ Object



135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
# File 'lib/stack_car/cli.rb', line 135

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-ci.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



78
79
80
# File 'lib/stack_car/cli.rb', line 78

def exec(*args)
  run("docker-compose exec #{options[:service]} #{args.join(' ')}")
end

#provision(environment) ⇒ Object



108
109
110
# File 'lib/stack_car/cli.rb', line 108

def provision(environment)
  run("cd ops && ansible-playbook -i hosts -l #{environment} provision.yml")
end

#ps(*args) ⇒ Object



57
58
59
# File 'lib/stack_car/cli.rb', line 57

def ps(*args)
  run("docker-compose ps #{options[:service]} #{args.join(' ')}")
end

#pull(*args) ⇒ Object



51
52
53
# File 'lib/stack_car/cli.rb', line 51

def pull(*args)
  run("docker-compose pull #{options[:service]} #{args.join(' ')}")
end

#push(*args) ⇒ Object



45
46
47
# File 'lib/stack_car/cli.rb', line 45

def push(*args)
  run("docker-compose push #{options[:service]} #{args.join(' ')}")
end

#release(environment) ⇒ Object



98
99
100
101
102
103
104
105
# File 'lib/stack_car/cli.rb', line 98

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



38
39
40
41
# File 'lib/stack_car/cli.rb', line 38

def stop
  run("docker-compose stop #{options[:service]}")
  run("rm -rf tmp/pids/*")
end

#upObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/stack_car/cli.rb', line 18

def up
  args = ['--remove-orphans']
  args << '--build' if options[:build]
  args << '-d' if !options[:foreground]
  if options[:build]
    run("docker-compose pull #{options[:service]}")
  end

  run("docker-compose up #{args.join(' ')} #{options[:service]}")

  if options[:build]
    @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]
  end
  run("docker-compose logs --tail 20 --follow ") if options[:logs]
end

#walk(*args) ⇒ Object



72
73
74
# File 'lib/stack_car/cli.rb', line 72

def walk(*args)
  run("docker-compose run #{options[:service]} #{args.join(' ')}")
end