Module: Geb::Site::Remote

Included in:
Geb::Site
Defined in:
lib/geb/site/remote.rb

Defined Under Namespace

Classes: RemotePathNotConfigured, RemoteURINotConfigured, SiteNotReleasedError

Instance Method Summary collapse

Instance Method Details

#launch_remoteNil

launch a remote session

Returns:

  • (Nil)

Raises:

  • SiteNotLoadedError if the site is not loaded

  • RemoteURINotConfigured if the remote uri is not configured



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/geb/site/remote.rb', line 35

def launch_remote

  # raise an error if the site is not loaded
  raise Geb::Site::SiteNotFoundError.new("Site not loaded") unless @loaded

  # make sure the remote uri is configured
  raise RemoteURINotConfigured.new unless @site_config.remote_uri

  # Temporarily disable reporting exceptions in threads
  original_thread_report_on_exception_setting = Thread.report_on_exception
  Thread.report_on_exception = false

  Geb.log "About to start an ssh session with the remote server #{@site_config.remote_uri}."

  # attempt to launch a remote session
  begin
    Open3.capture3("ssh", @site_config.remote_uri)
  rescue Interrupt, IOError
    Geb.log "Remote session interrupted."
  rescue
    Geb.log "Remote session interrupted."
  ensure
    # restore the original thread report on exception setting
    Thread.report_on_exception = original_thread_report_on_exception_setting
  end # begin ... rescue

end

#upload_release_to_remoteNil

upload the site release to the remote server

Returns:

  • (Nil)

Raises:

  • SiteNotReleasedError if the site has not been released

  • RemoteURINotConfigured if the remote uri is not configured

  • RemotePathNotConfigured if the remote path is not configured



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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
# File 'lib/geb/site/remote.rb', line 68

def upload_release_to_remote()

  # check if the release directory is empty
  raise SiteNotReleasedError.new unless released?

  # make sure the remote uri and remote path are configured
  raise RemoteURINotConfigured.new  unless @site_config.remote_uri
  raise RemotePathNotConfigured.new unless @site_config.remote_path

  # Temporarily disable reporting exceptions in threads
  original_thread_report_on_exception_setting = Thread.report_on_exception
  Thread.report_on_exception = false


  Geb.log "About to upload the site release to remote server2."

  # attempt to upload the release to the remote server
  begin

    # build up the command arguments
    command_exclude_pattern = '*.DS_Store'
    command_source_directory  = File.join(get_site_release_output_directory(), '/')
    command_remote_uri        = @site_config.remote_uri + ":" + @site_config.remote_path

    # build the rsync command
    rsync_command = [
      'rsync',
      '-av',
      '-e', 'ssh',
      "--exclude=#{command_exclude_pattern}",
      command_source_directory,
      command_remote_uri
    ]

    Geb.log " - upload command: #{rsync_command.join(' ')}"

    # execute the rsync command
    Open3.popen3(*rsync_command) do |stdin, stdout, stderr, wait_thr|

      # create threads to read the stdout
      stdout_thread = Thread.new do
        stdout.each_line { |line| Geb.log " - #{line}" }
      end

      # create threads to read the stderr
      stderr_thread = Thread.new do
        stderr.each_line { |line| Geb.log " - (error) #{line}" }
      end

      # wait for the threads to finish
      stdout_thread.join
      stderr_thread.join

      # get the status of the command
      status = wait_thr.value

      # log the status of the command
      { stdout: stdout, stderr: stderr, status: status }

    end # Open3.popen3

  rescue Interrupt, IOError
    Geb.log "Upload interrupted."
  rescue
    Geb.log "Upload interrupted."
  ensure
    # restore the original thread report on exception setting
    Thread.report_on_exception = original_thread_report_on_exception_setting
  end # begin ... rescue

end