1
0
mirror of https://github.com/rancher/os.git synced 2025-08-30 21:26:09 +00:00

Merge pull request #317 from imikushin/preload

docker image preloading
This commit is contained in:
Darren Shepherd 2015-05-22 10:48:52 -07:00
commit 6bb4f07606
4 changed files with 85 additions and 6 deletions

View File

@ -203,6 +203,22 @@ func NewConfig() *Config {
},
LogDriver: "json-file",
},
"preload-system-images": {
Image: "preload",
Privileged: true,
Labels: project.NewSliceorMap(map[string]string{
DETACH: "false",
SCOPE: SYSTEM,
}),
VolumesFrom: []string{
"command-volumes",
"system-volumes",
},
Volumes: []string{
"/var/run/system-docker.sock:/var/run/docker.sock",
"/var/lib/system-docker/preload:/mnt/preload",
},
},
"cloud-init-pre": {
Image: "cloudinit",
Privileged: true,
@ -215,6 +231,9 @@ func NewConfig() *Config {
Environment: project.NewMaporslice([]string{
"CLOUD_INIT_NETWORK=false",
}),
Links: []string{
"preload-system-images",
},
VolumesFrom: []string{
"command-volumes",
"system-volumes",
@ -246,6 +265,7 @@ func NewConfig() *Config {
}),
Net: "host",
Links: []string{
"preload-user-images",
"cloud-init-pre",
"network",
},
@ -311,6 +331,25 @@ func NewConfig() *Config {
"all-volumes",
},
},
"preload-user-images": {
Image: "preload",
Privileged: true,
Labels: project.NewSliceorMap(map[string]string{
DETACH: "false",
SCOPE: SYSTEM,
}),
Links: []string{
"dockerwait",
},
VolumesFrom: []string{
"command-volumes",
"system-volumes",
},
Volumes: []string{
"/var/run/docker.sock:/var/run/docker.sock",
"/var/lib/docker/preload:/mnt/preload",
},
},
"console": {
Image: "console",
Privileged: true,

View File

@ -242,12 +242,6 @@ func (c *Container) requiresUserDocker() bool {
return true
}
for _, v := range c.ContainerCfg.Service.Volumes {
if strings.Index(v, "/var/run/docker.sock") != -1 {
return true
}
}
return false
}
@ -267,10 +261,12 @@ func (c *Container) addLink(link string) {
func (c *Container) parseService() {
if c.requiresSyslog() {
c.addLink("syslog")
log.Infof("[%v]: Implicitly linked to 'syslog'", c.Name)
}
if c.requiresUserDocker() {
c.addLink("dockerwait")
log.Infof("[%v]: Implicitly linked to 'dockerwait'", c.Name)
} else if c.ContainerCfg.Service.Image != "" {
client, err := NewClient(c.dockerHost)
if err != nil {
@ -281,6 +277,7 @@ func (c *Container) parseService() {
i, _ := client.InspectImage(c.ContainerCfg.Service.Image)
if i == nil {
c.addLink("network")
log.Infof("[%v]: Implicitly linked to 'network'", c.Name)
}
}

View File

@ -0,0 +1,3 @@
FROM base
COPY scripts/dockerimages/scripts/preload.sh /
CMD ["/preload.sh"]

View File

@ -0,0 +1,40 @@
#!/bin/bash
set -e
BASE=${1:-${PRELOAD_DIR}}
BASE=${BASE:-/mnt/preload}
should_load() {
file=${1}
if [[ ${file} =~ \.done$ ]]; then echo false
elif [ -f ${file} ]; then
if [ ! -e ${file}.done ]; then echo true
elif [[ $(stat -c %Y ${file}) > $(stat -c %Y ${file}.done) ]]; then echo true
else echo false
fi
else echo false
fi
}
if [ -d ${BASE} ]; then
echo Preloading docker images from ${BASE}...
for file in $(ls ${BASE}); do
path=${BASE}/${file}
loading=$(should_load ${path})
if [ ${loading} == "true" ]; then
CAT="cat ${path}"
if [[ ${file} =~ \.t?gz$ ]]; then CAT="${CAT} | gunzip"; fi
if [[ ${file} =~ \.t?xz$ ]]; then CAT="${CAT} | unxz"; fi
CAT="${CAT} | docker load"
echo loading from ${path}
eval ${CAT} || :
touch ${path}.done || :
fi
done
echo Done.
else
echo Can not preload images from ${BASE}: not a dir or does not exist.
fi