mirror of
https://github.com/rancher/os.git
synced 2025-06-25 06:21:33 +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:
commit
a3f942f03b
@ -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,47 @@ 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
|
||||||
|
var client, userClient, systemClient dockerClient.APIClient
|
||||||
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
|
||||||
|
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{
|
p.ServiceConfigs.Add(serviceName, &composeConfig.ServiceConfig{
|
||||||
Image: serviceConfig.Image,
|
Image: serviceConfig.Image,
|
||||||
Labels: serviceConfig.Labels,
|
Labels: serviceConfig.Labels,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if needToPull {
|
||||||
return p.Pull(context.Background())
|
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
|
||||||
}
|
}
|
||||||
|
|
||||||
|
47
tests/ros_services.go
Normal file
47
tests/ros_services.go
Normal 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`)
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user