Class: Gitlab::QA::Release

Inherits:
Object
  • Object
show all
Defined in:
lib/gitlab/qa/release.rb

Constant Summary collapse

CANONICAL_REGEX =
/
  \A
    (?<edition>ce|ee|jh)
    (-qa)?
    (:(?<tag>.+))?
  \z
/xi
CUSTOM_GITLAB_IMAGE_REGEX =
%r{
  \A
    (?<image_without_tag>
      (?<registry>[^/:]+(:(?<port>\d+))?)
      (?<project>.+)
      gitlab-
      (?<edition>ce|ee|jh)
    )
    (-qa)?
    (:(?<tag>.+))?
  \z
}xi
DEV_OFFICIAL_TAG_REGEX =

Official dev tag example:

12.5.4(-rc42)-ee

|————-|–|

|             |
|             |
|             |
|          edition

version

/
  \A
    (?<version>\d+\.\d+.\d+(?:-rc\d+)?)-(?<edition>ce|ee|jh)
  \z
/xi
DEV_TAG_REGEX =

Dev tag example:

12.1.201906121026-325a6632895.b340d0bd35d

|—-|————|———–|———–|

|         |           |           |
|         |           |      omnibus-ref
|         |       gitlab-ee ref
|     timestamp

version

/
  \A
    (?<version>\d+\.\d+(.\d+)?)\.(?<timestamp>\d+)-(?<gitlab_ref>[A-Za-z0-9]+)\.(?<omnibus_ref>[A-Za-z0-9]+)
  \z
/xi
DEFAULT_TAG =
'latest'
DEFAULT_CANONICAL_TAG =
'nightly'
DEV_REGISTRY =
Gitlab::QA::Runtime::Env.qa_dev_registry
COM_REGISTRY =
Gitlab::QA::Runtime::Env.qa_com_registry
InvalidImageNameError =
Class.new(RuntimeError)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(release) ⇒ Release

Returns a new instance of Release.



68
69
70
71
72
73
# File 'lib/gitlab/qa/release.rb', line 68

def initialize(release)
  @release = release.to_s.downcase
  return if valid?

  raise InvalidImageNameError, "The release image name '#{@release}' does not have the expected format."
end

Instance Attribute Details

#releaseObject (readonly)

Returns the value of attribute release.



65
66
67
# File 'lib/gitlab/qa/release.rb', line 65

def release
  @release
end

#tagObject

Tag scheme for gitlab-ce,ee images is like 11.1.0-rc12.ee.0



134
135
136
137
138
139
140
141
# File 'lib/gitlab/qa/release.rb', line 134

def tag
  @tag ||=
    if canonical?
      release.match(CANONICAL_REGEX)[:tag] || DEFAULT_CANONICAL_TAG
    else
      release.match(CUSTOM_GITLAB_IMAGE_REGEX)&.[](:tag) || DEFAULT_TAG
    end
end

Instance Method Details

#api_project_nameObject



214
215
216
# File 'lib/gitlab/qa/release.rb', line 214

def api_project_name
  project_name.gsub('ce', 'foss').gsub('-ee', '')
end

#dev_gitlab_org?Boolean

Returns:

  • (Boolean)


198
199
200
# File 'lib/gitlab/qa/release.rb', line 198

def dev_gitlab_org?
  image.start_with?(DEV_REGISTRY)
end

#editionObject



85
86
87
88
89
90
91
92
# File 'lib/gitlab/qa/release.rb', line 85

def edition
  @edition ||=
    if canonical?
      release.match(CANONICAL_REGEX)[:edition].to_sym
    else
      release.match(CUSTOM_GITLAB_IMAGE_REGEX)[:edition].to_sym
    end
end

#ee?Boolean

Returns:

  • (Boolean)


94
95
96
# File 'lib/gitlab/qa/release.rb', line 94

def ee?
  edition == :ee
end

#imageObject



104
105
106
107
108
109
110
111
# File 'lib/gitlab/qa/release.rb', line 104

def image
  @image ||=
    if canonical?
      "gitlab/gitlab-#{edition}"
    else
      release.match(CUSTOM_GITLAB_IMAGE_REGEX)[:image_without_tag]
    end
end

#login_paramsObject



152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
# File 'lib/gitlab/qa/release.rb', line 152

