Method: Pkg::Util::File.fetch

Defined in:
lib/packaging/util/file.rb

.fetchObject

The fetch method pulls down two files from the build-data repo that contain additional data specific to Puppet Labs release infrastructure intended to augment/override any defaults specified in the source project repo, e.g. in ext/build_defaults.yaml

It uses curl to download the files, and places them in a temporary directory, e.g. /tmp/somedirectory/project,team/Pkg::Config.builder_data_file

Retrieve build-data configurations to override/extend local build_defaults



138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
# File 'lib/packaging/util/file.rb', line 138

def fetch
  # Each team has a build-defaults file that specifies local infrastructure targets
  # for things like builders, target locations for build artifacts, etc Since much
  # of these don't change, one file can be maintained for the team.  Each project
  # also has a data file for information specific to it. If the project builds
  # both PE and not PE, it has two files, one for PE, and the other for FOSS
  #
  data_repo = Pkg::Config.build_data_repo

  if Pkg::Config.dev_build
    puts "NOTICE: This is a dev build!"
    project_data_branch = "#{Pkg::Config.project}-dev"
  else
    project_data_branch = Pkg::Config.project
  end
  team_data_branch = Pkg::Config.team

  if Pkg::Config.build_pe
    project_data_branch = "pe-#{project_data_branch}" unless project_data_branch =~ /^pe-/
    team_data_branch = "pe-#{team_data_branch}" unless team_data_branch =~ /^pe-/
  end

  # Remove .packaging directory from old-style extras loading
  FileUtils.rm_rf("#{ENV['HOME']}/.packaging") if File.directory?("#{ENV['HOME']}/.packaging")

  # Touch the .packaging file which is allows packaging to present remote tasks
  FileUtils.touch("#{ENV['HOME']}/.packaging")

  begin
    build_data_directory = Pkg::Util::File.mktemp
    %x(git clone #{data_repo} #{build_data_directory})
    unless $?.success?
      fail 'Error: could not fetch the build-data repo. Maybe you do not have the correct permissions?'
    end

    Dir.chdir(build_data_directory) do
      [team_data_branch, project_data_branch].each do |branch|
        %x(git checkout #{branch})
        unless $?.success?
          warn "Warning: no build_defaults found in branch '#{branch}' of '#{data_repo}'. Skipping."
          next
        end
        load_extras(build_data_directory)
      end
    end
  ensure
    FileUtils.rm_rf(build_data_directory)
  end
end