Skip to content
Snippets Groups Projects
Unverified Commit 3e7f6031 authored by Tomasz Maczukin's avatar Tomasz Maczukin
Browse files

Fix services usage when service name is using variable

parent 1a6bdaaa
No related branches found
No related tags found
No related merge requests found
...@@ -621,13 +621,12 @@ func (s *executor) getServicesDefinitions() (common.Services, error) { ...@@ -621,13 +621,12 @@ func (s *executor) getServicesDefinitions() (common.Services, error) {
for _, service := range s.Build.Services { for _, service := range s.Build.Services {
serviceName := s.Build.GetAllVariables().ExpandValue(service.Name) serviceName := s.Build.GetAllVariables().ExpandValue(service.Name)
err := s.verifyAllowedImage(service.Name, "services", s.Config.Docker.AllowedServices, s.Config.Docker.Services) err := s.verifyAllowedImage(serviceName, "services", s.Config.Docker.AllowedServices, s.Config.Docker.Services)
if err != nil { if err != nil {
return nil, err return nil, err
} }
service.Name = serviceName service.Name = serviceName
serviceDefinitions = append(serviceDefinitions, service) serviceDefinitions = append(serviceDefinitions, service)
} }
......
...@@ -470,6 +470,72 @@ func TestCacheInContainer(t *testing.T) { ...@@ -470,6 +470,72 @@ func TestCacheInContainer(t *testing.T) {
assert.NotContains(t, output, skipCacheUpload, "Cache upload should be performed with policy: push") assert.NotContains(t, output, skipCacheUpload, "Cache upload should be performed with policy: push")
} }
func TestDockerImageNameFromVariable(t *testing.T) {
if helpers.SkipIntegrationTests(t, "docker", "info") {
return
}
successfulBuild, err := common.GetRemoteSuccessfulBuild()
successfulBuild.Variables = append(successfulBuild.Variables, common.JobVariable{
Key: "CI_REGISTRY_IMAGE",
Value: "alpine",
})
successfulBuild.Image = common.Image{
Name: "$CI_REGISTRY_IMAGE",
}
assert.NoError(t, err)
build := &common.Build{
JobResponse: successfulBuild,
Runner: &common.RunnerConfig{
RunnerSettings: common.RunnerSettings{
Executor: "docker",
Docker: &common.DockerConfig{
Image: "alpine",
AllowedServices: []string{"alpine"},
},
},
},
}
re := regexp.MustCompile("(?m)^ERROR: The [^ ]+ is not present on list of allowed images")
output := runTestJobWithOutput(t, build)
assert.NotRegexp(t, re, output, "Image's name should be expanded from variable")
}
func TestDockerServiceNameFromVariable(t *testing.T) {
if helpers.SkipIntegrationTests(t, "docker", "info") {
return
}
successfulBuild, err := common.GetRemoteSuccessfulBuild()
successfulBuild.Variables = append(successfulBuild.Variables, common.JobVariable{
Key: "CI_REGISTRY_IMAGE",
Value: "alpine",
})
successfulBuild.Services = append(successfulBuild.Services, common.Image{
Name: "$CI_REGISTRY_IMAGE",
})
assert.NoError(t, err)
build := &common.Build{
JobResponse: successfulBuild,
Runner: &common.RunnerConfig{
RunnerSettings: common.RunnerSettings{
Executor: "docker",
Docker: &common.DockerConfig{
Image: "alpine",
AllowedServices: []string{"alpine"},
},
},
},
}
re := regexp.MustCompile("(?m)^ERROR: The [^ ]+ is not present on list of allowed services")
output := runTestJobWithOutput(t, build)
assert.NotRegexp(t, re, output, "Service's name should be expanded from variable")
}
func runDockerInDocker(version string) (id string, err error) { func runDockerInDocker(version string) (id string, err error) {
cmd := exec.Command("docker", "run", "--detach", "--privileged", "-p", "2375", "docker:"+version+"-dind") cmd := exec.Command("docker", "run", "--detach", "--privileged", "-p", "2375", "docker:"+version+"-dind")
cmd.Stderr = os.Stderr cmd.Stderr = os.Stderr
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment