Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[command] for running container easy
- Loading branch information
Showing
2 changed files
with
62 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#!/usr/bin/env ruby | ||
require 'thor' | ||
require_relative '../lib/gaku/container' | ||
|
||
class GakuCLI < Thor | ||
desc 'container', 'handle container for gaku' | ||
argument :command, default: 'start', description: 'action to execute' | ||
def container | ||
return unless check | ||
Gaku::Container.new(command).execute | ||
end | ||
|
||
desc 'version', "Prints the version of the installed WSlave" | ||
def version() | ||
require 'rubygems' | ||
spec = Gem::Specification::load("#{__dir__}/../gaku.gemspec") | ||
puts spec.version | ||
end | ||
|
||
private | ||
|
||
def check | ||
return true if File.exist?("Dockerfile") && File.exist?("docker-compose.yml") | ||
puts "This does not appear to be the root of gaku." | ||
false | ||
end | ||
|
||
end | ||
|
||
GakuCLI.start(ARGV) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
module Gaku | ||
class Container | ||
attr_accessor :command | ||
|
||
def initialize(command) | ||
require 'pry';binding.pry | ||
@command = command | ||
end | ||
|
||
def execute | ||
system(resolve_command) | ||
end | ||
|
||
private | ||
|
||
def resolve_command | ||
case command | ||
when 'start' | ||
'docker-compose up' | ||
when 'console' | ||
'docker-compose exec web bundle exec rails console' | ||
when 'shell' | ||
'docker-compose exec web bundle exec /bin/bash' | ||
when 'sample' | ||
'docker-compose exec web bundle exec rake db:sample' | ||
when 'detach' | ||
'docker-compose up -d' | ||
end | ||
end | ||
|
||
end | ||
end |