Define cmd and entrypoint to services from config

Users can define services right inside of the `config.toml`. They can
only define the `name` and `alias` of the service. When using services
inside of the `gitlab-ci.yml` they can define [`entrypoint` and
`command`](https://docs.gitlab.com/ee/ci/docker/using_docker_images.html#available-settings-for-services),
however they can't do this inside of the `config.toml` file.

closes https://gitlab.com/gitlab-org/gitlab-runner/-/issues/27173
parent 9d6ef94a
......@@ -353,15 +353,20 @@ type NodeSelectorRequirement struct {
Values []string `toml:"values,omitempty" json:"values"`
}
//nolint:lll
type Service struct {
Name string `toml:"name" long:"name" description:"The image path for the service"`
Alias string `toml:"alias,omitempty" long:"alias" description:"The alias of the service"`
Name string `toml:"name" long:"name" description:"The image path for the service"`
Alias string `toml:"alias,omitempty" long:"alias" description:"The alias of the service"`
Command []string `toml:"command" long:"command" description:"Command or script that should be used as the container’s command. Syntax is similar to https://docs.docker.com/engine/reference/builder/#cmd"`
Entrypoint []string `toml:"entrypoint" long:"entrypoint" description:"Command or script that should be executed as the container’s entrypoint. syntax is similar to https://docs.docker.com/engine/reference/builder/#entrypoint"`
}
func (s *Service) ToImageDefinition() Image {
return Image{
Name: s.Name,
Alias: s.Alias,
Name: s.Name,
Alias: s.Alias,
Command: s.Command,
Entrypoint: s.Entrypoint,
}
}
......
......@@ -345,6 +345,26 @@ func TestService_ToImageDefinition(t *testing.T) {
service: Service{Name: "name", Alias: "alias"},
expectedImage: Image{Name: "name", Alias: "alias"},
},
"command specified": {
service: Service{Name: "name", Command: []string{"executable", "param1", "param2"}},
expectedImage: Image{Name: "name", Command: []string{"executable", "param1", "param2"}},
},
"entrypoint specified": {
service: Service{Name: "name", Entrypoint: []string{"executable", "param3", "param4"}},
expectedImage: Image{Name: "name", Entrypoint: []string{"executable", "param3", "param4"}},
},
"command and entrypoint specified": {
service: Service{
Name: "name",
Command: []string{"executable", "param1", "param2"},
Entrypoint: []string{"executable", "param3", "param4"},
},
expectedImage: Image{
Name: "name",
Command: []string{"executable", "param1", "param2"},
Entrypoint: []string{"executable", "param3", "param4"},
},
},
}
for tn, tt := range tests {
......
......@@ -292,6 +292,8 @@ Each service will be run in a separate container and linked to the build.
| --------- | ----------- |
| `name` | The name of the image to be run as a service |
| `alias` | Additional [alias name](https://docs.gitlab.com/ee/ci/docker/using_docker_images.html#available-settings-for-services) that can be used to access the service |
| `entrypoint` | Command or script that should be executed as the container’s entrypoint. The syntax is similar to [Dockerfile’s ENTRYPOINT](https://docs.docker.com/engine/reference/builder/#entrypoint) directive, where each shell token is a separate string in the array. Introduced in [GitLab Runner 13.6](https://gitlab.com/gitlab-org/gitlab-runner/-/issues/27173). |
| `command` | Command or script that should be used as the container’s command. The syntax is similar to [Dockerfile’s CMD](https://docs.docker.com/engine/reference/builder/#cmd) directive, where each shell token is a separate string in the array. Introduced in [GitLab Runner 13.6](https://gitlab.com/gitlab-org/gitlab-runner/-/issues/27173). |
Example:
......@@ -325,8 +327,9 @@ Example:
allowed_images = ["ruby:*", "python:*", "php:*"]
allowed_services = ["postgres:9", "redis:*", "mysql:*"]
[[runners.docker.services]]
name = "mysql"
alias = "db"
name = "svc1"
entrypoint = ["entrypoint.sh"]
command = ["executable","param1","param2"]
[[runners.docker.services]]
name = "redis:2.8"
alias = "cache"
......
......@@ -441,7 +441,8 @@ check_interval = 30
## Using services
> [Introduced](https://gitlab.com/gitlab-org/gitlab-runner/-/issues/4470) in GitLab Runner 12.5.
> - [Introduced](https://gitlab.com/gitlab-org/gitlab-runner/-/issues/4470) in GitLab Runner 12.5.
> - [Introduced `command` and `entrypoint`](https://gitlab.com/gitlab-org/gitlab-runner/-/issues/27173) in GitLab Runner 13.6.
Define a list of [services](https://docs.gitlab.com/ee/ci/services/).
......@@ -460,8 +461,10 @@ check_interval = 30
name = "postgres:12-alpine"
alias = "db1"
[[runners.kubernetes.services]]
name = "percona:latest"
name = "svc1"
alias = "db2"
entrypoint = ["entrypoint.sh"]
command = ["executable","param1","param2"]
```
## Using Affinity
......
......@@ -1843,14 +1843,38 @@ func TestGetServiceDefinitions(t *testing.T) {
"all services with proper name and alias": {
services: []common.Service{
{
Name: "name",
Alias: "alias",
Name: "name",
Alias: "alias",
Command: []string{"executable", "param1", "param2"},
Entrypoint: []string{"executable", "param3", "param4"},
},
{
Name: "name2",
Alias: "alias2",
Command: []string{"executable", "param1", "param2"},
},
{
Name: "name3",
Alias: "alias3",
Entrypoint: []string{"executable", "param3", "param4"},
},
},
expectedServices: common.Services{
{
Name: "name",
Alias: "alias",
Name: "name",
Alias: "alias",
Command: []string{"executable", "param1", "param2"},
Entrypoint: []string{"executable", "param3", "param4"},
},
{
Name: "name2",
Alias: "alias2",
Command: []string{"executable", "param1", "param2"},
},
{
Name: "name3",
Alias: "alias3",
Entrypoint: []string{"executable", "param3", "param4"},
},
},
},
......
......@@ -1429,6 +1429,19 @@ func TestPrepare(t *testing.T) {
{Name: "test-service-k8s"},
{Name: "test-service-k8s2"},
{Name: ""},
{
Name: "test-service-k8s3",
Command: []string{"executable", "param1", "param2"},
},
{
Name: "test-service-k8s4",
Entrypoint: []string{"executable", "param3", "param4"},
},
{
Name: "test-service-k8s5",
Command: []string{"executable", "param1", "param2"},
Entrypoint: []string{"executable", "param3", "param4"},
},
},
},
},
......@@ -1468,6 +1481,19 @@ func TestPrepare(t *testing.T) {
{
Name: "test-service-k8s2",
},
{
Name: "test-service-k8s3",
Command: []string{"executable", "param1", "param2"},
},
{
Name: "test-service-k8s4",
Entrypoint: []string{"executable", "param3", "param4"},
},
{
Name: "test-service-k8s5",
Command: []string{"executable", "param1", "param2"},
Entrypoint: []string{"executable", "param3", "param4"},
},
{
Name: "test-service",
Entrypoint: []string{"/init", "run"},
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment