本文整理匯總了Golang中github.com/fsouza/go-dockerclient.ParseRepositoryTag函數的典型用法代碼示例。如果您正苦於以下問題:Golang ParseRepositoryTag函數的具體用法?Golang ParseRepositoryTag怎麽用?Golang ParseRepositoryTag使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了ParseRepositoryTag函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: LoadImage
// LoadImage checks the client for an image matching from. If not found,
// attempts to pull the image and then tries to inspect again.
func (e *ClientExecutor) LoadImage(from string) (*docker.Image, error) {
image, err := e.Client.InspectImage(from)
if err == nil {
return image, nil
}
if err != docker.ErrNoSuchImage {
return nil, err
}
if !e.AllowPull {
glog.V(4).Infof("image %s did not exist", from)
return nil, docker.ErrNoSuchImage
}
repository, tag := docker.ParseRepositoryTag(from)
if len(tag) == 0 {
tag = "latest"
}
glog.V(4).Infof("attempting to pull %s with auth from repository %s:%s", from, repository, tag)
// TODO: we may want to abstract looping over multiple credentials
auth, _ := e.AuthFn(repository)
if len(auth) == 0 {
auth = append(auth, credentialprovider.LazyAuthConfiguration{})
}
if e.LogFn != nil {
e.LogFn("Image %s was not found, pulling ...", from)
}
var lastErr error
outputProgress := func(s string) {
e.LogFn("%s", s)
}
for _, config := range auth {
// TODO: handle IDs?
pullImageOptions := docker.PullImageOptions{
Repository: repository,
Tag: tag,
OutputStream: imageprogress.NewPullWriter(outputProgress),
RawJSONStream: true,
}
if glog.V(5) {
pullImageOptions.OutputStream = os.Stderr
pullImageOptions.RawJSONStream = false
}
authConfig := docker.AuthConfiguration{Username: config.Username, ServerAddress: config.ServerAddress, Password: config.Password}
if err = e.Client.PullImage(pullImageOptions, authConfig); err == nil {
break
}
lastErr = err
continue
}
if lastErr != nil {
return nil, fmt.Errorf("unable to pull image (from: %s, tag: %s): %v", repository, tag, lastErr)
}
return e.Client.InspectImage(from)
}
示例2: CommitContainer
// CommitContainer commits a container to an image with a specific tag.
// The new image ID is returned
func (d *stiDocker) CommitContainer(opts CommitContainerOptions) (string, error) {
repository, tag := docker.ParseRepositoryTag(opts.Repository)
dockerOpts := docker.CommitContainerOptions{
Container: opts.ContainerID,
Repository: repository,
Tag: tag,
}
if opts.Command != nil || opts.Entrypoint != nil {
config := docker.Config{
Cmd: opts.Command,
Entrypoint: opts.Entrypoint,
Env: opts.Env,
Labels: opts.Labels,
User: opts.User,
}
dockerOpts.Run = &config
glog.V(2).Infof("Committing container with dockerOpts: %+v, config: %+v", dockerOpts, config)
}
image, err := d.client.CommitContainer(dockerOpts)
if err == nil && image != nil {
return image.ID, nil
}
return "", err
}
示例3: pushImage
// pushImage pushes a docker image to the registry specified in its tag.
// The method will retry to push the image when following scenarios occur:
// - Docker registry is down temporarily or permanently
// - other image is being pushed to the registry
// If any other scenario the push will fail, without retries.
func pushImage(client DockerClient, name string, authConfig docker.AuthConfiguration) error {
repository, tag := docker.ParseRepositoryTag(name)
opts := docker.PushImageOptions{
Name: repository,
Tag: tag,
}
if glog.V(5) {
opts.OutputStream = os.Stderr
}
var err error
for retries := 0; retries <= DefaultPushRetryCount; retries++ {
err = client.PushImage(opts, authConfig)
if err == nil {
return nil
}
errMsg := fmt.Sprintf("%s", err)
if !strings.Contains(errMsg, "ping attempt failed with error") && !strings.Contains(errMsg, "is already in progress") {
return err
}
util.HandleError(fmt.Errorf("push for image %s failed, will retry in %s seconds ...", name, DefaultPushRetryDelay))
glog.Flush()
time.Sleep(DefaultPushRetryDelay)
}
return err
}
示例4: pushImage
// pushImage pushes a docker image to the registry specified in its tag.
// The method will retry to push the image when following scenarios occur:
// - Docker registry is down temporarily or permanently
// - other image is being pushed to the registry
// If any other scenario the push will fail, without retries.
func pushImage(client DockerClient, name string, authConfig docker.AuthConfiguration) error {
repository, tag := docker.ParseRepositoryTag(name)
opts := docker.PushImageOptions{
Name: repository,
Tag: tag,
}
if glog.V(5) {
opts.OutputStream = os.Stderr
}
var err error
var retriableError = false
for retries := 0; retries <= DefaultPushRetryCount; retries++ {
err = client.PushImage(opts, authConfig)
if err == nil {
return nil
}
errMsg := fmt.Sprintf("%s", err)
for _, errorString := range RetriableErrors {
if strings.Contains(errMsg, errorString) {
retriableError = true
break
}
}
if !retriableError {
return err
}
utilruntime.HandleError(fmt.Errorf("push for image %s failed, will retry in %s ...", name, DefaultPushRetryDelay))
glog.Flush()
time.Sleep(DefaultPushRetryDelay)
}
return err
}
示例5: createImage
// createImage creates a docker image either by pulling it from a registry or by
// loading it from the file system
func (d *DockerDriver) createImage(driverConfig *DockerDriverConfig, client *docker.Client, taskDir string) error {
image := driverConfig.ImageName
repo, tag := docker.ParseRepositoryTag(image)
if tag == "" {
tag = "latest"
}
var dockerImage *docker.Image
var err error
// We're going to check whether the image is already downloaded. If the tag
// is "latest" we have to check for a new version every time so we don't
// bother to check and cache the id here. We'll download first, then cache.
if tag != "latest" {
dockerImage, err = client.InspectImage(image)
}
// Download the image
if dockerImage == nil {
if len(driverConfig.LoadImages) > 0 {
return d.loadImage(driverConfig, client, taskDir)
}
return d.pullImage(driverConfig, client, repo, tag)
}
return err
}
示例6: pullImage
// pullImage pulls the latest image for the given repotag from a public
// registry.
func (c *client) pullImage(repoTag string) error {
// configuration options that get passed to client.PullImage
repository, tag := docker.ParseRepositoryTag(repoTag)
pullImageOptions := docker.PullImageOptions{Repository: repository, Tag: tag}
// pull image from registry
return c.client.PullImage(pullImageOptions, docker.AuthConfiguration{})
}
示例7: getImageName
// getImageName checks the image name and adds DefaultTag if none is specified
func getImageName(name string) string {
_, tag := docker.ParseRepositoryTag(name)
if len(tag) == 0 {
return strings.Join([]string{name, DefaultTag}, ":")
}
return name
}
示例8: ValidateImage
// ValidateImage validates the image field does not include a tag
func (c *ImageConfig) ValidateImage() error {
_, tag := docker.ParseRepositoryTag(c.Image)
if tag != "" {
return fmt.Errorf(
"tag %q must be specified in the `tags` field, not in `image`", tag)
}
return nil
}
示例9: ValidateTags
// ValidateTags to ensure the first tag is a basic tag without an image name.
func (c *ImageConfig) ValidateTags() error {
if len(c.Tags) == 0 {
return nil
}
_, tag := docker.ParseRepositoryTag(c.Tags[0])
if tag != "" {
return fmt.Errorf("the first tag %q may not include an image name", tag)
}
return nil
}
示例10: tagImage
// tagImage uses the dockerClient to tag a Docker image with name. It is a
// helper to facilitate the usage of dockerClient.TagImage, because the former
// requires the name to be split into more explicit parts.
func tagImage(dockerClient DockerClient, image, name string) error {
repo, tag := docker.ParseRepositoryTag(name)
return dockerClient.TagImage(image, docker.TagImageOptions{
Repo: repo,
Tag: tag,
// We need to set Force to true to update the tag even if it
// already exists. This is the same behavior as `docker build -t
// tag .`.
Force: true,
})
}
示例11: tagImage
func tagImage(ctx *context.ExecuteContext, config *config.ImageConfig, imageTag string) error {
canonicalImageTag := GetImageName(ctx, config)
if imageTag == canonicalImageTag {
return nil
}
repo, tag := docker.ParseRepositoryTag(imageTag)
err := ctx.Client.TagImage(canonicalImageTag, docker.TagImageOptions{
Repo: repo,
Tag: tag,
Force: true,
})
if err != nil {
return fmt.Errorf("failed to add tag %q: %s", imageTag, err)
}
return nil
}
示例12: pullImage
func pullImage(ctx *context.ExecuteContext, t *Task, imageTag string) error {
registry, err := parseAuthRepo(t.config.Image)
if err != nil {
return err
}
repo, tag := docker.ParseRepositoryTag(imageTag)
return Stream(os.Stdout, func(out io.Writer) error {
return ctx.Client.PullImage(docker.PullImageOptions{
Repository: repo,
Tag: tag,
OutputStream: out,
RawJSONStream: true,
// TODO: timeout
}, ctx.GetAuthConfig(registry))
})
}
示例13: importImage
func importImage(client *dockerClient.Client, name, fileName string) error {
file, err := os.Open(fileName)
if err != nil {
return err
}
defer file.Close()
log.Debugf("Importing image for %s", fileName)
repo, tag := dockerClient.ParseRepositoryTag(name)
return client.ImportImage(dockerClient.ImportImageOptions{
Source: "-",
Repository: repo,
Tag: tag,
InputStream: file,
})
}
示例14: ForEachTag
// ForEachTag runs a function for each tag
func (t *Task) ForEachTag(ctx *context.ExecuteContext, each func(string) error) error {
if len(t.config.Tags) == 0 {
return each(GetImageName(ctx, t.config))
}
for _, tag := range t.config.Tags {
imageTag := t.config.Image + ":" + tag
// If the tag is already a complete image name then use it directly
if _, hasTag := docker.ParseRepositoryTag(tag); hasTag != "" {
imageTag = tag
}
if err := each(imageTag); err != nil {
return err
}
}
return nil
}
示例15: LoadImage
// LoadImage checks the client for an image matching from. If not found,
// attempts to pull the image and then tries to inspect again.
func (e *ClientExecutor) LoadImage(from string) (*docker.Image, error) {
image, err := e.Client.InspectImage(from)
if err == nil {
return image, nil
}
if err != docker.ErrNoSuchImage {
return nil, err
}
if !e.AllowPull {
glog.V(4).Infof("image %s did not exist", from)
return nil, docker.ErrNoSuchImage
}
repository, _ := docker.ParseRepositoryTag(from)
glog.V(4).Infof("attempting to pull %s with auth from repository %s", from, repository)
// TODO: we may want to abstract looping over multiple credentials
auth, _ := e.AuthFn(repository)
if len(auth) == 0 {
auth = append(auth, docker.AuthConfiguration{})
}
if e.LogFn != nil {
e.LogFn("Image %s was not found, pulling ...", from)
}
var lastErr error
for _, config := range auth {
// TODO: handle IDs?
// TODO: use RawJSONStream:true and handle the output nicely
if err = e.Client.PullImage(docker.PullImageOptions{Repository: from, OutputStream: e.Out}, config); err == nil {
break
}
lastErr = err
continue
}
if lastErr != nil {
return nil, lastErr
}
return e.Client.InspectImage(from)
}