Module: Dapp::Project::Shellout::System

Included in:
Dapp::Project
Defined in:
lib/dapp/project/shellout/system.rb

Overview

System

Constant Summary collapse

SYSTEM_SHELLOUT_IMAGE =
'ubuntu:14.04'.freeze
SYSTEM_SHELLOUT_VERSION =
3

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.default_env_keys ⇒ Object



94
95
96
# File 'lib/dapp/project/shellout/system.rb', line 94

def default_env_keys
  @default_env_keys ||= []
end

Instance Method Details

#system_shellout(command, raise_error: false, **kwargs) ⇒ Object



59
60
61
62
63
64
65
# File 'lib/dapp/project/shellout/system.rb', line 59

def system_shellout(command, raise_error: false, **kwargs)
  if raise_error
    shellout! _to_system_shellout_command(command), **kwargs
  else
    shellout _to_system_shellout_command(command), **kwargs
  end
end

#system_shellout!(command, **kwargs) ⇒ Object



67
68
69
# File 'lib/dapp/project/shellout/system.rb', line 67

def system_shellout!(command, **kwargs)
  system_shellout(command, raise_error: true, **kwargs)
end

#system_shellout_container ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/dapp/project/shellout/system.rb', line 17

def system_shellout_container
  do_livecheck = false

  @system_shellout_container ||= begin
    lock(system_shellout_container_name) do
      cmd = shellout("docker inspect -f {{.State.Running}} #{system_shellout_container_name}")
      if cmd.exitstatus.nonzero?
        start_container = true
      elsif cmd.stdout.strip == 'false'
        shellout!("docker rm -f #{system_shellout_container_name}")
        start_container = true
      else
        start_container = false
      end

      if start_container
        volumes_from = [base_container, gitartifact_container]
        log_secondary_process(t(code: 'process.system_shellout_container_loading'), short: true) do
          shellout! ['docker run --detach --privileged',
                     "--name #{system_shellout_container_name}",
                     *volumes_from.map { |container| "--volumes-from #{container}" },
                     '--volume /:/.system_shellout_root',
                     "#{SYSTEM_SHELLOUT_IMAGE} #{bash_path} -ec 'while true ; do sleep 1 ; done'"].join(' ')

          shellout! ["docker exec #{system_shellout_container_name}",
                     "bash -ec '#{[
                       'mkdir -p /.system_shellout_root/.dapp',
                       'mount --rbind /.dapp /.system_shellout_root/.dapp'
                     ].join(' && ')}'"].join(' ')
        end
      end
    end

    do_livecheck = true
    system_shellout_container_name
  end

  system_shellout_livecheck! if do_livecheck

  @system_shellout_container
end

#system_shellout_container_name ⇒ Object



10
11
12
13
14
15
# File 'lib/dapp/project/shellout/system.rb', line 10

def system_shellout_container_name
  "dapp_system_shellout_#{hashsum [SYSTEM_SHELLOUT_VERSION,
                                   SYSTEM_SHELLOUT_IMAGE,
                                   Deps::Base::BASE_VERSION,
                                   Deps::Gitartifact::GITARTIFACT_VERSION]}"
end