Skip to content
Snippets Groups Projects
Commit 80b12155 authored by Nick Thomas's avatar Nick Thomas
Browse files

Merge branch '2636-fix-service-name-expanding-from-variable' into 'master'

Fix services usage when service name is using variable

Closes #2636

See merge request !641
parents ff79746c 3e7f6031
No related branches found
No related tags found
No related merge requests found
......@@ -622,13 +622,12 @@ func (s *executor) getServicesDefinitions() (common.Services, error) {
for _, service := range s.Build.Services {
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 {
return nil, err
}
service.Name = serviceName
serviceDefinitions = append(serviceDefinitions, service)
}
......
......@@ -505,6 +505,72 @@ func TestCacheInContainer(t *testing.T) {
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) {
cmd := exec.Command("docker", "run", "--detach", "--privileged", "-p", "2375", "docker:"+version+"-dind")
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