Method: Gitlab::QA::Docker::Engine#write_files

Defined in:
lib/gitlab/qa/docker/engine.rb

#write_files(name) ⇒ Object

Write to file(s) in the Docker container specified by @param name

Examples:

engine.write_files('gitlab-abc123') do |files|
  files.append('/etc/hosts', '127.0.0.1 localhost')
  files.write('/opt/other', <<~TEXT
    This is content
    That goes within /opt/other
  TEXT)

Parameters:

  • name

    The name of the Docker Container



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/gitlab/qa/docker/engine.rb', line 61

def write_files(name)
  exec(name, yield(
    Class.new do
      # @param file The name of the file
      # @param contents The content of the file to write
      # @param expand_vars Set false if you need to write an environment variable '$' to a file. The variable should be escaped \\\$
      def self.write(file, contents, expand_vars = true)
        if expand_vars
          %(echo "#{contents}" > #{file};)
        else
          %(echo '#{contents}' > #{file};)
        end
      end

      def self.append(file, contents)
        %(echo "#{contents}" >> #{file};)
      end
    end
  ))
end