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



55
56
57
# File 'lib/stack_car/cli.rb', line 55

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

#bundle_exec(*args) ⇒ Object



74
75
76
# File 'lib/stack_car/cli.rb', line 74

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

#console(*args) ⇒ Object



81
82
83
# File 'lib/stack_car/cli.rb', line 81

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

#deploy(environment) ⇒ Object



102
103
104
# File 'lib/stack_car/cli.rb', line 102

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

#dockerize(dir = ".") ⇒ Object



126
127
128
129
130
131
132
133
134
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
# File 'lib/stack_car/cli.rb', line 126

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")
 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'
  else
    empty_directory('ops')
  end

  # Do this after we figure out whether to use an empty ops directory or a full one
  ['env.conf', 'webapp.conf'].each do |template_file|
    template("#{template_file}.erb", "ops/#{template_file}")
  end
end

#exec(*args) ⇒ Object



67
68
69
# File 'lib/stack_car/cli.rb', line 67

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

#provision(environment) ⇒ Object



97
98
99
# File 'lib/stack_car/cli.rb', line 97

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

#ps(*args) ⇒ Object



48
49
50
# File 'lib/stack_car/cli.rb', line 48

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

#pull(*args) ⇒ Object



42
43
44
# File 'lib/stack_car/cli.rb', line 42

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

#push(*args) ⇒ Object



36
37
38
# File 'lib/stack_car/cli.rb', line 36

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

#release(environment) ⇒ Object



87
88
89
90
91
92
93
94
# File 'lib/stack_car/cli.rb', line 87

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



29
30
31
32
# File 'lib/stack_car/cli.rb', line 29

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

#upObject



17
18
19
20
21
22
23
24
25
# File 'lib/stack_car/cli.rb', line 17

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

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

#walk(*args) ⇒ Object



61
62
63
# File 'lib/stack_car/cli.rb', line 61

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