Add latest changes from gitlab-org/gitlab@master

This commit is contained in:
GitLab Bot 2023-11-16 09:13:14 +00:00
parent 4b74e7efc0
commit 34a59635a9
52 changed files with 138 additions and 653 deletions

View File

@ -31,7 +31,6 @@ RSpec/FilePath:
- 'spec/requests/api/ci/runner/jobs_artifacts_spec.rb'
- 'spec/requests/api/ci/runner/jobs_put_spec.rb'
- 'spec/requests/api/ci/runner/jobs_request_post_spec.rb'
- 'spec/requests/api/ci/runner/jobs_request_yamls_spec.rb'
- 'spec/requests/api/ci/runner/jobs_trace_spec.rb'
- 'spec/requests/api/ci/runner/runners_delete_spec.rb'
- 'spec/requests/api/ci/runner/runners_post_spec.rb'

View File

@ -509,18 +509,6 @@
"description": "Command or script that should be executed as the container's entrypoint. It will be translated to Docker's --entrypoint option while creating the container. The syntax is similar to Dockerfile's ENTRYPOINT directive, where each shell token is a separate string in the array.",
"minItems": 1
},
"docker": {
"type": "object",
"description": "Options to pass to Runners Docker Executor",
"additionalProperties": false,
"properties": {
"platform": {
"type": "string",
"minLength": 1,
"description": "Image architecture to pull."
}
}
},
"pull_policy": {
"markdownDescription": "Specifies how to pull the image in Runner. It can be one of `always`, `never` or `if-not-present`. The default value is `always`. [Learn more](https://docs.gitlab.com/ee/ci/yaml/#imagepull_policy).",
"default": "always",
@ -591,18 +579,6 @@
"type": "string"
}
},
"docker": {
"type": "object",
"description": "Options to pass to Runners Docker Executor",
"additionalProperties": false,
"properties": {
"platform": {
"type": "string",
"minLength": 1,
"description": "Image architecture to pull."
}
}
},
"pull_policy": {
"markdownDescription": "Specifies how to pull the image in Runner. It can be one of `always`, `never` or `if-not-present`. The default value is `always`. [Learn more](https://docs.gitlab.com/ee/ci/yaml/#servicepull_policy).",
"default": "always",

View File

@ -1,5 +1,4 @@
# frozen_string_literal: true
#
# JsonSchemaValidator
#
@ -25,19 +24,11 @@ class JsonSchemaValidator < ActiveModel::EachValidator
end
def validate_each(record, attribute, value)
value = value.to_h.deep_stringify_keys if options[:hash_conversion] == true
value = value.to_h.stringify_keys if options[:hash_conversion] == true
value = Gitlab::Json.parse(value.to_s) if options[:parse_json] == true && !value.nil?
if options[:detail_errors]
validator.validate(value).each do |error|
message = format(
_("the '%{data_pointer}' must be a valid '%{type}'"),
data_pointer: error['data_pointer'], type: error['type']
)
record.errors.add(attribute, message)
end
else
record.errors.add(attribute, _("must be a valid json schema")) unless valid_schema?(value)
unless valid_schema?(value)
record.errors.add(attribute, _("must be a valid json schema"))
end
end

View File

@ -71,6 +71,7 @@ In the following table, you can see:
| [Users and permissions report](../../administration/admin_area.md#user-permission-export) | GitLab 16.6 and later |
| [Advanced search](../../user/search/advanced_search.md) | GitLab 16.6 and later |
| [DevOps Adoption](../../user/group/devops_adoption/index.md) | GitLab 16.6 and later |
| [Сross-project pipelines with artifacts dependencies](../../ci/yaml/index.md#needsproject) | GitLab 16.7 and later |
### Enable registration features

Binary file not shown.

Before

Width:  |  Height:  |  Size: 63 KiB

After

Width:  |  Height:  |  Size: 20 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 74 KiB

After

Width:  |  Height:  |  Size: 21 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 410 KiB

After

Width:  |  Height:  |  Size: 117 KiB

View File

@ -2439,37 +2439,6 @@ image:
- [Override the entrypoint of an image](../docker/using_docker_images.md#override-the-entrypoint-of-an-image).
#### `image:docker`
> [Introduced](https://gitlab.com/gitlab-org/gitlab-runner/-/issues/27919) in GitLab 16.7. Requires GitLab Runner 16.7 or later.
Use `image:docker` to pass options to the Docker executor of a GitLab Runner.
**Keyword type**: Job keyword. You can use it only as part of a job or in the
[`default` section](#default).
**Possible inputs**:
A hash of options for the Docker executor, which can include:
- `platform`: Selects the architecture of the image to pull. When not specified,
the default is the same platform as the host runner.
**Example of `image:docker`**:
```yaml
arm-sql-job:
script: echo "Run sql tests"
image:
name: super/sql:experimental
docker:
platform: arm64/v8
```
**Additional details**:
- `image:docker:platform` maps to the [`docker pull --platform` option](https://docs.docker.com/engine/reference/commandline/pull/#options).
#### `image:pull_policy`
> - [Introduced](https://gitlab.com/gitlab-org/gitlab/-/issues/21619) in GitLab 15.1 [with a flag](../../administration/feature_flags.md) named `ci_docker_image_pull_policy`. Disabled by default.
@ -4286,38 +4255,6 @@ In this example, GitLab launches two containers for the job:
- [Run your CI/CD jobs in Docker containers](../docker/using_docker_images.md).
- [Use Docker to build Docker images](../docker/using_docker_build.md).
#### `services:docker`
> [Introduced](https://gitlab.com/gitlab-org/gitlab-runner/-/issues/27919) in GitLab 16.7. Requires GitLab Runner 16.7 or later.
Use `services:docker` to pass options to the Docker executor of a GitLab Runner.
**Keyword type**: Job keyword. You can use it only as part of a job or in the
[`default` section](#default).
**Possible inputs**:
A hash of options for the Docker executor, which can include:
- `platform`: Selects the architecture of the image to pull. When not specified,
the default is the same platform as the host runner.
**Example of `service:docker`**:
```yaml
arm-sql-job:
script: echo "Run sql tests in service container"
image: ruby:2.6
services:
- name: super/sql:experimental
docker:
platform: arm64/v8
```
**Additional details**:
- `services:docker:platform` maps to the [`docker pull --platform` option](https://docs.docker.com/engine/reference/commandline/pull/#options).
#### `service:pull_policy`
> - [Introduced](https://gitlab.com/gitlab-org/gitlab/-/issues/21619) in GitLab 15.1 [with a flag](../../administration/feature_flags.md) named `ci_docker_image_pull_policy`. Disabled by default.

View File

@ -6,6 +6,9 @@ info: Any user with at least the Maintainer role can merge updates to this conte
# Working with diffs
This page contains developer documentation for diffs. For the user documentation,
see [Diffs in merge requests](../../../user/project/merge_requests/versions.md).
We rely on different sources to present diffs. These include:
- Gitaly service

Binary file not shown.

Before

Width:  |  Height:  |  Size: 50 KiB

After

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 39 KiB

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 19 KiB

After

Width:  |  Height:  |  Size: 6.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 229 KiB

After

Width:  |  Height:  |  Size: 30 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 154 KiB

After

Width:  |  Height:  |  Size: 21 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 34 KiB

After

Width:  |  Height:  |  Size: 11 KiB

View File

@ -83,3 +83,12 @@ To view the changes between previously merged commits:
If you selected to add previously merged commits for context, those commits are
also shown in the list.
## Find the merge request that introduced a change
When you view the commit details page, GitLab links to one or more merge requests
that contain that commit.
This behavior only applies to commits that are in the most recent version of a merge
request. If the commits were in a merge request and were rebased out of that merge
request, the commits are not linked.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 22 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 17 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 7.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.7 KiB

View File

@ -4,69 +4,60 @@ group: Code Review
info: To determine the technical writer assigned to the Stage/Group associated with this page, see https://about.gitlab.com/handbook/product/ux/technical-writing/#assignments
---
# Merge requests versions **(FREE ALL)**
# Merge request diff versions **(FREE ALL)**
Every time you push to a branch that is tied to a merge request, a new version
of merge request diff is created. When you visit a merge request that contains
more than one pushes, you can select and compare the versions of those merge
request diffs.
When you create a merge request, you select two branches to compare. The differences
between the two branches are shown as a **diff** in the merge request. Each time
you push commits to a branch connected to a merge request, GitLab updates the
merge request diff to a new **diff version**.
![Merge request versions](img/versions.png)
NOTE:
Diff versions are updated on each push, not each commit. If a push contains multiple
commits, only one new diff version is created.
## Selecting a version
By default, GitLab compares the latest push in your source branch (`feature`)
against the most recent commit in the target branch, often `main`.
By default, the latest version of changes is shown. However, you
can select an older one from version dropdown list.
## Compare diff versions
![Merge request versions dropdown list](img/versions_dropdown.png)
If you've pushed to your branch multiple times, the diff version from each previous push
is available for comparison. When your merge request contains many changes or
sequential changes to the same file, you might want to compare a smaller number of changes.
Merge request versions are based on push not on commit. So, if you pushed 5
commits in a single push, it displays as a single option in the dropdown list. If you
pushed 5 times, that counts for 5 options.
Prerequisites:
You can also compare the merge request version with an older one to see what has
changed since then.
- The merge request branch must contain commits from multiple pushes. Individual commits
in the same push do not generate new diff versions.
![Merge request versions compare](img/versions_compare.png)
To compare diff versions:
Comments are disabled while viewing outdated merge versions or comparing to
versions other than base.
1. On the left sidebar, select **Search or go to** and find your project.
1. Select **Code > Merge requests**.
1. Select a merge request.
1. To view the current diff version for this merge request, select **Changes**.
1. Next to **Compare** (**{file-tree}**), select the pushes to compare. This example
compares `main` to the most recent push (latest diff version) of the branch:
Every time you push new changes to the branch, a link to compare the last
changes appears as a system note.
![Merge request versions dropdown list](img/versions_dropdown_v16_6.png)
![Merge request versions system note](img/versions_system_note.png)
This example branch has four commits, but the branch contains only three diff versions
because two commits were pushed at the same time.
## Find the merge request that introduced a change
## View diff versions from a system note
When viewing the commit details page, GitLab links to the merge request (or
merge requests, if it's in more than one) containing that commit.
GitLab adds a system note to a merge request each time you push new changes to
the merge request's branch. In this example, a single push added two commits:
This only applies to commits that are in the most recent version of a merge
request - if commits were in a merge request, then rebased out of that merge
request, they aren't linked.
![Merge request versions system note](img/versions_system_note_v16_6.png)
## `HEAD` comparison mode for merge requests
To view the diff for that commit, select the commit SHA.
> [Introduced](https://gitlab.com/gitlab-org/gitlab/-/issues/27008) in GitLab 12.10.
For more information, see how to [show or filter system notes on a merge request](../system_notes.md#on-a-merge-request).
Merge requests, particularly the **Changes** tab, is where source code
is reviewed and discussed. In circumstances where the target branch was
merged into the source branch of the merge request, the changes in the
source and target branch can be shown mixed together making it hard to
understand which changes are being added and which already exist in the
target branch.
## Related topics
In GitLab 12.10, we added a comparison mode, which
shows a diff calculated by simulating how it would look like once merged - a more accurate
representation of the changes rather than using the base of the two
branches. The new mode is available from the comparison target drop down
by selecting **main (HEAD)**. In GitLab 13.9, it
[replaced](https://gitlab.com/gitlab-org/gitlab/-/issues/198458) the
old default comparison. For technical details, additional information is available in the
[developer documentation](../../../development/merge_request_concepts/diffs/index.md#merge-request-diffs-against-the-head-of-the-target-branch).
![Merge request versions compare HEAD](img/versions_compare_head_v12_10.png)
- [Merge request diffs for developers](../../../development/merge_request_concepts/diffs/index.md)
- [Merge request diff storage for administrators](../../../administration/merge_request_diffs.md)
<!-- ## Troubleshooting

View File

@ -8,7 +8,6 @@ module API
expose :name, :entrypoint
expose :ports, using: Entities::Ci::JobRequest::Port
expose :executor_opts
expose :pull_policy
end
end

View File

@ -8,7 +8,6 @@ module API
expose :name, :entrypoint
expose :ports, using: Entities::Ci::JobRequest::Port
expose :executor_opts
expose :pull_policy
expose :alias, :command
expose :variables

View File

@ -4,7 +4,7 @@ module Gitlab
module Ci
module Build
class Image
attr_reader :alias, :command, :entrypoint, :name, :ports, :variables, :executor_opts, :pull_policy
attr_reader :alias, :command, :entrypoint, :name, :ports, :variables, :pull_policy
class << self
def from_image(job)
@ -28,7 +28,6 @@ module Gitlab
when String
@name = image
@ports = []
@executor_opts = {}
when Hash
@alias = image[:alias]
@command = image[:command]
@ -36,7 +35,6 @@ module Gitlab
@name = image[:name]
@ports = build_ports(image).select(&:valid?)
@variables = build_variables(image)
@executor_opts = image.fetch(:executor_opts, {})
@pull_policy = image[:pull_policy]
end
end

View File

@ -13,6 +13,21 @@ module Gitlab
validations do
validates :config, allowed_keys: IMAGEABLE_ALLOWED_KEYS
end
def value
if string?
{ name: @config }
elsif hash?
{
name: @config[:name],
entrypoint: @config[:entrypoint],
ports: (ports_value if ports_defined?),
pull_policy: pull_policy_value
}.compact
else
{}
end
end
end
end
end

View File

@ -12,9 +12,7 @@ module Gitlab
include ::Gitlab::Config::Entry::Attributable
include ::Gitlab::Config::Entry::Configurable
EXECUTOR_OPTS_KEYS = %i[docker].freeze
IMAGEABLE_ALLOWED_KEYS = EXECUTOR_OPTS_KEYS + %i[name entrypoint ports pull_policy].freeze
IMAGEABLE_ALLOWED_KEYS = %i[name entrypoint ports pull_policy].freeze
included do
include ::Gitlab::Config::Entry::Validatable
@ -25,15 +23,9 @@ module Gitlab
validates :name, type: String, presence: true
validates :entrypoint, array_of_strings: true, allow_nil: true
validates :executor_opts, json_schema: {
base_directory: "lib/gitlab/ci/config/entry/schemas/imageable",
detail_errors: true,
filename: "executor_opts",
hash_conversion: true
}, allow_nil: true
end
attributes :docker, :ports, :pull_policy
attributes :ports, :pull_policy
entry :ports, Entry::Ports,
description: 'Ports used to expose the image/service'
@ -57,28 +49,6 @@ module Gitlab
def skip_config_hash_validation?
true
end
def executor_opts
return unless config.is_a?(Hash)
config.slice(*EXECUTOR_OPTS_KEYS).compact.presence
end
def value
if string?
{ name: config }
elsif hash?
{
name: config[:name],
entrypoint: config[:entrypoint],
executor_opts: executor_opts,
ports: (ports_value if ports_defined?),
pull_policy: pull_policy_value
}.compact
else
{}
end
end
end
end
end

View File

@ -1,19 +0,0 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"description": "Describe `image:` and `service:` options like `docker:`",
"type": "object",
"properties": {
"docker": {
"type": "object",
"properties": {
"platform": {
"type": "string",
"minLength": 1,
"maxLength": 64
}
},
"additionalProperties": false
}
},
"additionalProperties": false
}

View File

@ -34,13 +34,14 @@ module Gitlab
end
def value
if hash?
super.merge(
command: @config[:command],
alias: @config[:alias]
if string?
{ name: @config }
elsif hash?
@config.merge(
pull_policy: pull_policy_value
).compact
else
super
{}
end
end
end

View File

@ -58358,9 +58358,6 @@ msgstr ""
msgid "test case"
msgstr ""
msgid "the '%{data_pointer}' must be a valid '%{type}'"
msgstr ""
msgid "the correct format."
msgstr ""

View File

@ -3,14 +3,16 @@
module QA
RSpec.describe 'Govern' do
describe 'Group access token', product_group: :authentication do
include QA::Support::Helpers::Project
let(:group_access_token) { create(:group_access_token) }
let(:api_client) { Runtime::API::Client.new(:gitlab, personal_access_token: group_access_token.token) }
let(:project) do
Resource::Project.fabricate! do |project|
project.name = 'project-for-group-access-token'
project.group = group_access_token.group
project.initialize_with_readme = true
end
create(:project, name: 'project-for-group-access-token', group: group_access_token.group)
end
before do
wait_until_project_is_ready(project)
end
it(
@ -30,11 +32,7 @@ module QA
it(
'can be used to commit via the API',
testcase: 'https://gitlab.com/gitlab-org/gitlab/-/quality/test_cases/367067',
quarantine: {
type: :flaky,
issue: "https://gitlab.com/gitlab-org/gitlab/-/issues/396615"
}
testcase: 'https://gitlab.com/gitlab-org/gitlab/-/quality/test_cases/367067'
) do
expect do
create(:commit,

View File

@ -3,10 +3,16 @@
module QA
RSpec.describe 'Govern' do
describe 'Project access token', product_group: :authentication do
let!(:project) { create(:project, name: "project-to-test-project-access-token-#{SecureRandom.hex(4)}") }
include QA::Support::Helpers::Project
let!(:project) { create(:project, name: "project-to-test-project-access-token") }
let!(:project_access_token) { create(:project_access_token, project: project) }
let!(:user_api_client) { Runtime::API::Client.new(:gitlab, personal_access_token: project_access_token.token) }
before do
wait_until_project_is_ready(project)
end
context 'for the same project' do
it 'can be used to create a file via the project API',
testcase: 'https://gitlab.com/gitlab-org/gitlab/-/quality/test_cases/347858' do
@ -41,7 +47,11 @@ module QA
context 'for a different project' do
let(:different_project) do
create(:project, name: "different-project-to-test-project-access-token-#{SecureRandom.hex(4)}")
create(:project, name: "different-project-to-test-project-access-token")
end
before do
wait_until_project_is_ready(different_project)
end
after do

View File

@ -12,6 +12,8 @@ module QA
end
context 'when added to parent group' do
include QA::Support::Helpers::Project
let!(:parent_group_user) { create(:user, api_client: admin_api_client) }
let!(:parent_group_user_api_client) do
@ -23,6 +25,8 @@ module QA
end
before do
wait_until_project_is_ready(sub_group_project)
parent_group.add_member(parent_group_user)
end

View File

@ -0,0 +1,18 @@
# frozen_string_literal: true
module QA
module Support
module Helpers
module Project
def wait_until_project_is_ready(project)
# Repository can take a short time to become ready after project is created
Support::Retrier.retry_on_exception(sleep_interval: 5) do
create(:commit, project: project, commit_message: 'Add new file', actions: [
{ action: 'create', file_path: 'new_file', content: '# This is a new file' }
])
end
end
end
end
end
end

View File

@ -36,31 +36,3 @@ empty_pull_policy:
services:
- name: postgres:11.6
pull_policy: []
invalid_image_platform:
script: echo "Specifying platform."
image:
name: alpine:latest
docker:
platform: ["arm64"] # The expected value is a string, not an array
invalid_image_executor_opts:
script: echo "Specifying platform."
image:
name: alpine:latest
docker:
unknown_key: test
invalid_service_executor_opts:
script: echo "Specifying platform."
services:
- name: mysql:5.7
docker:
unknown_key: test
invalid_service_platform:
script: echo "Specifying platform."
services:
- name: mysql:5.7
docker:
platform: ["arm64"] # The expected value is a string, not an array

View File

@ -29,17 +29,3 @@ pull_policy_array:
services:
- name: postgres:11.6
pull_policy: [always, if-not-present]
image_platform_string:
script: echo "Specifying platform."
services:
- name: mysql:5.7
docker:
platform: arm64
services_platform_string:
script: echo "Specifying platform."
image:
name: alpine:latest
docker:
platform: arm64

View File

@ -4,10 +4,7 @@ require 'spec_helper'
RSpec.describe API::Entities::Ci::JobRequest::Image do
let(:ports) { [{ number: 80, protocol: 'http', name: 'name' }] }
let(:image) do
double(name: 'image_name', entrypoint: ['foo'], executor_opts: {}, ports: ports, pull_policy: ['if-not-present'])
end
let(:image) { double(name: 'image_name', entrypoint: ['foo'], ports: ports, pull_policy: ['if-not-present']) }
let(:entity) { described_class.new(image) }
subject { entity.as_json }
@ -32,10 +29,6 @@ RSpec.describe API::Entities::Ci::JobRequest::Image do
end
end
it 'returns the executor_opts options' do
expect(subject[:executor_opts]).to eq({})
end
it 'returns the pull policy' do
expect(subject[:pull_policy]).to eq(['if-not-present'])
end

View File

@ -9,7 +9,6 @@ RSpec.describe API::Entities::Ci::JobRequest::Service do
::Gitlab::Ci::Build::Image,
name: 'image_name',
entrypoint: ['foo'],
executor_opts: {},
ports: ports,
pull_policy: ['if-not-present'],
alias: 'alias',
@ -26,7 +25,6 @@ RSpec.describe API::Entities::Ci::JobRequest::Service do
expect(result).to eq(
name: 'image_name',
entrypoint: ['foo'],
executor_opts: {},
ports: ports,
pull_policy: ['if-not-present'],
alias: 'alias',

View File

@ -10,7 +10,7 @@ RSpec.describe Gitlab::Ci::Build::Image do
context 'when image is defined in job' do
let(:image_name) { 'image:1.0' }
let(:job) { create(:ci_build, options: { image: image_name }) }
let(:job) { create(:ci_build, options: { image: image_name } ) }
context 'when image is defined as string' do
it 'fabricates an object of the proper class' do
@ -29,14 +29,12 @@ RSpec.describe Gitlab::Ci::Build::Image do
context 'when image is defined as hash' do
let(:entrypoint) { '/bin/sh' }
let(:pull_policy) { %w[always if-not-present] }
let(:executor_opts) { { docker: { platform: 'arm64' } } }
let(:job) do
create(:ci_build, options: { image: { name: image_name,
entrypoint: entrypoint,
ports: [80],
executor_opts: executor_opts,
pull_policy: pull_policy } })
pull_policy: pull_policy } } )
end
it 'fabricates an object of the proper class' do
@ -46,7 +44,6 @@ RSpec.describe Gitlab::Ci::Build::Image do
it 'populates fabricated object with the proper attributes' do
expect(subject.name).to eq(image_name)
expect(subject.entrypoint).to eq(entrypoint)
expect(subject.executor_opts).to eq(executor_opts)
expect(subject.pull_policy).to eq(pull_policy)
end
@ -101,12 +98,11 @@ RSpec.describe Gitlab::Ci::Build::Image do
let(:service_entrypoint) { '/bin/sh' }
let(:service_alias) { 'db' }
let(:service_command) { 'sleep 30' }
let(:executor_opts) { { docker: { platform: 'amd64' } } }
let(:pull_policy) { %w[always if-not-present] }
let(:job) do
create(:ci_build, options: { services: [{ name: service_image_name, entrypoint: service_entrypoint,
alias: service_alias, command: service_command, ports: [80],
executor_opts: executor_opts, pull_policy: pull_policy }] })
pull_policy: pull_policy }] })
end
it 'fabricates an non-empty array of objects' do
@ -120,7 +116,6 @@ RSpec.describe Gitlab::Ci::Build::Image do
expect(subject.first.entrypoint).to eq(service_entrypoint)
expect(subject.first.alias).to eq(service_alias)
expect(subject.first.command).to eq(service_command)
expect(subject.first.executor_opts).to eq(executor_opts)
expect(subject.first.pull_policy).to eq(pull_policy)
port = subject.first.ports.first

View File

@ -42,12 +42,6 @@ RSpec.describe Gitlab::Ci::Config::Entry::Image do
end
end
describe '#executor_opts' do
it "returns nil" do
expect(entry.executor_opts).to be_nil
end
end
describe '#ports' do
it "returns image's ports" do
expect(entry.ports).to be_nil
@ -94,52 +88,6 @@ RSpec.describe Gitlab::Ci::Config::Entry::Image do
end
end
context 'when configuration specifies docker' do
let(:config) { { name: 'image:1.0', docker: {} } }
it 'is valid' do
expect(entry).to be_valid
end
describe '#value' do
it "returns value" do
expect(entry.value).to eq(
name: 'image:1.0',
executor_opts: {
docker: {}
}
)
end
end
context "when docker specifies an option" do
let(:config) { { name: 'image:1.0', docker: { platform: 'amd64' } } }
it 'is valid' do
expect(entry).to be_valid
end
describe '#value' do
it "returns value" do
expect(entry.value).to eq(
name: 'image:1.0',
executor_opts: {
docker: { platform: 'amd64' }
}
)
end
end
end
context "when docker specifies an invalid option" do
let(:config) { { name: 'image:1.0', docker: { platform: 1 } } }
it 'is not valid' do
expect(entry).not_to be_valid
end
end
end
context 'when configuration has ports' do
let(:ports) { [{ number: 80, protocol: 'http', name: 'foobar' }] }
let(:config) { { name: 'image:1.0', entrypoint: %w[/bin/sh run], ports: ports } }
@ -198,7 +146,7 @@ RSpec.describe Gitlab::Ci::Config::Entry::Image do
describe '#errors' do
it 'saves errors' do
expect(entry.errors.first)
.to match(/config should be a hash or a string/)
.to match /config should be a hash or a string/
end
end
@ -215,7 +163,7 @@ RSpec.describe Gitlab::Ci::Config::Entry::Image do
describe '#errors' do
it 'saves errors' do
expect(entry.errors.first)
.to match(/config contains unknown keys: non_existing/)
.to match /config contains unknown keys: non_existing/
end
end

View File

@ -47,17 +47,17 @@ RSpec.describe Gitlab::Ci::Config::Entry::Service do
expect(entry.ports).to be_nil
end
end
describe '#executor_opts' do
it "returns service's executor_opts configuration" do
expect(entry.executor_opts).to be_nil
end
end
end
context 'when configuration is a hash' do
let(:config) do
{ name: 'postgresql:9.5', alias: 'db', command: %w[cmd run], entrypoint: %w[/bin/sh run] }
{
name: 'postgresql:9.5',
alias: 'db',
command: %w[cmd run],
entrypoint: %w[/bin/sh run],
variables: { 'MY_VAR' => 'variable' }
}
end
describe '#valid?' do
@ -147,27 +147,6 @@ RSpec.describe Gitlab::Ci::Config::Entry::Service do
end
end
context 'when configuration has docker options' do
let(:config) { { name: 'postgresql:9.5', docker: { platform: 'amd64' } } }
describe '#valid?' do
it 'is valid' do
expect(entry).to be_valid
end
end
describe '#value' do
it "returns value" do
expect(entry.value).to eq(
name: 'postgresql:9.5',
executor_opts: {
docker: { platform: 'amd64' }
}
)
end
end
end
context 'when configuration has pull_policy' do
let(:config) { { name: 'postgresql:9.5', pull_policy: 'if-not-present' } }

View File

@ -1313,46 +1313,6 @@ module Gitlab
})
end
end
context 'when image and service have docker options' do
let(:config) do
<<~YAML
test:
script: exit 0
image:
name: ruby:2.7
docker:
platform: linux/amd64
services:
- name: postgres:11.9
docker:
platform: linux/amd64
YAML
end
it { is_expected.to be_valid }
it "returns with image" do
expect(processor.builds).to contain_exactly({
stage: "test",
stage_idx: 2,
name: "test",
only: { refs: %w[branches tags] },
options: {
script: ["exit 0"],
image: { name: "ruby:2.7",
executor_opts: { docker: { platform: 'linux/amd64' } } },
services: [{ name: "postgres:11.9",
executor_opts: { docker: { platform: 'linux/amd64' } } }]
},
allow_failure: false,
when: "on_success",
job_variables: [],
root_variables_inheritance: true,
scheduling_type: :stage
})
end
end
end
describe 'Variables' do

View File

@ -272,19 +272,16 @@ RSpec.describe API::Ci::Runner, :clean_gitlab_redis_shared_state, feature_catego
expect(json_response['job_info']).to include(expected_job_info)
expect(json_response['git_info']).to eq(expected_git_info)
expect(json_response['image']).to eq(
{ 'name' => 'image:1.0', 'entrypoint' => '/bin/sh', 'ports' => [], 'executor_opts' => {},
'pull_policy' => nil }
{ 'name' => 'image:1.0', 'entrypoint' => '/bin/sh', 'ports' => [], 'pull_policy' => nil }
)
expect(json_response['services']).to eq(
[
{ 'name' => 'postgres', 'entrypoint' => nil, 'alias' => nil, 'command' => nil, 'ports' => [],
'variables' => nil, 'executor_opts' => {}, 'pull_policy' => nil },
{ 'name' => 'docker:stable-dind', 'entrypoint' => '/bin/sh', 'alias' => 'docker',
'command' => 'sleep 30', 'ports' => [], 'variables' => [], 'executor_opts' => {},
'pull_policy' => nil },
'variables' => nil, 'pull_policy' => nil },
{ 'name' => 'docker:stable-dind', 'entrypoint' => '/bin/sh', 'alias' => 'docker', 'command' => 'sleep 30',
'ports' => [], 'variables' => [], 'pull_policy' => nil },
{ 'name' => 'mysql:latest', 'entrypoint' => nil, 'alias' => nil, 'command' => nil, 'ports' => [],
'variables' => [{ 'key' => 'MYSQL_ROOT_PASSWORD', 'value' => 'root123.' }], 'executor_opts' => {},
'pull_policy' => nil }
'variables' => [{ 'key' => 'MYSQL_ROOT_PASSWORD', 'value' => 'root123.' }], 'pull_policy' => nil }
])
expect(json_response['steps']).to eq(expected_steps)
expect(json_response['hooks']).to eq(expected_hooks)
@ -923,41 +920,6 @@ RSpec.describe API::Ci::Runner, :clean_gitlab_redis_shared_state, feature_catego
end
end
context 'when image has docker options' do
let(:job) { create(:ci_build, :pending, :queued, pipeline: pipeline, options: options) }
let(:options) do
{
image: {
name: 'ruby',
executor_opts: {
docker: {
platform: 'amd64'
}
}
}
}
end
it 'returns the image with docker options' do
request_job
expect(response).to have_gitlab_http_status(:created)
expect(json_response).to include(
'id' => job.id,
'image' => { 'name' => 'ruby',
'executor_opts' => {
'docker' => {
'platform' => 'amd64'
}
},
'pull_policy' => nil,
'entrypoint' => nil,
'ports' => [] }
)
end
end
context 'when image has pull_policy' do
let(:job) { create(:ci_build, :pending, :queued, pipeline: pipeline, options: options) }
@ -976,11 +938,7 @@ RSpec.describe API::Ci::Runner, :clean_gitlab_redis_shared_state, feature_catego
expect(response).to have_gitlab_http_status(:created)
expect(json_response).to include(
'id' => job.id,
'image' => { 'name' => 'ruby',
'executor_opts' => {},
'pull_policy' => ['if-not-present'],
'entrypoint' => nil,
'ports' => [] }
'image' => { 'name' => 'ruby', 'pull_policy' => ['if-not-present'], 'entrypoint' => nil, 'ports' => [] }
)
end
end
@ -1004,8 +962,7 @@ RSpec.describe API::Ci::Runner, :clean_gitlab_redis_shared_state, feature_catego
expect(json_response).to include(
'id' => job.id,
'services' => [{ 'alias' => nil, 'command' => nil, 'entrypoint' => nil, 'name' => 'postgres:11.9',
'ports' => [], 'executor_opts' => {}, 'pull_policy' => ['if-not-present'],
'variables' => [] }]
'ports' => [], 'pull_policy' => ['if-not-present'], 'variables' => [] }]
)
end
end

View File

@ -1,64 +0,0 @@
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe API::Ci::Runner, :clean_gitlab_redis_shared_state, feature_category: :continuous_integration do
include StubGitlabCalls
let_it_be(:user) { create(:user) }
let_it_be(:project) { create(:project, :repository, shared_runners_enabled: false) }
let_it_be(:runner) { create(:ci_runner, :project, projects: [project]) }
let(:user_agent) { 'gitlab-runner 9.0.0 (9-0-stable; go1.7.4; linux/amd64)' }
before_all do
project.add_maintainer(user)
end
Dir[Rails.root.join("spec/requests/api/ci/runner/yamls/*.yml")].each do |yml_file|
context "for #{File.basename(yml_file)}" do
let(:yaml_content) { YAML.load_file(yml_file) }
let(:gitlab_ci_yml) { yaml_content.fetch("gitlab_ci") }
let(:request_response) { yaml_content.fetch("request_response") }
it 'runs a job' do
stub_ci_pipeline_yaml_file(YAML.dump(gitlab_ci_yml))
pipeline_response = create_pipeline!
expect(pipeline_response).to be_success, pipeline_response.message
expect(pipeline_response.payload).to be_created_successfully
expect(pipeline_response.payload.builds).to be_one
build = pipeline_response.payload.builds.first
process_pipeline!(pipeline_response.payload)
expect(build.reload).to be_pending
request_job(runner.token)
expect(response).to have_gitlab_http_status(:created)
expect(response.headers['Content-Type']).to eq('application/json')
expect(json_response).to include('id' => build.id, 'token' => build.token)
expect(json_response).to include(request_response)
end
end
end
def create_pipeline!
params = { ref: 'master',
before: '00000000',
after: project.commit.id,
commits: [{ message: 'some commit' }] }
Ci::CreatePipelineService.new(project, user, params).execute(:push)
end
def process_pipeline!(pipeline)
PipelineProcessWorker.new.perform(pipeline.id)
end
def request_job(token, **params)
new_params = params.merge(token: token)
post api('/jobs/request'), params: new_params.to_json,
headers: { 'User-Agent' => user_agent, 'Content-Type': 'application/json' }
end
end

View File

@ -1,15 +0,0 @@
# .gitlab-ci.yml end-to-end tests
The purpose of this folder is to provide a single job `.gitlab-ci.yml`
that will be validated against end-to-end response that is send to runner.
This allows to easily test end-to-end all CI job transformation that
and impact on how such job is rendered to be executed by the GitLab Runner.
```yaml
gitlab_ci:
# .gitlab-ci.yml to stub
request_response:
# exact payload that is checked as returned by `/api/v4/jobs/request`
```

View File

@ -1,19 +0,0 @@
gitlab_ci:
rspec:
image: alpine:latest
script: echo Hello World
request_response:
image:
name: alpine:latest
entrypoint: null
executor_opts: {}
ports: []
pull_policy: null
steps:
- name: script
script: ["echo Hello World"]
timeout: 3600
when: on_success
allow_failure: false
services: []

View File

@ -1,25 +0,0 @@
gitlab_ci:
rspec:
image:
name: alpine:latest
docker:
platform: amd64
script: echo Hello World
request_response:
image:
name: alpine:latest
entrypoint: null
executor_opts:
docker:
platform: amd64
ports: []
pull_policy: null
steps:
- name: script
script: ["echo Hello World"]
timeout: 3600
when: on_success
allow_failure: false
services: []

View File

@ -1,23 +0,0 @@
gitlab_ci:
rspec:
services:
- docker:dind
script: echo Hello World
request_response:
image: null
steps:
- name: script
script: ["echo Hello World"]
timeout: 3600
when: on_success
allow_failure: false
services:
- name: docker:dind
alias: null
command: null
entrypoint: null
executor_opts: {}
ports: []
pull_policy: null
variables: []

View File

@ -1,27 +0,0 @@
gitlab_ci:
rspec:
services:
- name: docker:dind
docker:
platform: amd64
script: echo Hello World
request_response:
image: null
steps:
- name: script
script: ["echo Hello World"]
timeout: 3600
when: on_success
allow_failure: false
services:
- name: docker:dind
alias: null
command: null
entrypoint: null
executor_opts:
docker:
platform: amd64
ports: []
pull_policy: null
variables: []

View File

@ -58,32 +58,5 @@ RSpec.describe JsonSchemaValidator do
end
end
end
context "for executor_opts schema" do
context 'when detail_errors is true' do
let(:validator) { described_class.new(attributes: [:data], detail_errors: true, filename: "build_report_result_data") }
context 'when data is valid' do
it 'returns no errors' do
subject
expect(build_report_result.errors).to be_empty
end
end
context 'when data is invalid' do
it 'returns json schema is invalid' do
build_report_result.data = { invalid: 'data' }
subject
expect(build_report_result.errors.size).to eq(1)
expect(build_report_result.errors.full_messages).to match_array(
["Data the '/invalid' must be a valid 'schema'"]
)
end
end
end
end
end
end