Commit 19ed1d98 authored by DJ Mountney's avatar DJ Mountney Committed by DJ Mountney

Merge branch 'dev-version-file-location' into 'master'

Use API to fetch VERSION files from dev

See merge request charts/gitlab!726
parent 52e2a941
Pipeline #56421376 failed with stages
in 21 minutes and 43 seconds
...@@ -2,19 +2,29 @@ require_relative 'version' ...@@ -2,19 +2,29 @@ require_relative 'version'
require 'open-uri' require 'open-uri'
require 'uri' require 'uri'
require 'cgi'
class VersionFetcher class VersionFetcher
def initialize(version, repo) def initialize(version, repo)
@version = Version.new(version) @version = Version.new(version)
@repo = repo @repo = repo
@api_token = ENV['FETCH_DEV_ARTIFACTS_PAT']
@api_url = if @repo.start_with?('gitlab/')
'https://dev.gitlab.org/api/v4'
elsif @repo.start_with?('gitlab-org/')
'https://gitlab.com/api/v4'
else
ENV['CI_API_V4_URL']
end
end end
# GitLab Shell Version # GitLab Shell Version
def gitlab_shell def gitlab_shell
return @version if @version == 'master' return @version if @version == 'master'
url = "#{@repo}/raw/#{ref(@version)}/GITLAB_SHELL_VERSION" url = "#{@api_url}/projects/#{CGI.escape(@repo)}/repository/files/GITLAB_SHELL_VERSION/raw?ref=#{ref(@version)}"
new_version = URI.parse(url).read.strip $stdout.puts "Getting GitLab Shell version from #{url}"
new_version = open(url, 'PRIVATE-TOKEN' => @api_token).read.strip
$stdout.puts "# Shell appVersion: #{new_version}" $stdout.puts "# Shell appVersion: #{new_version}"
new_version new_version
end end
...@@ -23,8 +33,9 @@ class VersionFetcher ...@@ -23,8 +33,9 @@ class VersionFetcher
def gitaly def gitaly
return @version if @version == 'master' return @version if @version == 'master'
url = "#{@repo}/raw/#{ref(@version)}/GITALY_SERVER_VERSION" url = "#{@api_url}/projects/#{CGI.escape(@repo)}/repository/files/GITALY_SERVER_VERSION/raw?ref=#{ref(@version)}"
new_version = URI.parse(url).read.strip $stdout.puts "Getting Gitaly version from #{url}"
new_version = open(url, 'PRIVATE-TOKEN' => @api_token).read.strip
$stdout.puts "# Gitaly appVersion: #{new_version}" $stdout.puts "# Gitaly appVersion: #{new_version}"
new_version new_version
end end
......
...@@ -24,7 +24,7 @@ class VersionOptionsParser ...@@ -24,7 +24,7 @@ class VersionOptionsParser
# defaults # defaults
options.working_dir = Dir.pwd options.working_dir = Dir.pwd
options.include_subcharts = false options.include_subcharts = false
options.gitlab_repo = "https://gitlab.com/gitlab-org/gitlab-ee" options.gitlab_repo = "gitlab-org/gitlab-ee"
OptionParser.new do |opts| OptionParser.new do |opts|
opts.banner = "Usage: #{__FILE__} [options] \n\n" opts.banner = "Usage: #{__FILE__} [options] \n\n"
......
...@@ -2,30 +2,64 @@ require 'spec_helper' ...@@ -2,30 +2,64 @@ require 'spec_helper'
require_relative '../../../scripts/lib/version_fetcher.rb' require_relative '../../../scripts/lib/version_fetcher.rb'
describe VersionFetcher do describe VersionFetcher do
let(:repo_url) { 'https://gitlab.com/gitlab-org/gitlab-ce' } let(:com_path) { 'gitlab-org%2Fgitlab-ce/repository/files/GITLAB_SHELL_VERSION/raw?ref=v11.8.0' }
let(:uri_response) { URI.parse(repo_url) } let(:dev_path) { 'gitlab%2Fgitlabhq/repository/files/GITLAB_SHELL_VERSION/raw?ref=v11.8.0' }
let(:version_fetcher) { VersionFetcher.new('v11.8.0', repo_url) } let(:custom_path) { 'johndoe%2Fgitlab-ee/repository/files/GITLAB_SHELL_VERSION/raw?ref=v11.8.0' }
before do before do
allow(URI).to receive(:parse).and_return(uri_response) allow(ENV).to receive(:[]).and_call_original
allow(uri_response).to receive(:read).and_return("1.2.3\n") allow(ENV).to receive(:[]).with('FETCH_DEV_ARTIFACTS_PAT').and_return(nil)
allow(version_fetcher).to receive(:gitlab_shell).and_call_original end
allow(version_fetcher).to receive(:gitaly).and_call_original
describe 'detecting API URL' do
it 'works correctly gitlab.com registry' do
version_fetcher = VersionFetcher.new('v11.8.0', 'gitlab-org/gitlab-ce')
allow(version_fetcher).to receive_message_chain(:open, :read).and_return("1.2.3\n")
expect(version_fetcher).to receive(:open).with("https://gitlab.com/api/v4/projects/#{com_path}", { 'PRIVATE-TOKEN' => nil })
version_fetcher.fetch('gitlab-shell')
end
it 'works correctly dev registry' do
allow(ENV).to receive(:[]).with('FETCH_DEV_ARTIFACTS_PAT').and_return('myrandomtoken')
version_fetcher = VersionFetcher.new('v11.8.0', 'gitlab/gitlabhq')
allow(version_fetcher).to receive_message_chain(:open, :read).and_return("1.2.3\n")
expect(version_fetcher).to receive(:open).with("https://dev.gitlab.org/api/v4/projects/#{dev_path}", { 'PRIVATE-TOKEN' => 'myrandomtoken'})
version_fetcher.fetch('gitlab-shell')
end
it 'falls back correctly to current registry for unknown projects' do
version_fetcher = VersionFetcher.new('v11.8.0', 'johndoe/gitlab-ee')
allow(version_fetcher).to receive_message_chain(:open, :read).and_return("1.2.3\n")
expect(version_fetcher).to receive(:open).with("#{ENV['CI_API_V4_URL']}/projects/#{custom_path}", { 'PRIVATE-TOKEN' => nil})
version_fetcher.fetch('gitlab-shell')
end
end end
describe '#gitlab_shell' do describe 'instance methods' do
it 'returns correct value' do let(:version_fetcher) { VersionFetcher.new('v11.8.0', 'gitlab-org/gitlab-ce') }
expect(version_fetcher.gitlab_shell).to eq('1.2.3')
before do
allow(version_fetcher).to receive_message_chain(:open, :read).and_return("1.2.3\n")
allow(version_fetcher).to receive(:gitlab_shell).and_call_original
allow(version_fetcher).to receive(:gitaly).and_call_original
end
describe '#gitlab_shell' do
it 'returns correct value' do
expect(version_fetcher.gitlab_shell).to eq('1.2.3')
end
end end
describe '#gitaly' do describe '#gitaly' do
it 'returns correct value' do it 'returns correct value' do
expect(version_fetcher.fetch('gitaly')).to eq('1.2.3') expect(version_fetcher.gitaly).to eq('1.2.3')
end end
end end
describe '#fetch' do describe '#fetch' do
it 'callse subchart methods' do it 'calls subchart methods' do
expect(version_fetcher).to receive(:gitlab_shell) expect(version_fetcher).to receive(:gitlab_shell)
expect(version_fetcher).to receive(:gitaly) expect(version_fetcher).to receive(:gitaly)
version_fetcher.fetch('gitlab-shell') version_fetcher.fetch('gitlab-shell')
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment