diff --git a/build/lite/docker/pull.go b/build/lite/docker/pull.go index 8620c63c589..1bd8b80e5c0 100644 --- a/build/lite/docker/pull.go +++ b/build/lite/docker/pull.go @@ -21,6 +21,8 @@ import ( "fmt" "io" + "github.com/alibaba/sealer/image/reference" + "github.com/alibaba/sealer/common" dockerstreams "github.com/docker/cli/cli/streams" dockerjsonmessage "github.com/docker/docker/pkg/jsonmessage" @@ -32,6 +34,7 @@ import ( ) type Docker struct { + Auth string Username string Password string } @@ -60,27 +63,41 @@ func (d Docker) ImagesPullByList(images []string) { } func (d Docker) ImagePull(image string) error { + var ( + named reference.Named + err error + cli *client.Client + authConfig types.AuthConfig + out io.ReadCloser + encodedJSON []byte + authStr string + ) + named, err = reference.ParseToNamed(image) + if err != nil { + logger.Warn("image information parsing failed: %v", err) + return err + } var ImagePullOptions types.ImagePullOptions ctx := context.Background() - cli, err := client.NewClientWithOpts(client.FromEnv, client.WithAPIVersionNegotiation()) + cli, err = client.NewClientWithOpts(client.FromEnv, client.WithAPIVersionNegotiation()) if err != nil { + logger.Warn("docker client creation failed: %v", err) return err } - if d.Username != "" && d.Password != "" { - authConfig := types.AuthConfig{ - Username: d.Username, - Password: d.Password, - } - encodedJSON, err := json.Marshal(authConfig) + authConfig, err = utils.GetDockerAuthInfoFromDocker(named.Domain()) + if err == nil { + encodedJSON, err = json.Marshal(authConfig) if err != nil { - return err + logger.Warn("authConfig encodedJSON failed: %v", err) + } else { + authStr = base64.URLEncoding.EncodeToString(encodedJSON) } - authStr := base64.URLEncoding.EncodeToString(encodedJSON) - ImagePullOptions = types.ImagePullOptions{RegistryAuth: authStr} } - out, err := cli.ImagePull(ctx, image, ImagePullOptions) + ImagePullOptions = types.ImagePullOptions{RegistryAuth: authStr} + out, err = cli.ImagePull(ctx, image, ImagePullOptions) if err != nil { + logger.Warn("Image pull failed: %v", err) return err } defer func() { diff --git a/filesystem/rootfs/docker/scripts/init-registry.sh b/filesystem/rootfs/docker/scripts/init-registry.sh index 1acebc75795..91964fc9978 100644 --- a/filesystem/rootfs/docker/scripts/init-registry.sh +++ b/filesystem/rootfs/docker/scripts/init-registry.sh @@ -25,4 +25,11 @@ startRegistry() { docker load -q -i ../images/registry.tar || true docker rm $container -f || true -docker run -d --restart=always --net=host --name $container -v $VOLUME:/var/lib/registry registry:2.7.1 || startRegistry + +config=$(dirname "$(pwd)")'/etc/registry_config.yaml' + +if [ -f $config ]; then + docker run -d --restart=always --net=host --name $container -v $VOLUME:/var/lib/registry registry:2.7.1 -v $config:/etc/docker/registry/config.yml|| startRegistry +else + docker run -d --restart=always --net=host --name $container -v $VOLUME:/var/lib/registry registry:2.7.1 || startRegistry +fi \ No newline at end of file diff --git a/sealer/cmd/build.go b/sealer/cmd/build.go index 47015fc8d82..9254585d4bd 100644 --- a/sealer/cmd/build.go +++ b/sealer/cmd/build.go @@ -27,8 +27,6 @@ type BuildFlag struct { KubefileName string BuildType string NoCache bool - Lite bool - ImageList string } var buildConfig *BuildFlag