Skip to content
Snippets Groups Projects
Unverified Commit f2ca82dd authored by Balasankar "Balu" C's avatar Balasankar "Balu" C
Browse files

Make Docker tag computation respect IMAGE_TAG if set

parent ddfe5594
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -341,12 +341,6 @@ Trigger:gitlab-docker:
stage: trigger-docker
script:
- if [ -n "$TRIGGERED_USER" ] && [ -n "$TRIGGER_SOURCE" ]; then echo "Pipeline triggered by $TRIGGERED_USER at $TRIGGER_SOURCE"; fi
# While triggering from omnibus repo in .com, we explicitly pass IMAGE_TAG
# variable, which will be used to tag the final Docker image.
# So, if IMAGE_TAG variable is empty, it means the trigger happened from
# either CE or EE repository. In that case, we can use the GITLAB_VERSION
# variable as IMAGE_TAG.
- if [ -z "${IMAGE_TAG}" ]; then export IMAGE_TAG=${GITLAB_VERSION}; fi
- bundle exec rake docker:build:image
- bundle exec rake docker:push:triggered
<<: *com-trigger-only
Loading
Loading
@@ -363,8 +357,6 @@ Trigger:qa-docker:
stage: trigger-docker
script:
- if [ -n "$TRIGGERED_USER" ] && [ -n "$TRIGGER_SOURCE" ]; then echo "Pipeline triggered by $TRIGGERED_USER at $TRIGGER_SOURCE"; fi
# For builds triggered from omnibus project, we are explicitly specifying IMAGE_TAG
- if [ -z "$IMAGE_TAG" ]; then export IMAGE_TAG=$GITLAB_VERSION; fi
- bundle exec rake qa:build
- bundle exec rake qa:push:triggered
<<: *com-trigger-only
Loading
Loading
@@ -376,8 +368,6 @@ Trigger:qa-test:
image: "${PUBLIC_BUILDER_IMAGE_REGISTRY}/ruby_docker:${BUILDER_IMAGE_REVISION}"
script:
- if [ -n "$TRIGGERED_USER" ] && [ -n "$TRIGGER_SOURCE" ]; then echo "Pipeline triggered by $TRIGGERED_USER at $TRIGGER_SOURCE"; fi
# For builds triggered from omnibus project, we are explicitly specifying IMAGE_TAG
- if [ -z "$IMAGE_TAG" ]; then export IMAGE_TAG=$GITLAB_VERSION; fi
- bundle exec rake qa:test
<<: *com-trigger-only
dependencies: []
Loading
Loading
Loading
Loading
@@ -65,7 +65,7 @@ module Build
end
 
def docker_tag
Info.release_version.tr('+', '-')
Gitlab::Util.get_env('IMAGE_TAG') || Info.release_version.tr('+', '-')
end
 
def gitlab_version
Loading
Loading
@@ -190,14 +190,7 @@ module Build
end
 
def image_reference
if Gitlab::Util.get_env('CI_PROJECT_PATH') == OMNIBUS_PROJECT_MIRROR_PATH && %w[trigger pipeline].include?(Gitlab::Util.get_env('CI_PIPELINE_SOURCE'))
"#{Build::GitlabImage.gitlab_registry_image_address}:#{Gitlab::Util.get_env('IMAGE_TAG')}"
elsif Build::Check.is_nightly? || Build::Check.on_tag?
# We push nightly images to both dockerhub and gitlab registry
"#{Build::GitlabImage.gitlab_registry_image_address}:#{Info.docker_tag}"
else
abort 'unknown pipeline type: only support triggered/nightly/tag pipeline'
end
"#{Build::GitlabImage.gitlab_registry_image_address}:#{Info.docker_tag}"
end
 
def deploy_env
Loading
Loading
Loading
Loading
@@ -19,7 +19,6 @@ module Build
"variables[BUILDER_IMAGE_REGISTRY]" => Gitlab::Util.get_env('BUILDER_IMAGE_REGISTRY'),
"variables[PUBLIC_BUILDER_IMAGE_REGISTRY]" => Gitlab::Util.get_env('PUBLIC_BUILDER_IMAGE_REGISTRY'),
"variables[COMPILE_ASSETS]" => Gitlab::Util.get_env('COMPILE_ASSETS'),
"variables[IMAGE_TAG]" => Build::Info.docker_tag,
"variables[ee]" => Gitlab::Util.get_env("ee") || "false",
"variables[TRIGGERED_USER]" => Gitlab::Util.get_env("TRIGGERED_USER") || Gitlab::Util.get_env("GITLAB_USER_NAME"),
"variables[TRIGGER_SOURCE]" => Gitlab::Util.get_env('CI_JOB_URL'),
Loading
Loading
Loading
Loading
@@ -56,7 +56,7 @@ namespace :docker do
 
