Skip to content

Commit 6a9387a

Browse files
balasankarcRobert Marshall
authored andcommitted
Tag container images with CI_COMMIT_REF_SLUG
- containers built in trigger builds are now tagged additionally with CI_COMMIT_REF_SLUG to enable local testing Signed-off-by: Balasankar "Balu" C <[email protected]>
1 parent 6f0568b commit 6a9387a

File tree

3 files changed

+11
-0
lines changed

3 files changed

+11
-0
lines changed

lib/gitlab/build/info/ci.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ def api_v4_url
3434
Gitlab::Util.get_env('CI_API_V4_URL')
3535
end
3636

37+
def commit_ref_slug
38+
Gitlab::Util.get_env('CI_COMMIT_REF_SLUG')
39+
end
40+
3741
def artifact_url(job_name, file_path)
3842
client = Gitlab::APIClient.new
3943
target_job_id = client.get_job_id(job_name)

lib/gitlab/tasks/docker_tasks.rake

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
require 'docker'
22
require_relative '../docker_operations'
33
require_relative '../build/info'
4+
require_relative '../build/info/ci'
45
require_relative '../build/check'
56
require_relative '../build/gitlab_image'
67
require_relative "../util.rb"
@@ -61,6 +62,10 @@ namespace :docker do
6162
task :triggered do
6263
Gitlab::Util.section('docker:push:triggered') do
6364
Build::GitlabImage.tag_and_push_to_gitlab_registry(Build::Info::Docker.tag)
65+
66+
# Also tag with CI_COMMIT_REF_SLUG so that manual testing using Docker
67+
# can use the same image name/tag.
68+
Build::GitlabImage.tag_and_push_to_gitlab_registry(Build::Info::CI.commit_ref_slug)
6469
end
6570
end
6671
end

spec/lib/gitlab/tasks/docker_tasks_spec.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,13 @@
9090
end
9191

9292
it 'pushes triggered images correctly' do
93+
allow(ENV).to receive(:[]).with('CI_COMMIT_REF_SLUG').and_return('foo-bar')
9394
allow(ENV).to receive(:[]).with('CI_REGISTRY_IMAGE').and_return('registry.gitlab.com/gitlab-org/omnibus-gitlab')
9495
allow(ENV).to receive(:[]).with("IMAGE_TAG").and_return("omnibus-12345")
9596
allow(Build::Info::Docker).to receive(:tag).and_call_original
9697

9798
expect(dummy_image).to receive(:push).with(dummy_creds, repo_tag: 'registry.gitlab.com/gitlab-org/omnibus-gitlab/gitlab-ce:omnibus-12345')
99+
expect(dummy_image).to receive(:push).with(dummy_creds, repo_tag: 'registry.gitlab.com/gitlab-org/omnibus-gitlab/gitlab-ce:foo-bar')
98100
Rake::Task['docker:push:triggered'].invoke
99101
end
100102
end

0 commit comments

Comments
 (0)