Skip to content

Commit

Permalink
add the build parameter to support submitting the private registry ac… (
Browse files Browse the repository at this point in the history
sealerio#475)

* add the build parameter to support submitting the private registry account password

* automatically obtain docker authentication information

* fix

* fix
  • Loading branch information
lllwan authored Aug 4, 2021
1 parent 2cacdc6 commit e713bf2
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 14 deletions.
39 changes: 28 additions & 11 deletions build/lite/docker/pull.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -32,6 +34,7 @@ import (
)

type Docker struct {
Auth string
Username string
Password string
}
Expand Down Expand Up @@ -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() {
Expand Down
9 changes: 8 additions & 1 deletion filesystem/rootfs/docker/scripts/init-registry.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 0 additions & 2 deletions sealer/cmd/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ type BuildFlag struct {
KubefileName string
BuildType string
NoCache bool
Lite bool
ImageList string
}

var buildConfig *BuildFlag
Expand Down

0 comments on commit e713bf2

Please sign in to comment.