def 
  return if Runtime::Env.skip_pull?

  params = if dev_gitlab_org?
             Runtime::Env.require_qa_dev_access_token!

             {
               username: Runtime::Env.gitlab_dev_username,
               password: Runtime::Env.dev_access_token_variable,
               registry: DEV_REGISTRY
             }
           elsif omnibus_mirror? || omnibus_security?
             
           end

  populate_registry_env_vars(params)
end

#omnibus_login_paramsObject



180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
# File 'lib/gitlab/qa/release.rb', line 180

def 
  username, password = if Runtime::Env.ci_job_token && Runtime::Env.ci_pipeline_source.include?('pipeline')
                         ['gitlab-ci-token', Runtime::Env.ci_job_token]
                       elsif Runtime::Env.qa_container_registry_access_token
                         [Runtime::Env.gitlab_username, Runtime::Env.qa_container_registry_access_token]
                       else
                         Runtime::Env.require_qa_access_token!

                         [Runtime::Env.gitlab_username, Runtime::Env.qa_access_token]
                       end

  {
    username: username,
    password: password,
    registry: COM_REGISTRY
  }
end

#omnibus_mirror?Boolean

Returns:

  • (Boolean)


202
203
204
# File 'lib/gitlab/qa/release.rb', line 202

def omnibus_mirror?
  image.start_with?("#{COM_REGISTRY}/gitlab-org/build/omnibus-gitlab-mirror/")
end

#omnibus_security?Boolean

Returns:

  • (Boolean)


206
207
208
# File 'lib/gitlab/qa/release.rb', line 206

def omnibus_security?
  image.start_with?("#{COM_REGISTRY}/gitlab-org/security/omnibus-gitlab/")
end

#populate_registry_env_vars(params) ⇒ Object



170
171
172
173
174
175
176
177
178
# File 'lib/gitlab/qa/release.rb', line 170

def populate_registry_env_vars(params)
  if params
    Runtime::Env.release_registry_url = params[:registry]
    Runtime::Env.release_registry_username = params[:username]
    Runtime::Env.release_registry_password = params[:password]
  end

  params
end

#previous_stableObject



79
80
81
82
83
# File 'lib/gitlab/qa/release.rb', line 79

def previous_stable
  # The previous stable is always gitlab/gitlab-ce:latest or
  # gitlab/gitlab-ee:latest
  self.class.new("#{canonical_image}:latest")
end

#project_nameObject



124
125
126
127
128
129
130
131
# File 'lib/gitlab/qa/release.rb', line 124

def project_name
  @project_name ||=
    if canonical?
      "gitlab-#{edition}"
    else
      "gitlab-#{release.match(CUSTOM_GITLAB_IMAGE_REGEX)[:edition]}"
    end
end

#qa_imageObject



113
114
115
116
117
118
119
120
121
122
# File 'lib/gitlab/qa/release.rb', line 113

def qa_image
  @qa_image ||= if omnibus_mirror?
                  omnibus_project = image.match(CUSTOM_GITLAB_IMAGE_REGEX)[:project]
                  gitlab_project = ci_project_path ? "/#{ci_project_path}/" : "/gitlab-org/gitlab/"

                  "#{image.gsub(omnibus_project, gitlab_project)}-qa"
                else
                  "#{image}-qa"
                end
end

#qa_tagObject

Tag scheme for gitlab-ce,ee-qa images is like 11.1.0-rc12-ee



144
145
146
147
148
149
150
# File 'lib/gitlab/qa/release.rb', line 144

def qa_tag
  if dev_gitlab_org? && (match_data = tag.match(DEV_TAG_REGEX))
    match_data[:gitlab_ref]
  else
    tag.sub(/[-.]([ce]e)(\.(\d+))?\z/, '-\1')
  end
end

#to_eeObject



98
99
100
101
102
# File 'lib/gitlab/qa/release.rb', line 98

def to_ee
  return self if ee?

  self.class.new(to_s.sub('ce:', 'ee:'))
end

#to_sObject



75
76
77
# File 'lib/gitlab/qa/release.rb', line 75

def to_s
  "#{image}:#{tag}"
end

#valid?Boolean

Returns:

  • (Boolean)


210
211
212
# File 'lib/gitlab/qa/release.rb', line 210

def valid?
  canonical? || release.match?(CUSTOM_GITLAB_IMAGE_REGEX)
end