1
0
mirror of https://github.com/rancher/os.git synced 2025-06-22 21:17:02 +00:00

Merge pull request #2001 from SvenDowideit/use-local-image-for-local-service

look into local image not used when enabling a local service.
This commit is contained in:
Sven Dowideit 2017-07-21 09:52:38 +10:00 committed by GitHub
commit a3f942f03b
3 changed files with 85 additions and 2 deletions

View File

@ -6,10 +6,12 @@ import (
"golang.org/x/net/context"
yaml "github.com/cloudfoundry-incubator/candiedyaml"
dockerClient "github.com/docker/engine-api/client"
"github.com/docker/libcompose/cli/logger"
composeConfig "github.com/docker/libcompose/config"
"github.com/docker/libcompose/docker"
composeClient "github.com/docker/libcompose/docker/client"
"github.com/docker/libcompose/project"
"github.com/docker/libcompose/project/events"
"github.com/docker/libcompose/project/options"
@ -245,13 +247,47 @@ func StageServices(cfg *config.CloudConfig, services ...string) error {
}
// Reduce service configurations to just image and labels
needToPull := false
var client, userClient, systemClient dockerClient.APIClient
for _, serviceName := range p.ServiceConfigs.Keys() {
serviceConfig, _ := p.ServiceConfigs.Get(serviceName)
// test to see if we need to Pull
if serviceConfig.Labels[config.ScopeLabel] != config.System {
if userClient == nil {
userClient, err = rosDocker.NewDefaultClient()
if err != nil {
log.Error(err)
}
}
client = userClient
} else {
if systemClient == nil {
systemClient, err = rosDocker.NewSystemClient()
if err != nil {
log.Error(err)
}
client = systemClient
}
}
if client != nil {
_, _, err := client.ImageInspectWithRaw(context.Background(), serviceConfig.Image, false)
if err == nil {
log.Infof("Service %s using local image %s", serviceName, serviceConfig.Image)
continue
}
}
needToPull = true
p.ServiceConfigs.Add(serviceName, &composeConfig.ServiceConfig{
Image: serviceConfig.Image,
Labels: serviceConfig.Labels,
})
}
return p.Pull(context.Background())
if needToPull {
return p.Pull(context.Background())
}
return nil
}

View File

@ -54,7 +54,7 @@ func (s *Service) missingImage() bool {
return false
}
client := s.context.ClientFactory.Create(s)
_, _, err := client.ImageInspectWithRaw(context.Background(), s.Config().Image, false)
_, _, err := client.ImageInspectWithRaw(context.Background(), image, false)
return err != nil
}

47
tests/ros_services.go Normal file
View File

@ -0,0 +1,47 @@
package integration
import . "gopkg.in/check.v1"
func (s *QemuSuite) TestRosLocalService(c *C) {
s.RunQemu(c)
// System-docker
s.CheckCall(c, `echo "FROM $(sudo system-docker images --format '{{.Repository}}:{{.Tag}}' | grep os-base)" > Dockerfile
sudo system-docker build -t testimage .`)
s.CheckCall(c, `echo "test:" > test.yml
echo " image: testimage" >> test.yml
echo " entrypoint: ls" >> test.yml
echo " labels:" >> test.yml
echo " io.rancher.os.scope: system" >> test.yml
echo " io.rancher.os.after: console" >> test.yml
`)
s.CheckCall(c, `sudo cp test.yml /var/lib/rancher/conf/test.yml`)
s.CheckCall(c, `sudo ros service enable /var/lib/rancher/conf/test.yml`)
s.CheckCall(c, `sudo ros service up test`)
s.CheckCall(c, `sudo ros service logs test | grep bin`)
}
func (s *QemuSuite) TestRosLocalServiceUser(c *C) {
s.RunQemu(c)
// User-docker
s.CheckCall(c, `echo "FROM alpine" > Dockerfile
sudo docker build -t testimage .`)
s.CheckCall(c, `echo "test:" > test.yml
echo " image: testimage" >> test.yml
echo " entrypoint: ls" >> test.yml
echo " labels:" >> test.yml
echo " io.rancher.os.scope: user" >> test.yml
echo " io.rancher.os.after: console" >> test.yml
`)
s.CheckCall(c, `sudo cp test.yml /var/lib/rancher/conf/test.yml`)
s.CheckCall(c, `sudo ros service enable /var/lib/rancher/conf/test.yml`)
s.CheckCall(c, `sudo ros service up test`)
s.CheckCall(c, `sudo ros service logs test | grep bin`)
}