mirror of
https://github.com/rancher/os.git
synced 2025-09-01 06:40:31 +00:00
@@ -203,6 +203,22 @@ func NewConfig() *Config {
|
|||||||
},
|
},
|
||||||
LogDriver: "json-file",
|
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": {
|
"cloud-init-pre": {
|
||||||
Image: "cloudinit",
|
Image: "cloudinit",
|
||||||
Privileged: true,
|
Privileged: true,
|
||||||
@@ -215,6 +231,9 @@ func NewConfig() *Config {
|
|||||||
Environment: project.NewMaporslice([]string{
|
Environment: project.NewMaporslice([]string{
|
||||||
"CLOUD_INIT_NETWORK=false",
|
"CLOUD_INIT_NETWORK=false",
|
||||||
}),
|
}),
|
||||||
|
Links: []string{
|
||||||
|
"preload-system-images",
|
||||||
|
},
|
||||||
VolumesFrom: []string{
|
VolumesFrom: []string{
|
||||||
"command-volumes",
|
"command-volumes",
|
||||||
"system-volumes",
|
"system-volumes",
|
||||||
@@ -246,6 +265,7 @@ func NewConfig() *Config {
|
|||||||
}),
|
}),
|
||||||
Net: "host",
|
Net: "host",
|
||||||
Links: []string{
|
Links: []string{
|
||||||
|
"preload-user-images",
|
||||||
"cloud-init-pre",
|
"cloud-init-pre",
|
||||||
"network",
|
"network",
|
||||||
},
|
},
|
||||||
@@ -311,6 +331,25 @@ func NewConfig() *Config {
|
|||||||
"all-volumes",
|
"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": {
|
"console": {
|
||||||
Image: "console",
|
Image: "console",
|
||||||
Privileged: true,
|
Privileged: true,
|
||||||
|
@@ -242,12 +242,6 @@ func (c *Container) requiresUserDocker() bool {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, v := range c.ContainerCfg.Service.Volumes {
|
|
||||||
if strings.Index(v, "/var/run/docker.sock") != -1 {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -267,10 +261,12 @@ func (c *Container) addLink(link string) {
|
|||||||
func (c *Container) parseService() {
|
func (c *Container) parseService() {
|
||||||
if c.requiresSyslog() {
|
if c.requiresSyslog() {
|
||||||
c.addLink("syslog")
|
c.addLink("syslog")
|
||||||
|
log.Infof("[%v]: Implicitly linked to 'syslog'", c.Name)
|
||||||
}
|
}
|
||||||
|
|
||||||
if c.requiresUserDocker() {
|
if c.requiresUserDocker() {
|
||||||
c.addLink("dockerwait")
|
c.addLink("dockerwait")
|
||||||
|
log.Infof("[%v]: Implicitly linked to 'dockerwait'", c.Name)
|
||||||
} else if c.ContainerCfg.Service.Image != "" {
|
} else if c.ContainerCfg.Service.Image != "" {
|
||||||
client, err := NewClient(c.dockerHost)
|
client, err := NewClient(c.dockerHost)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -281,6 +277,7 @@ func (c *Container) parseService() {
|
|||||||
i, _ := client.InspectImage(c.ContainerCfg.Service.Image)
|
i, _ := client.InspectImage(c.ContainerCfg.Service.Image)
|
||||||
if i == nil {
|
if i == nil {
|
||||||
c.addLink("network")
|
c.addLink("network")
|
||||||
|
log.Infof("[%v]: Implicitly linked to 'network'", c.Name)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
3
scripts/dockerimages/13-preload
Normal file
3
scripts/dockerimages/13-preload
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
FROM base
|
||||||
|
COPY scripts/dockerimages/scripts/preload.sh /
|
||||||
|
CMD ["/preload.sh"]
|
40
scripts/dockerimages/scripts/preload.sh
Executable file
40
scripts/dockerimages/scripts/preload.sh
Executable 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
|
||||||
|
|
Reference in New Issue
Block a user