Class: WSlaveDocker

Inherits:
Object
  • Object
show all
Defined in:
lib/wslave_docker.rb

Instance Method Summary collapse

Constructor Details

#initializeWSlaveDocker

Returns a new instance of WSlaveDocker.



5
6
7
# File 'lib/wslave_docker.rb', line 5

def initialize
  puts 'Initializing WSlave Docker Control'
end

Instance Method Details

#_checkObject



75
76
77
78
79
80
# File 'lib/wslave_docker.rb', line 75

def _check()
  return true if (File.exist?("./config/.wslave") &&
                  File.exist?("docker-compose.yml"))
  puts "This does not appear to be the root of a WSlave managed app."
  false
end

#_force_downObject



82
83
84
# File 'lib/wslave_docker.rb', line 82

def _force_down()
  `docker-compose down --remove-orphans`
end

#_unfuck_dot_htaccessObject

Sometimes the docker container or a windows fs will screw up or delete .htaccess



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

def _unfuck_dot_htaccess()
  begin
    FileUtils.cp_r("#{__dir__}/../base/public/.htaccess", "./public/.htaccess")
    # FileUtils.chmod(0444, "./public/.htaccess")
  rescue => e
    # noop
  end
end

#consoleObject



70
71
72
73
# File 'lib/wslave_docker.rb', line 70

def console()
  return unless _check()
  system("docker-compose exec web /bin/bash")
end

#logObject



60
61
62
63
64
65
66
67
68
# File 'lib/wslave_docker.rb', line 60

def log()
  return unless _check()
  begin
    system("docker-compose logs -f")
  rescue Exception => e
    puts "\n\nEnding log trace. NOTE: Server containers are still running!\n\n"
    return
  end
end

#remove(force = false) ⇒ Object



54
55
56
57
58
# File 'lib/wslave_docker.rb', line 54

def remove(force = false)
  return unless _check()
  _force_down() if force
  `docker-compose down -v`
end

#reset(force = false) ⇒ Object



46
47
48
49
50
51
52
# File 'lib/wslave_docker.rb', line 46

def reset(force = false)
  return unless _check()
  _force_down() if force
  `docker-compose down -v`
  `docker-compose build`
  `docker-compose up -d`
end

#server(command = :start, force = false) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/wslave_docker.rb', line 9

def server(command = :start, force = false)
  case (command)
  when :start
    start(force)
  when :stop
    stop(force)
  when :reset
    reset(force)
  when :remove
    remove(force)
  when :log
    log()
  when :console
    console()
  else
    puts "server subcommand \"#{command.to_s}\" not found."
    puts "Available commands: start stop log console"
  end
end

#start(force = false) ⇒ Object



29
30
31
32
33
34
35
36
37
38
# File 'lib/wslave_docker.rb', line 29

def start(force = false)
  return unless _check()
  _force_down() if force
  `docker-compose stop` # Shutdown existing instances
  _unfuck_dot_htaccess()
  WSlaveTools.set_dev_perms
  `docker-compose build`
  `docker-compose start -d`
  `docker-compose up -d`
end

#stop(force = false) ⇒ Object



40
41
42
43
44
# File 'lib/wslave_docker.rb', line 40

def stop(force = false)
  return unless _check()
  _force_down() if force
  `docker-compose stop`
end