Commit c2ddc011 authored by John Skarbek's avatar John Skarbek Committed by Robert Speicher

Brings back ability to do nightly builds

* With the recent work to rely on creating a commit to start a pipeline,
these created a bit of havoc for nightly builds due to using the same
process.
  * The master branch was unnecessarily updated with the versions inside
  of omnibus which is undesired
* This commit strives to find a way to continue building nightlies from
passing builds
* We do this by determining if we are using an auto-deploy branch
  * if not, we'll create a temporary branch inside the dev environment
  in order to compile the frontend assets needed for the build
  * We trigger a build in omnibus using a large set of environment
  variables including:
    * all versions of gitlab components
    * setting nightly to true, allowing a package to be built
  * The trigger is set to wait 3 hours
  * After waiting we'll delete the branch as it's no longer required
parent a0725a79
......@@ -66,6 +66,7 @@ require 'release_tools/packages/publish_service'
require 'release_tools/passing_build'
require 'release_tools/patch_issue'
require 'release_tools/pick_into_label'
require 'release_tools/pipeline'
require 'release_tools/preparation_merge_request'
require 'release_tools/project/base_project'
require 'release_tools/project/cng_image'
......
......@@ -27,6 +27,16 @@ module ReleaseTools
end
def trigger_build(version_map)
if ref.match?(/\A\d+-\d+-auto-deploy-\d+\z/)
trigger_commit_build(version_map)
else
trigger_branch_build(version_map)
end
end
private
def trigger_commit_build(version_map)
commit = ReleaseTools::ComponentVersions.update_omnibus(ref, version_map)
url = commit_url(ReleaseTools::Project::OmnibusGitlab, commit.short_id)
......@@ -36,7 +46,22 @@ module ReleaseTools
# TODO: Tagging
end
private
def trigger_branch_build(version_map)
pipeline_id = ENV.fetch('CI_PIPELINE_ID', 'pipeline_id_unset')
branch_name = "#{ref}-#{pipeline_id}"
$stdout.puts "Creating branch #{branch_name}"
ReleaseTools::GitlabDevClient.create_branch(branch_name, ref, project)
ReleaseTools::Pipeline.new(
project,
ref,
version_map
).trigger
$stdout.puts "Deleting branch #{branch_name}"
ReleaseTools::GitlabDevClient.delete_branch(branch_name, project)
end
def commit_url(project, id)
"https://gitlab.com/#{project.path}/commit/#{id}"
......
module ReleaseTools
class Pipeline
attr_reader :project, :sha
def initialize(project, sha, versions)
@project = project
@sha = sha
@token = ENV.fetch('OMNIBUS_BUILD_TRIGGER_TOKEN') do |name|
raise "Missing environment variable `#{name}`"
end
@versions = versions
end
def trigger
$stdout.puts "Trigger build: #{sha} for #{project.path}".indent(4)
trigger = ReleaseTools::GitlabDevClient.run_trigger(
ReleaseTools::Project::OmnibusGitlab,
@token,
'master',
build_variables
)
$stdout.puts "Pipeline triggered: #{trigger.web_url}".indent(4)
wait(trigger.id)
end
private
def status(id)
ReleaseTools::GitlabDevClient.pipeline(ReleaseTools::Project::OmnibusGitlab, id).status
end
def wait(id)
interval = 60 # seconds
max_duration = 3600 * 3 # 3 hours
start = Time.now.to_i
$stdout.puts "Waiting on pipeline for #{max_duration} seconds...".indent(4)
loop do
if ReleaseTools::TimeUtil.timeout?(start, max_duration)
raise "Pipeline timeout after waiting for #{max_duration} seconds."
end
case status(id)
when 'created', 'pending', 'running'
sleep interval
when 'success'
$stdout.puts "Pipeline succeeded in #{max_duration} seconds."
break
else
raise 'Pipeline did not succeed.'
end
end
end
def build_variables
@versions.merge(
'GITLAB_VERSION' => @sha,
'NIGHTLY' => 'true',
'ee' => @project == ReleaseTools::Project::GitlabEe
)
end
end
end
---
http_interactions:
- request:
method: post
uri: https://dev.gitlab.org/api/v4/projects/gitlab%2Fomnibus-gitlab/trigger/pipeline
body:
encoding: UTF-8
string: token=[OMNIBUS_BUILD_TRIGGER_TOKEN]&ref=master&variables[VERSION]=1.2.3&variables[GITLAB_VERSION]=master&variables[NIGHTLY]=true&variables[ee]=false
headers:
Accept:
- application/json
Content-Type:
- application/x-www-form-urlencoded
User-Agent:
- Gitlab Ruby Gem 4.10.0
response:
status:
code: 201
message: Created
headers:
Server:
- nginx
Date:
- Fri, 26 Apr 2019 17:21:32 GMT
Content-Type:
- application/json
Content-Length:
- '990'
Connection:
- keep-alive
Cache-Control:
- max-age=0, private, must-revalidate
Etag:
- W/"0f0d825903a3c2d7e532fdf488f3e12c"
Vary:
- Origin
X-Content-Type-Options:
- nosniff
X-Frame-Options:
- SAMEORIGIN
X-Request-Id:
- f55f8dpt5d2
X-Runtime:
- '1.175520'
Strict-Transport-Security:
- max-age=31536000
Referrer-Policy:
- strict-origin-when-cross-origin
body:
encoding: UTF-8
string: '{"id":110524,"sha":"c48bb4cb7732871a946b96dff1b127bace6ea828","ref":"master","status":"pending","web_url":"https://dev.gitlab.org/gitlab/omnibus-gitlab/pipelines/110524","before_sha":"0000000000000000000000000000000000000000","tag":false,"yaml_errors":null,"user":{"id":483,"name":"John
Skarbek","username":"skarbek","state":"active","avatar_url":"https://secure.gravatar.com/avatar/c6455ce4726023aac6dd7fb0acd1f236?s=80\u0026d=identicon","web_url":"https://dev.gitlab.org/skarbek"},"created_at":"2019-04-26T17:21:31.881Z","updated_at":"2019-04-26T17:21:32.342Z","started_at":null,"finished_at":null,"committed_at":null,"duration":null,"coverage":null,"detailed_status":{"icon":"status_pending","text":"pending","label":"pending","group":"pending","tooltip":"pending","has_details":false,"details_path":"/gitlab/omnibus-gitlab/pipelines/110524","illustration":null,"favicon":"/assets/ci_favicons/favicon_status_pending-5bdf338420e5221ca24353b6bff1c9367189588750632e9a871b7af09ff6a2ae.png"}}'
http_version:
recorded_at: Fri, 26 Apr 2019 17:21:32 GMT
- request:
method: get
uri: https://dev.gitlab.org/api/v4/projects/gitlab%2Fomnibus-gitlab/pipelines/110524
body:
encoding: US-ASCII
string: ''
headers:
Accept:
- application/json
Content-Type:
- application/x-www-form-urlencoded
User-Agent:
- Gitlab Ruby Gem 4.10.0
Private-Token:
- "[DEV_API_PRIVATE_TOKEN]"
response:
status:
code: 200
message: OK
headers:
Server:
- nginx
Date:
- Fri, 26 Apr 2019 18:40:49 GMT
Content-Type:
- application/json
Content-Length:
- '1059'
Connection:
- keep-alive
Cache-Control:
- max-age=0, private, must-revalidate
Etag:
- W/"0b97123edb97c6f38a8bafb202831f19"
Vary:
- Origin
X-Content-Type-Options:
- nosniff
X-Frame-Options:
- SAMEORIGIN
X-Request-Id:
- 254uVlbA8G5
X-Runtime:
- '0.033876'
Strict-Transport-Security:
- max-age=31536000
Referrer-Policy:
- strict-origin-when-cross-origin
body:
encoding: UTF-8
string: '{"id":110524,"sha":"c48bb4cb7732871a946b96dff1b127bace6ea828","ref":"master","status":"success","web_url":"https://dev.gitlab.org/gitlab/omnibus-gitlab/pipelines/110524","before_sha":"0000000000000000000000000000000000000000","tag":false,"yaml_errors":null,"user":{"id":483,"name":"John
Skarbek","username":"skarbek","state":"active","avatar_url":"https://secure.gravatar.com/avatar/c6455ce4726023aac6dd7fb0acd1f236?s=80\u0026d=identicon","web_url":"https://dev.gitlab.org/skarbek"},"created_at":"2019-04-26T17:21:31.881Z","updated_at":"2019-04-26T18:39:50.609Z","started_at":"2019-04-26T17:21:36.059Z","finished_at":"2019-04-26T18:39:50.603Z","committed_at":null,"duration":4681,"coverage":null,"detailed_status":{"icon":"status_warning","text":"passed","label":"passed
with warnings","group":"success-with-warnings","tooltip":"passed","has_details":false,"details_path":"/gitlab/omnibus-gitlab/pipelines/110524","illustration":null,"favicon":"/assets/ci_favicons/favicon_status_success-8451333011eee8ce9f2ab25dc487fe24a8758c694827a582f17f42b0a90446a2.png"}}'
http_version:
recorded_at: Fri, 26 Apr 2019 18:40:49 GMT
recorded_with: VCR 2.9.3
......@@ -52,14 +52,45 @@ describe ReleaseTools::PassingBuild do
end
describe '#trigger_build' do
let(:fake_client) { spy }
describe 'when using auto-deploy' do
let(:fake_client) { spy }
let(:project) { ReleaseTools::Project::GitlabCe }
let(:version_map) { { 'VERSION' => '1.2.3' } }
it 'updates Omnibus versions', :silence_stdout do
expect(ReleaseTools::ComponentVersions)
.to receive(:update_omnibus).with('master', version_map)
.and_return(double('Commit', short_id: 'abcdefg'))
subject(:service) { described_class.new(project, '11-10-auto-deploy-1234') }
it 'updates Omnibus versions', :silence_stdout do
expect(ReleaseTools::ComponentVersions)
.to receive(:update_omnibus).with('11-10-auto-deploy-1234', version_map)
.and_return(double('Commit', short_id: 'abcdefg'))
service.trigger_build(version_map)
end
end
describe 'when not using auto-deploy' do
let(:fake_client) { spy }
let(:project) { ReleaseTools::Project::GitlabCe }
let(:version_map) { { 'VERSION' => '1.2.3' } }
let(:pipeline_id) { ENV.fetch('CI_PIPELINE_ID', 'pipeline_id_unset') }
subject(:service) { described_class.new(project, 'master') }
it 'triggers a pipeline build', :silence_stdout do
expect(ReleaseTools::GitlabDevClient)
.to receive(:create_branch).with("master-#{pipeline_id}", 'master', project)
allow(ReleaseTools::Pipeline).to receive(:new).and_call_original
expect(ReleaseTools::Pipeline)
.to receive(:new).with(project, 'master', version_map)
expect(ReleaseTools::GitlabDevClient)
.to receive(:delete_branch).with("master-#{pipeline_id}", project)
service.trigger_build(version_map)
VCR.use_cassette('pipeline/trigger') do
service.trigger_build(version_map)
end
end
end
end
end
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