Skip to content

Commit 7c6c30e

Browse files
Merge branch 'make-artifact-fetches-use-library' into 'master'
Use GitLab API interface for fetching artifacts See merge request https://gitlab.com/gitlab-org/omnibus-gitlab/-/merge_requests/7007 Merged-by: Jason Plum <[email protected]> Approved-by: Dustin Collins <[email protected]> Approved-by: Jason Plum <[email protected]> Reviewed-by: Jason Plum <[email protected]> Co-authored-by: Balasankar "Balu" C <[email protected]>
2 parents 0a5afcb + 1a3db29 commit 7c6c30e

File tree

3 files changed

+5
-70
lines changed

3 files changed

+5
-70
lines changed

lib/gitlab/build/facts.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,8 @@ def qa_trigger_vars
7777
GITLAB_SEMVER_VERSION=#{Build::Info.latest_stable_tag.tr('+', '-')}
7878
RAT_REFERENCE_ARCHITECTURE=#{Gitlab::Util.get_env('RAT_REFERENCE_ARCHITECTURE') || 'omnibus-gitlab-mrs'}
7979
RAT_FIPS_REFERENCE_ARCHITECTURE=#{Gitlab::Util.get_env('RAT_FIPS_REFERENCE_ARCHITECTURE') || 'omnibus-gitlab-mrs-fips-ubuntu'}
80-
RAT_PACKAGE_URL=#{Gitlab::Util.get_env('PACKAGE_URL') || Build::Info.triggered_build_package_url(fips: false)}
81-
RAT_FIPS_PACKAGE_URL=#{Gitlab::Util.get_env('FIPS_PACKAGE_URL') || Build::Info.triggered_build_package_url(fips: true)}
80+
RAT_PACKAGE_URL=#{Gitlab::Util.get_env('PACKAGE_URL') || Build::Info::CI.triggered_package_download_url(fips: false)}
81+
RAT_FIPS_PACKAGE_URL=#{Gitlab::Util.get_env('FIPS_PACKAGE_URL') || Build::Info::CI.triggered_package_download_url(fips: true)}
8282
]
8383
end
8484

lib/gitlab/build/info.rb

Lines changed: 0 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
require 'omnibus'
2-
require 'net/http'
3-
require 'json'
42

53
require_relative '../build_iteration'
64
require_relative "../util.rb"
@@ -236,15 +234,6 @@ def log_level
236234
end
237235
end
238236

239-
# Fetch the package from an S3 bucket
240-
def deb_package_download_url(arch: 'amd64')
241-
folder = 'ubuntu-jammy'
242-
folder = "#{folder}_aarch64" if arch == 'arm64'
243-
244-
package_filename_url_safe = Info.release_version.gsub("+", "%2B")
245-
"https://#{Info.release_bucket}.#{Info.release_bucket_s3_endpoint}/#{folder}/#{Info.package}_#{package_filename_url_safe}_#{arch}.deb"
246-
end
247-
248237
# Fetch the package used in AWS AMIs from an S3 bucket
249238
def ami_deb_package_download_url(arch: 'amd64')
250239
folder = 'ubuntu-focal'
@@ -254,53 +243,6 @@ def ami_deb_package_download_url(arch: 'amd64')
254243
"https://#{Info.release_bucket}.#{Info.release_bucket_s3_endpoint}/#{folder}/#{Info.package}_#{package_filename_url_safe}_#{arch}.deb"
255244
end
256245

