mirror of
https://github.com/rancher/os.git
synced 2025-09-07 17:54:57 +00:00
Don't pull an image that is already local
Signed-off-by: Sven Dowideit <SvenDowideit@home.org.au>
This commit is contained in:
@@ -6,10 +6,12 @@ import (
|
|||||||
"golang.org/x/net/context"
|
"golang.org/x/net/context"
|
||||||
|
|
||||||
yaml "github.com/cloudfoundry-incubator/candiedyaml"
|
yaml "github.com/cloudfoundry-incubator/candiedyaml"
|
||||||
|
dockerClient "github.com/docker/engine-api/client"
|
||||||
"github.com/docker/libcompose/cli/logger"
|
"github.com/docker/libcompose/cli/logger"
|
||||||
composeConfig "github.com/docker/libcompose/config"
|
composeConfig "github.com/docker/libcompose/config"
|
||||||
"github.com/docker/libcompose/docker"
|
"github.com/docker/libcompose/docker"
|
||||||
composeClient "github.com/docker/libcompose/docker/client"
|
composeClient "github.com/docker/libcompose/docker/client"
|
||||||
|
|
||||||
"github.com/docker/libcompose/project"
|
"github.com/docker/libcompose/project"
|
||||||
"github.com/docker/libcompose/project/events"
|
"github.com/docker/libcompose/project/events"
|
||||||
"github.com/docker/libcompose/project/options"
|
"github.com/docker/libcompose/project/options"
|
||||||
@@ -245,13 +247,40 @@ func StageServices(cfg *config.CloudConfig, services ...string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Reduce service configurations to just image and labels
|
// Reduce service configurations to just image and labels
|
||||||
|
needToPull := false
|
||||||
for _, serviceName := range p.ServiceConfigs.Keys() {
|
for _, serviceName := range p.ServiceConfigs.Keys() {
|
||||||
serviceConfig, _ := p.ServiceConfigs.Get(serviceName)
|
serviceConfig, _ := p.ServiceConfigs.Get(serviceName)
|
||||||
|
|
||||||
|
// test to see if we need to Pull
|
||||||
|
var client dockerClient.APIClient
|
||||||
|
if serviceConfig.Labels[config.ScopeLabel] != config.System {
|
||||||
|
client, err = rosDocker.NewDefaultClient()
|
||||||
|
if err != nil {
|
||||||
|
log.Error(err)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
client, err = rosDocker.NewSystemClient()
|
||||||
|
if err != nil {
|
||||||
|
log.Error(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
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{
|
p.ServiceConfigs.Add(serviceName, &composeConfig.ServiceConfig{
|
||||||
Image: serviceConfig.Image,
|
Image: serviceConfig.Image,
|
||||||
Labels: serviceConfig.Labels,
|
Labels: serviceConfig.Labels,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
return p.Pull(context.Background())
|
if needToPull {
|
||||||
|
return p.Pull(context.Background())
|
||||||
|
}
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
@@ -54,7 +54,7 @@ func (s *Service) missingImage() bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
client := s.context.ClientFactory.Create(s)
|
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
|
return err != nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -5,10 +5,11 @@ import . "gopkg.in/check.v1"
|
|||||||
func (s *QemuSuite) TestRosLocalService(c *C) {
|
func (s *QemuSuite) TestRosLocalService(c *C) {
|
||||||
s.RunQemu(c)
|
s.RunQemu(c)
|
||||||
|
|
||||||
|
// System-docker
|
||||||
s.CheckCall(c, `echo "FROM $(sudo system-docker images --format '{{.Repository}}:{{.Tag}}' | grep os-base)" > Dockerfile
|
s.CheckCall(c, `echo "FROM $(sudo system-docker images --format '{{.Repository}}:{{.Tag}}' | grep os-base)" > Dockerfile
|
||||||
sudo system-docker build -t testimage .
|
sudo system-docker build -t testimage .`)
|
||||||
|
|
||||||
echo "test:" > test.yml
|
s.CheckCall(c, `echo "test:" > test.yml
|
||||||
echo " image: testimage" >> test.yml
|
echo " image: testimage" >> test.yml
|
||||||
echo " entrypoint: ls" >> test.yml
|
echo " entrypoint: ls" >> test.yml
|
||||||
echo " labels:" >> test.yml
|
echo " labels:" >> test.yml
|
||||||
@@ -18,7 +19,29 @@ 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 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 enable /var/lib/rancher/conf/test.yml`)
|
||||||
s.CheckCall(c, `sudo ros service up /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`)
|
s.CheckCall(c, `sudo ros service logs test | grep bin`)
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user