1
0
mirror of https://github.com/rancher/os.git synced 2025-08-30 03:56:17 +00:00

Reduce repeated system image loading

This commit is contained in:
niusmallnan 2018-11-20 11:08:26 +08:00 committed by niusmallnan
parent f508c86d5a
commit 6be7426bf3

View File

@ -1,10 +1,12 @@
package sysinit package sysinit
import ( import (
"fmt"
"os" "os"
"os/exec" "os/exec"
"path" "path"
"path/filepath" "path/filepath"
"strings"
"syscall" "syscall"
"github.com/rancher/os/cmd/control" "github.com/rancher/os/cmd/control"
@ -20,6 +22,7 @@ import (
const ( const (
systemImagesPreloadDirectory = "/var/lib/rancher/preload/system-docker" systemImagesPreloadDirectory = "/var/lib/rancher/preload/system-docker"
systemImagesLoadStamp = "/var/lib/rancher/.sysimages_%s_loaded.done"
) )
func hasImage(name string) bool { func hasImage(name string) bool {
@ -46,9 +49,16 @@ func LoadBootstrapImages(cfg *config.CloudConfig) (*config.CloudConfig, error) {
} }
func LoadSystemImages(cfg *config.CloudConfig) (*config.CloudConfig, error) { func LoadSystemImages(cfg *config.CloudConfig) (*config.CloudConfig, error) {
stamp := fmt.Sprintf(systemImagesLoadStamp, strings.Replace(config.Version, ".", "_", -1))
if _, err := os.Stat(stamp); os.IsNotExist(err) {
os.Create(stamp)
return loadImages(cfg, false) return loadImages(cfg, false)
} }
log.Infof("Skipped loading system images because %s exists", systemImagesLoadStamp)
return cfg, nil
}
func loadImages(cfg *config.CloudConfig, bootstrap bool) (*config.CloudConfig, error) { func loadImages(cfg *config.CloudConfig, bootstrap bool) (*config.CloudConfig, error) {
archive := getImagesArchive(bootstrap) archive := getImagesArchive(bootstrap)
@ -75,7 +85,7 @@ func loadImages(cfg *config.CloudConfig, bootstrap bool) (*config.CloudConfig, e
dockerImages, _ := client.ImageList(context.Background(), types.ImageListOptions{}) dockerImages, _ := client.ImageList(context.Background(), types.ImageListOptions{})
for _, dimg := range dockerImages { for _, dimg := range dockerImages {
log.Infof("Got image repo tags: %s", dimg.RepoTags) log.Debugf("Loaded a docker image: %s", dimg.RepoTags)
} }
return cfg, nil return cfg, nil