Skip to content
Snippets Groups Projects
Unverified Commit 09910ca5 authored by Furkan Ayhan's avatar Furkan Ayhan Committed by GitLab
Browse files

Merge branch 'docker-opts-user' into 'master'

parents eca3e45e f3ec5bf2
No related branches found
No related tags found
No related merge requests found
Pipeline #21109091 canceled
Showing
with 238 additions and 23 deletions
Loading
Loading
@@ -528,6 +528,12 @@
"type": "string",
"minLength": 1,
"description": "Image architecture to pull."
},
"user": {
"type": "string",
"minLength": 1,
"maxLength": 255,
"description": "Username or UID to use for the container."
}
}
},
Loading
Loading
@@ -603,6 +609,12 @@
"type": "string",
"minLength": 1,
"description": "Image architecture to pull."
},
"user": {
"type": "string",
"minLength": 1,
"maxLength": 255,
"description": "Username or UID to use for the container."
}
}
},
Loading
Loading
Loading
Loading
@@ -2511,7 +2511,8 @@ image:
 
#### `image:docker`
 
> [Introduced](https://gitlab.com/gitlab-org/gitlab-runner/-/issues/27919) in GitLab 16.7. Requires GitLab Runner 16.7 or later.
> - [Introduced](https://gitlab.com/gitlab-org/gitlab-runner/-/issues/27919) in GitLab 16.7. Requires GitLab Runner 16.7 or later.
> - `user` input option [introduced](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/137907) in GitLab 16.8.
 
Use `image:docker` to pass options to the Docker executor of a GitLab Runner.
 
Loading
Loading
@@ -2524,6 +2525,7 @@ 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.
- `user`: Specify the username or UID to use when running the container.
 
**Example of `image:docker`**:
 
Loading
Loading
@@ -2534,11 +2536,13 @@ arm-sql-job:
name: super/sql:experimental
docker:
platform: arm64/v8
user: dave
```
 
**Additional details**:
 
- `image:docker:platform` maps to the [`docker pull --platform` option](https://docs.docker.com/engine/reference/commandline/pull/#options).
- `image:docker:user` maps to the [`docker run --user` option](https://docs.docker.com/engine/reference/commandline/run/#options).
 
#### `image:pull_policy`
 
Loading
Loading
@@ -4428,7 +4432,8 @@ In this example, GitLab launches two containers for the job:
 
#### `services:docker`
 
> [Introduced](https://gitlab.com/gitlab-org/gitlab-runner/-/issues/27919) in GitLab 16.7. Requires GitLab Runner 16.7 or later.
> - [Introduced](https://gitlab.com/gitlab-org/gitlab-runner/-/issues/27919) in GitLab 16.7. Requires GitLab Runner 16.7 or later.
> - `user` input option [introduced](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/137907) in GitLab 16.8.
 
Use `services:docker` to pass options to the Docker executor of a GitLab Runner.
 
Loading
Loading
@@ -4441,6 +4446,7 @@ 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.
- `user`: Specify the username or UID to use when running the container.
 
**Example of `services:docker`**:
 
Loading
Loading
@@ -4452,11 +4458,13 @@ arm-sql-job:
- name: super/sql:experimental
docker:
platform: arm64/v8
user: dave
```
 
**Additional details**:
 
- `services:docker:platform` maps to the [`docker pull --platform` option](https://docs.docker.com/engine/reference/commandline/pull/#options).
- `services:docker:user` maps to the [`docker run --user` option](https://docs.docker.com/engine/reference/commandline/run/#options).
 
#### `services:pull_policy`
 
Loading
Loading
Loading
Loading
@@ -10,6 +10,11 @@
"type": "string",
"minLength": 1,
"maxLength": 64
},
"user": {
"type": "string",
"minLength": 1,
"maxLength": 255
}
},
"additionalProperties": false
Loading
Loading
Loading
Loading
@@ -26,6 +26,17 @@ invalid_image_platform:
docker:
platform: ["arm64"] # The expected value is a string, not an array
 
invalid_image_user:
image:
name: alpine:latest
docker:
user: ["dave"] # The expected value is a string, not an array
empty_image_user:
image:
name: alpine:latest
docker:
user: ""
invalid_image_executor_opts:
image:
name: alpine:latest
Loading
Loading
Loading
Loading
@@ -50,3 +50,17 @@ invalid_service_platform:
- name: mysql:5.7
docker:
platform: ["arm64"] # The expected value is a string, not an array
invalid_service_user:
script: echo "Specifying user."
services:
- name: mysql:5.7
docker:
user: ["dave"] # The expected value is a string, not an array
empty_service_user:
script: echo "Specifying user"
services:
- name: alpine:latest
docker:
user: ""
Loading
Loading
@@ -30,6 +30,19 @@ valid_image_with_docker:
docker:
platform: linux/amd64
 
valid_image_with_docker_user:
image:
name: ubuntu:latest
docker:
user: ubuntu
valid_image_with_docker_multiple_options:
image:
name: ubuntu:latest
docker:
platform: linux/arm64
user: ubuntu
valid_image_full:
image:
name: alpine:latest
Loading
Loading
Loading
Loading
@@ -36,3 +36,18 @@ services_platform_string:
- name: mysql:5.7
docker:
platform: arm64
services_with_docker_user:
script: echo "Specifying platform."
services:
- name: mysql:5.7
docker:
user: ubuntu
services_with_docker_multiple_options:
script: echo "Specifying platform."
services:
- name: mysql:5.7
docker:
platform: linux/arm64
user: ubuntu
Loading
Loading
@@ -29,7 +29,7 @@
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(:executor_opts) { { docker: { platform: 'arm64', user: 'dave' } } }
 
let(:job) do
create(:ci_build, options: { image: { name: image_name,
Loading
Loading
@@ -101,7 +101,7 @@
let(:service_entrypoint) { '/bin/sh' }
let(:service_alias) { 'db' }
let(:service_command) { 'sleep 30' }
let(:executor_opts) { { docker: { platform: 'amd64' } } }
let(:executor_opts) { { docker: { platform: 'amd64', user: 'dave' } } }
let(:pull_policy) { %w[always if-not-present] }
let(:job) do
create(:ci_build, options: { services: [{ name: service_image_name, entrypoint: service_entrypoint,
Loading
Loading
Loading
Loading
@@ -112,7 +112,7 @@
end
end
 
context "when docker specifies an option" do
context "when docker specifies platform" do
let(:config) { { name: 'image:1.0', docker: { platform: 'amd64' } } }
 
it 'is valid' do
Loading
Loading
@@ -129,15 +129,73 @@
)
end
end
context "when invalid data type is specified for platform option" do
let(:config) { { name: 'image:1.0', docker: { platform: 1 } } }
it 'raises an error' do
expect(entry).not_to be_valid
expect(entry.errors.first)
.to match %r{image executor opts '/docker/platform' must be a valid 'string'}
end
end
end
context "when docker specifies user" do
let(:config) { { name: 'image:1.0', docker: { user: 'dave' } } }
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: { user: 'dave' }
}
)
end
end
context "when user is a UID" do
let(:config) { { name: 'image:1.0', docker: { user: '1001' } } }
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: { user: '1001' }
}
)
end
end
end
context "when invalid data type is specified for user option" do
let(:config) { { name: 'image:1.0', docker: { user: 1 } } }
it 'raises an error' do
expect(entry).not_to be_valid
expect(entry.errors.first)
.to match %r{image executor opts '/docker/user' must be a valid 'string'}
end
end
end
 
context "when docker specifies an invalid option" do
let(:config) { { name: 'image:1.0', docker: { platform: 1 } } }
let(:config) { { name: 'image:1.0', docker: { unknown_key: 'foo' } } }
 
it 'is not valid' do
expect(entry).not_to be_valid
expect(entry.errors.first)
.to match %r{image executor opts '/docker/platform' must be a valid 'string'}
.to match %r{image executor opts '/docker/unknown_key' must be a valid 'schema'}
end
end
end
Loading
Loading
Loading
Loading
@@ -154,22 +154,45 @@
end
 
context 'when configuration has docker options' do
let(:config) { { name: 'postgresql:9.5', docker: { platform: 'amd64' } } }
context "with platform option" do
let(:config) { { name: 'postgresql:9.5', docker: { platform: 'amd64' } } }
 
describe '#valid?' do
it 'is valid' do
expect(entry).to be_valid
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
 
describe '#value' do
it "returns value" do
expect(entry.value).to eq(
name: 'postgresql:9.5',
executor_opts: {
docker: { platform: 'amd64' }
}
)
context "with user option" do
let(:config) { { name: 'postgresql:9.5', docker: { user: 'dave' } } }
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: { user: 'dave' }
}
)
end
end
end
end
Loading
Loading
Loading
Loading
@@ -1295,10 +1295,12 @@ module Ci
name: ruby:2.7
docker:
platform: linux/amd64
user: dave
services:
- name: postgres:11.9
docker:
platform: linux/amd64
user: john
YAML
end
 
Loading
Loading
@@ -1313,9 +1315,9 @@ module Ci
options: {
script: ["exit 0"],
image: { name: "ruby:2.7",
executor_opts: { docker: { platform: 'linux/amd64' } } },
executor_opts: { docker: { platform: 'linux/amd64', user: 'dave' } } },
services: [{ name: "postgres:11.9",
executor_opts: { docker: { platform: 'linux/amd64' } } }]
executor_opts: { docker: { platform: 'linux/amd64', user: 'john' } } }]
},
allow_failure: false,
when: "on_success",
Loading
Loading
Loading
Loading
@@ -932,7 +932,8 @@
name: 'ruby',
executor_opts: {
docker: {
platform: 'amd64'
platform: 'amd64',
user: 'dave'
}
}
}
Loading
Loading
@@ -948,7 +949,8 @@
'image' => { 'name' => 'ruby',
'executor_opts' => {
'docker' => {
'platform' => 'amd64'
'platform' => 'amd64',
'user' => 'dave'
}
},
'pull_policy' => nil,
Loading
Loading
gitlab_ci:
rspec:
image:
name: alpine:latest
docker:
user: dave
script: echo Hello World
request_response:
image:
name: alpine:latest
entrypoint: null
executor_opts:
docker:
user: dave
ports: []
pull_policy: null
steps:
- name: script
script: ["echo Hello World"]
timeout: 3600
when: on_success
allow_failure: false
services: []
gitlab_ci:
rspec:
services:
- name: docker:dind
docker:
user: john
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:
user: john
ports: []
pull_policy: null
variables: []
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