desc "Push triggered Docker Image to GitLab Registry"
task :triggered do
Build::GitlabImage.tag_and_push_to_gitlab_registry(Gitlab::Util.get_env('IMAGE_TAG'))
Build::GitlabImage.tag_and_push_to_gitlab_registry(Build::Info.docker_tag)
end
end
 
Loading
Loading
Loading
Loading
@@ -53,13 +53,13 @@ namespace :qa do
 
desc "Push triggered version of gitlab-{ce,ee}-qa to the GitLab registry"
task :triggered do
Build::QAImage.tag_and_push_to_gitlab_registry(Gitlab::Util.get_env('IMAGE_TAG'))
Build::QAImage.tag_and_push_to_gitlab_registry(Build::Info.docker_tag)
end
end
 
desc "Run QA tests"
task :test do
image_address = Build::GitlabImage.gitlab_registry_image_address(tag: Gitlab::Util.get_env('IMAGE_TAG'))
image_address = Build::GitlabImage.gitlab_registry_image_address(tag: Build::Info.docker_tag)
Build::QATrigger.invoke!(image: image_address, post_comment: true).wait!
end
 
Loading
Loading
Loading
Loading
@@ -66,6 +66,11 @@ RSpec.describe Build::Info do
it 'returns package version when regular build' do
expect(described_class.docker_tag).to eq('12.121.12-ce.1')
end
it 'respects IMAGE_TAG if set' do
allow(ENV).to receive(:[]).with('IMAGE_TAG').and_return('foobar')
expect(described_class.docker_tag).to eq('foobar')
end
end
 
# Specs for latest_tag and for latest_stable_tag are really useful since we
Loading
Loading
@@ -208,60 +213,6 @@ RSpec.describe Build::Info do
end
end
 
describe '.image_reference' do
before do
allow(ENV).to receive(:[]).and_call_original
allow(ENV).to receive(:[]).with('IMAGE_TAG').and_return('foo')
allow(Build::GitlabImage).to receive(:gitlab_registry_image_address).and_return('mock.gitlab.com/omnibus')
allow(Build::Info).to receive(:docker_tag).and_return('bar')
end
context 'On a triggered pipeline' do
before do
allow(ENV).to receive(:[]).with('CI_PROJECT_PATH').and_return('gitlab-org/build/omnibus-gitlab-mirror')
allow(ENV).to receive(:[]).with('CI_PIPELINE_SOURCE').and_return('trigger')
end
it 'returns image reference correctly' do
expect(described_class.image_reference).to eq("mock.gitlab.com/omnibus:foo")
end
end
context 'On a nightly pipeline' do
before do
allow(Build::Check).to receive(:is_nightly?).and_return(true)
end
it 'returns image reference correctly' do
expect(described_class.image_reference).to eq("mock.gitlab.com/omnibus:bar")
end
end
context 'On a tag pipeline' do
before do
allow(Build::Check).to receive(:is_nightly?).and_return(false)
allow(Build::Check).to receive(:on_tag?).and_return(true)
end
it 'returns image reference correctly' do
expect(described_class.image_reference).to eq("mock.gitlab.com/omnibus:bar")
end
end
context 'On a regular pipeline' do
before do
allow(Build::Check).to receive(:is_nightly?).and_return(false)
allow(Build::Check).to receive(:on_tag?).and_return(false)
end
it 'raises error' do
expect { described_class.image_reference }
.to raise_error(SystemExit,
/unknown pipeline type: only support triggered\/nightly\/tag pipeline/)
end
end
end
describe '.deploy_env' do
before do
allow(ENV).to receive(:[]).with('AUTO_DEPLOY_ENVIRONMENT').and_return('ad')
Loading
Loading
Loading
Loading
@@ -120,6 +120,7 @@ RSpec.describe 'docker', type: :rake do
it 'pushes triggered images correctly' do
allow(ENV).to receive(:[]).with('CI_REGISTRY_IMAGE').and_return('registry.gitlab.com/gitlab-org/omnibus-gitlab')
allow(ENV).to receive(:[]).with("IMAGE_TAG").and_return("omnibus-12345")
allow(Build::Info).to receive(:docker_tag).and_call_original
 
expect(dummy_image).to receive(:push).with(dummy_creds, repo_tag: 'registry.gitlab.com/gitlab-org/omnibus-gitlab/gitlab-ce:omnibus-12345')
Rake::Task['docker:push:triggered'].invoke
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment