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(*args) ⇒ Object
- #bundle_exec(*args) ⇒ Object
- #console(*args) ⇒ Object
- #deploy(environment) ⇒ Object
- #dockerize(dir = ".") ⇒ Object
- #exec(*args) ⇒ Object
- #provision(environment) ⇒ Object
- #ps(*args) ⇒ Object
- #pull(*args) ⇒ Object
- #push(*args) ⇒ 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(*args) ⇒ Object
64 65 66 67 68 |
# File 'lib/stack_car/cli.rb', line 64 def bundle(*args) run("docker-compose exec #{[:service]} bundle") @project_name = File.basename(File.('.')) run("docker cp #{@project_name}_#{[: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 #{[: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 #{[: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.(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-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 [: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
78 79 80 |
# File 'lib/stack_car/cli.rb', line 78 def exec(*args) run("docker-compose exec #{[: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 #{[: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 #{[: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 #{[: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 |
#stop ⇒ Object
38 39 40 41 |
# File 'lib/stack_car/cli.rb', line 38 def stop run("docker-compose stop #{[:service]}") run("rm -rf tmp/pids/*") end |
#up ⇒ Object
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 [:build] args << '-d' if ![:foreground] if [:build] run("docker-compose pull #{[:service]}") end run("docker-compose up #{args.join(' ')} #{[:service]}") if [:build] @project_name = File.basename(File.('.')) say 'copying bundle to local, you can start using the app now.' run("docker cp #{@project_name}_#{[:service]}_1:/bundle .") if [:build] end run("docker-compose logs --tail 20 --follow ") if [:logs] end |
#walk(*args) ⇒ Object
72 73 74 |
# File 'lib/stack_car/cli.rb', line 72 def walk(*args) run("docker-compose run #{[:service]} #{args.join(' ')}") end |