257-
def rpm_package_download_url(arch: 'x86_64')
258-
folder = 'el-8'
259-
folder = "#{folder}_aarch64" if arch == 'arm64'
260-
folder = "#{folder}_fips" if Build::Check.use_system_ssl?
261-
262-
package_filename_url_safe = Info.release_version.gsub("+", "%2B")
263-
"https://#{Info.release_bucket}.#{Info.release_bucket_s3_endpoint}/#{folder}/#{Info.package}-#{package_filename_url_safe}.el8.#{arch}.rpm"
264-
end
265-
266-
def get_api(path, token: nil)
267-
uri = URI("https://gitlab.com/api/v4/#{path}")
268-
req = Net::HTTP::Get.new(uri)
269-
req['PRIVATE-TOKEN'] = token || Gitlab::Util.get_env('TRIGGER_PRIVATE_TOKEN')
270-
http = Net::HTTP.new(uri.hostname, uri.port)
271-
http.use_ssl = true
272-
res = http.request(req)
273-
JSON.parse(res.body) if res.code == '200'
274-
end
275-
276-
def fetch_artifact_url(project_id, pipeline_id, fips: Build::Check.use_system_ssl?)
277-
job_name = 'Trigger:package'
278-
job_name = "#{job_name}:fips" if fips
279-
280-
output = get_api("projects/#{project_id}/pipelines/#{pipeline_id}/jobs") || {}
281-
output.map { |job| job['id'] if job['name'] == job_name }.compact.max
282-
end
283-
284-
def fetch_pipeline_jobs(project_id, pipeline_id, token)
285-
get_api("projects/#{project_id}/pipelines/#{pipeline_id}/jobs")
286-
end
287-
288-
def triggered_build_package_url(fips: Build::Check.use_system_ssl?)
289-
project_id = Gitlab::Util.get_env('CI_PROJECT_ID')
290-
pipeline_id = Gitlab::Util.get_env('CI_PIPELINE_ID')
291-
return unless project_id && !project_id.empty? && pipeline_id && !pipeline_id.empty?
292-
293-
id = fetch_artifact_url(project_id, pipeline_id, fips: fips)
294-
295-
return unless id
296-
297-
# Ubuntu 22.04 is still not FIPS compliant, so we use 20.04 packages
298-
# there.
299-
folder = fips ? 'ubuntu-focal_fips' : 'ubuntu-jammy'
300-
301-
"https://gitlab.com/api/v4/projects/#{Gitlab::Util.get_env('CI_PROJECT_ID')}/jobs/#{id}/artifacts/pkg/#{folder}/gitlab.deb"
302-
end
303-
304246
def tag_match_pattern
305247
return '*[+.]ee.*' if Check.is_ee?
306248

lib/gitlab/package_size.rb

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
require_relative "util"
22
require_relative "ohai_helper"
33
require_relative "build/check"
4+
require_relative "build/info/secrets"
45

56
require 'gitlab'
67

@@ -12,21 +13,13 @@ class PackageSizeCheck
1213

1314
class << self
1415
def fetch_sizefile
15-
api_url = Gitlab::Util.get_env('CI_API_V4_URL')
16-
project_id = Gitlab::Util.get_env('CI_PROJECT_ID')
17-
pipeline_id = Gitlab::Util.get_env('CI_PIPELINE_ID')
18-
token = Gitlab::Util.get_env('PACKAGE_SIZE_CHECK_OMNIBUS_GITLAB_MIRROR_TOKEN')
19-
20-
gitlab_client = ::Gitlab.client(endpoint: api_url, private_token: token)
21-
pipeline_jobs = gitlab_client.pipeline_jobs(project_id, pipeline_id)
22-
trigger_package_job = pipeline_jobs.find { |j| j.name == 'Trigger:package' }
16+
sizefile_url = Build::Info::CI.artifact_url("Trigger:package", "pkg/ubuntu-jammy/gitlab.deb.size")
2317

2418
# We have to use net/http here because `gitlab` gem's `download_job_artifact_file`
2519
# method doesn't support plain text files. It has to be either binary or valid JSON.
2620
# https://github.com/NARKOZ/gitlab/issues/621
27-
sizefile_url = URI("#{api_url}/projects/#{project_id}/jobs/#{trigger_package_job.id}/artifacts/pkg/ubuntu-jammy/gitlab.deb.size")
2821
req = Net::HTTP::Get.new(sizefile_url)
29-
req['PRIVATE-TOKEN'] = token
22+
req['PRIVATE-TOKEN'] = Build::Info::Secrets.api_token
3023
res = Net::HTTP.start(sizefile_url.hostname, sizefile_url.port, use_ssl: true) do |http|
3124
http.request(req)
3225
end

0 commit comments

Comments
 (0)