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(*args) ⇒ Object
- #bundle_exec(*args) ⇒ Object
- #console(*args) ⇒ Object
- #deploy(environment) ⇒ Object
- #dockerize(dir = ".") ⇒ Object
- #down ⇒ Object
- #exec(*args) ⇒ Object
- #provision(environment) ⇒ Object
- #ps(*args) ⇒ Object
- #pull(*args) ⇒ Object
- #push(*args) ⇒ Object
- #release(environment) ⇒ Object
- #sh(*args) ⇒ Object
- #ssh(environment) ⇒ Object
- #stop ⇒ Object
- #up ⇒ Object
- #walk(*args) ⇒ Object
Class Method Details
.exit_on_failure? ⇒ Boolean
19 20 21 |
# File 'lib/stack_car/cli.rb', line 19 def self.exit_on_failure? true end |
Instance Method Details
#build ⇒ Object
102 103 104 105 106 |
# File 'lib/stack_car/cli.rb', line 102 def build setup ensure_development_env run_with_exit("#{dotenv} docker compose build #{[:service]}") end |
#bundle(*args) ⇒ Object
139 140 141 142 |
# File 'lib/stack_car/cli.rb', line 139 def bundle(*args) setup run_with_exit("#{dotenv} docker compose exec #{[:service]} bundle") end |
#bundle_exec(*args) ⇒ Object
168 169 170 171 |
# File 'lib/stack_car/cli.rb', line 168 def bundle_exec(*args) setup run_with_exit("#{dotenv} docker compose exec #{[:service]} bundle exec #{args.join(' ')}") end |
#console(*args) ⇒ Object
176 177 178 179 |
# File 'lib/stack_car/cli.rb', line 176 def console(*args) setup run_with_exit("#{dotenv} docker compose exec #{[:service]} bundle exec rails console #{args.join(' ')}") end |
#deploy(environment) ⇒ Object
223 224 225 226 |
# File 'lib/stack_car/cli.rb', line 223 def deploy(environment) setup run_with_exit("DEPLOY_HOOK=$DEPLOY_HOOK_#{environment.upcase} #{dotenv(environment)} ansible-playbook -i ops/hosts -l #{environment}:localhost ops/deploy.yml") end |
#dockerize(dir = ".") ⇒ Object
253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 |
# File 'lib/stack_car/cli.rb', line 253 def dockerize(dir=".") Dir.chdir(dir) self.destination_root = dir setup # Commandline overrides config files # options = file_config.merge(options) # Sets project name to parent directory name if working with stack_car dir @project_name = @sc_dir ? File.basename(File.('..')) : File.basename(File.(dir)) apt_packages << "libpq-dev postgresql-client" if [:postgres] apt_packages << "mysql-client" if [:mysql] apt_packages << "imagemagick" if [:imagemagick] pre_apt << "echo 'Downloading Packages'" post_apt << "echo 'Packages Downloaded'" if [:yarn] apt_packages << 'yarn' pre_apt << "curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add -" pre_apt << "echo 'deb https://dl.yarnpkg.com/debian/ stable main' | tee /etc/apt/sources.list.d/yarn.list" post_apt << "yarn config set no-progress" post_apt << "yarn config set silent" end if [:fcrepo] apt_packages << "libc6-dev libreoffice imagemagick unzip ghostscript ffmpeg" post_apt << "mkdir -p /opt/fits" post_apt << "curl -fSL -o /opt/fits-1.0.5.zip http://projects.iq.harvard.edu/files/fits/files/fits-1.0.5.zip" post_apt << "cd /opt && unzip fits-1.0.5.zip && chmod +X fits-1.0.5/fits.sh" end ['.dockerignore', 'Dockerfile', 'docker-compose.yml', '.gitlab-ci.yml', '.env'].each do |template_file| puts template_file template("#{template_file}.erb", template_file) end directory('.gitlab', '.gitlab') template(".env.development.erb", ".env.development") template(".env.erb", ".env.production") template(".sops.yaml.erb", ".sops.yaml") template("decrypt-secrets", "bin/decrypt-secrets") template("encrypt-secrets", "bin/encrypt-secrets") template("database.yml.erb", "config/database.yml") template("development.rb.erb", "config/environments/development.rb") template("production.rb.erb", "config/environments/production.rb") if [:solr] template("solrcloud-upload-configset.sh", "bin/solrcloud-upload-configset.sh") template("solrcloud-assign-configset.sh", "bin/solrcloud-assign-configset.sh") end if File.exist?('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 File.exist?('Gemfile') append_to_file('Gemfile', "gem 'activerecord-nulldb-adapter'") else append_to_file('../Gemfile', "gem 'activerecord-nulldb-adapter'", { verbose: false }) # TODO: remove '../' from message after other status messages are prepended with 'stack_car/' append_to_file("../Gemfile", "gem 'pronto', groups: [:development, :test]") append_to_file("../Gemfile", "gem 'pronto-rubocop', groups: [:development, :test]") say_status(:append, '../Gemfile') end if [:deploy] || [:rancher] directory('ops') ['hosts', 'deploy.yml', 'provision.yml'].each do |template_file| template("#{template_file}.erb", "ops/#{template_file}") end say 'Please update ops/hosts with the correct server addresses' elsif [:helm] directory('chart') if [:fcrepo] directory('chart-fcrepo', 'chart/templates') end if [:sidekiq] directory('chart-sidekiq', 'chart/templates') end 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', 'worker.sh', 'nginx.sh'].each do |template_file| template("#{template_file}.erb", "ops/#{template_file}") end say 'Please find and replace all CHANGEME lines' end |
#down ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/stack_car/cli.rb', line 60 def down setup ensure_development_env if [:help] run('docker compose down --help') say 'Additional stack_car options:' say ' -a, --all Removes all containers, networks, volumes, and' say ' images created by `up`.' say ' -s, --service Specify a service defined in the Compose file' say ' whose containers and volumes should be removed.' exit(0) end if [:service] rm_vol = true if [:volumes] remove_container([:service], rm_vol) exit(0) end run_conf = 'Running down will stop and remove all of the Docker containers and networks ' \ 'defined in the docker-compose.yml file. Continue?' prompt_run_confirmation(run_conf) args = [] if [:all] prompt_run_confirmation('--all will remove all containers, volumes, networks, and local images. Continue?') args = %w[--volumes --rmi=local] else args << '--volumes' if [:volumes] args << '--rmi=local' if [:rmi] args << '--timeout' if [:timeout] end run("#{dotenv} docker compose down #{args.join(' ')}") run_with_exit('rm -rf tmp/pids/*') end |
#exec(*args) ⇒ Object
153 154 155 156 |
# File 'lib/stack_car/cli.rb', line 153 def exec(*args) setup run_with_exit("#{dotenv} docker compose exec #{[:service]} #{args.join(' ')}") end |
#provision(environment) ⇒ Object
204 205 206 207 208 |
# File 'lib/stack_car/cli.rb', line 204 def provision(environment) setup # TODO make dotenv load a specific environment? run_with_exit("DEPLOY_ENV=#{environment} #{dotenv(environment)} ansible-playbook -i ops/hosts -l #{environment}:localhost ops/provision.yml") end |
#ps(*args) ⇒ Object
124 125 126 127 |
# File 'lib/stack_car/cli.rb', line 124 def ps(*args) setup run_with_exit("#{dotenv} docker compose ps #{[:service]} #{args.join(' ')}") end |
#pull(*args) ⇒ Object
117 118 119 120 |
# File 'lib/stack_car/cli.rb', line 117 def pull(*args) setup run_with_exit("#{dotenv} docker compose pull #{[:service]} #{args.join(' ')}") end |
#push(*args) ⇒ Object
110 111 112 113 |
# File 'lib/stack_car/cli.rb', line 110 def push(*args) setup run_with_exit("#{dotenv} docker compose push #{[:service]} #{args.join(' ')}") end |
#release(environment) ⇒ Object
183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 |
# File 'lib/stack_car/cli.rb', line 183 def release(environment) Dotenv.load(".env.#{environment}", '.env') setup = Time.now.strftime("%Y%m%d%I%M%S") sha = `git rev-parse HEAD`[0..8] registry = "#{ENV['REGISTRY_HOST']}#{ENV['REGISTRY_URI']}" tag = ENV["TAG"] || 'latest' unless File.exist?("#{ENV['HOME']}/.docker/config.json") && File.readlines("#{ENV['HOME']}/.docker/config.json").grep(/#{ENV['REGISTRY_HOST']}/).size > 0 run_with_exit("#{dotenv(environment)} docker login #{ENV['REGISTRY_HOST']}") end run_with_exit("#{dotenv(environment)} docker tag #{registry}:#{tag} #{registry}:#{environment}-#{}") run_with_exit("#{dotenv(environment)} docker push #{registry}:#{environment}-#{}") run_with_exit("#{dotenv(environment)} docker tag #{registry}:#{tag} #{registry}:#{sha}") run_with_exit("#{dotenv(environment)} docker push #{registry}:#{sha}") run_with_exit("#{dotenv(environment)} docker tag #{registry}:#{tag} #{registry}:#{environment}-latest") run_with_exit("#{dotenv(environment)} docker push #{registry}:#{environment}-latest") run_with_exit("#{dotenv(environment)} docker tag #{registry}:#{tag} #{registry}:latest") run_with_exit("#{dotenv(environment)} docker push #{registry}:latest") end |
#sh(*args) ⇒ Object
161 162 163 164 |
# File 'lib/stack_car/cli.rb', line 161 def sh(*args) setup run_with_exit("#{dotenv} docker compose exec -e COLUMNS=\"\`tput cols\`\" -e LINES=\"\`tput lines\`\" #{[:service]} bash #{args.join(' ')}") end |
#ssh(environment) ⇒ Object
211 212 213 214 215 216 217 218 219 220 |
# File 'lib/stack_car/cli.rb', line 211 def ssh(environment) Dotenv.load(".env.#{environment}", '.env') setup target = ENV["#{environment.upcase}_SSH"] if target run_with_exit(target) else say "Please set #{environment.upcase}_SSH" end end |
#stop ⇒ Object
46 47 48 49 50 51 |
# File 'lib/stack_car/cli.rb', line 46 def stop setup ensure_development_env run("#{dotenv} docker compose stop #{[:service]}") run_with_exit("rm -rf tmp/pids/*") end |
#up ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/stack_car/cli.rb', line 31 def up setup ensure_development_env args = [] args << '--build' if [:build] args << '--detach' if [:detach] if [:build] run("#{dotenv} docker compose pull #{[:service]}") end run_with_exit("#{dotenv} docker compose up #{args.join(' ')} #{[:service]}") end |
#walk(*args) ⇒ Object
146 147 148 149 |
# File 'lib/stack_car/cli.rb', line 146 def walk(*args) setup run_with_exit("#{dotenv} docker compose run #{[:service]} #{args.join(' ')}") end |