/** * Configures the output tarball archive with an image reference to set as its tag. * * @param imageReference the image reference * @return a {@link Builder} to finish constructing a new {@link TarImage} * @throws InvalidImageReferenceException if {@code imageReference} is not a valid image reference */ public static Builder named(String imageReference) throws InvalidImageReferenceException { return named(ImageReference.parse(imageReference)); }
/** * Constructs an {@link ImageReference} from the image reference components, consisting of an * optional registry, a repository, and an optional tag. * * @param registry the image registry, or {@code null} to use the default registry (Docker Hub) * @param repository the image repository * @param tag the image tag, or {@code null} to use the default tag ({@code latest}) * @return an {@link ImageReference} built from the given registry, repository, and tag */ public static ImageReference of( @Nullable String registry, String repository, @Nullable String tag) { Preconditions.checkArgument(Strings.isNullOrEmpty(registry) || isValidRegistry(registry)); Preconditions.checkArgument(isValidRepository(repository)); Preconditions.checkArgument(Strings.isNullOrEmpty(tag) || isValidTag(tag)); if (Strings.isNullOrEmpty(registry)) { registry = DOCKER_HUB_REGISTRY; } if (Strings.isNullOrEmpty(tag)) { tag = DEFAULT_TAG; } return new ImageReference(registry, repository, tag); }
public String getImageRegistry() { return image.getRegistry(); }
public String forNoCredentialsDefined(String registry, String repository) { Preconditions.checkNotNull(baseImageReference); Preconditions.checkNotNull(targetImageReference); if (noCredentialsDefinedForBaseImage && registry.equals(baseImageReference.getRegistry()) && repository.equals(baseImageReference.getRepository())) { return forNoCredentialHelpersDefined( baseImageCredHelperConfiguration, baseImageAuthConfiguration.apply(registry)); } if (noCredentialsDefinedForTargetImage && registry.equals(targetImageReference.getRegistry()) && repository.equals(targetImageReference.getRepository())) { return forNoCredentialHelpersDefined( targetImageCredHelperConfiguration, targetImageAuthConfiguration.apply(registry)); } // Credential helper probably was not configured correctly or did not have the necessary // credentials. return forCredentialsNotCorrect(registry); }
/** * Returns {@code true} if the {@link ImageReference} uses the default tag ((@code latest} or * empty); {@code false} if not * * @return {@code true} if uses the default tag; {@code false} if not */ public boolean usesDefaultTag() { return isDefaultTag(tag); }
public String getImageRepository() { return image.getRepository(); }
public String getImageTag() { return image.getTag(); }
/** * Adds an additional tag to tag the target image with. For example, the following would * containerize to both {@code gcr.io/my-project/my-image:tag} and {@code * gcr.io/my-project/my-image:tag2}: * * <pre>{@code * Containerizer.to(RegistryImage.named("gcr.io/my-project/my-image:tag")).withAdditionalTag("tag2"); * }</pre> * * @param tag the additional tag to push to * @return this */ public Containerizer withAdditionalTag(String tag) { Preconditions.checkArgument(ImageReference.isValidTag(tag)); additionalTags.add(tag); return this; }
/** * Stringifies the {@link ImageReference}. When the tag is a digest, it is prepended with the at * {@code @} symbol instead of a colon {@code :}. * * @return the image reference in Docker-readable format (inverse of {@link #parse}) */ @Override public String toString() { StringBuilder referenceString = new StringBuilder(); if (!DOCKER_HUB_REGISTRY.equals(registry)) { // Use registry and repository if not Docker Hub. referenceString.append(registry).append('/').append(repository); } else if (repository.startsWith(LIBRARY_REPOSITORY_PREFIX)) { // If Docker Hub and repository has 'library/' prefix, remove the 'library/' prefix. referenceString.append(repository.substring(LIBRARY_REPOSITORY_PREFIX.length())); } else { // Use just repository if Docker Hub. referenceString.append(repository); } // Use tag if not the default tag. if (!DEFAULT_TAG.equals(tag)) { // Append with "@tag" instead of ":tag" if tag is a digest referenceString.append(isTagDigest() ? '@' : ':').append(tag); } return referenceString.toString(); }
return new ImageReference(registry, repository, tag);
public String forNoCredentialsDefined(String registry, String repository) { Preconditions.checkNotNull(baseImageReference); Preconditions.checkNotNull(targetImageReference); if (noCredentialsDefinedForBaseImage && registry.equals(baseImageReference.getRegistry()) && repository.equals(baseImageReference.getRepository())) { return forNoCredentialHelpersDefined( baseImageCredHelperConfiguration, baseImageAuthConfiguration.apply(registry)); } if (noCredentialsDefinedForTargetImage && registry.equals(targetImageReference.getRegistry()) && repository.equals(targetImageReference.getRepository())) { return forNoCredentialHelpersDefined( targetImageCredHelperConfiguration, targetImageAuthConfiguration.apply(registry)); } // Credential helper probably was not configured correctly or did not have the necessary // credentials. return forCredentialsNotCorrect(registry); }
/** * Returns {@code true} if the {@link ImageReference} uses the default tag ((@code latest} or * empty); {@code false} if not * * @return {@code true} if uses the default tag; {@code false} if not */ public boolean usesDefaultTag() { return isDefaultTag(tag); }
public String getImageRepository() { return image.getRepository(); }
public String getImageTag() { return image.getTag(); }
/** * Adds an additional tag to tag the target image with. For example, the following would * containerize to both {@code gcr.io/my-project/my-image:tag} and {@code * gcr.io/my-project/my-image:tag2}: * * <pre>{@code * Containerizer.to(RegistryImage.named("gcr.io/my-project/my-image:tag")).withAdditionalTag("tag2"); * }</pre> * * @param tag the additional tag to push to * @return this */ public Containerizer withAdditionalTag(String tag) { Preconditions.checkArgument(ImageReference.isValidTag(tag)); additionalTags.add(tag); return this; }
/** * Stringifies the {@link ImageReference}. When the tag is a digest, it is prepended with the at * {@code @} symbol instead of a colon {@code :}. * * @return the image reference in Docker-readable format (inverse of {@link #parse}) */ @Override public String toString() { StringBuilder referenceString = new StringBuilder(); if (!DOCKER_HUB_REGISTRY.equals(registry)) { // Use registry and repository if not Docker Hub. referenceString.append(registry).append('/').append(repository); } else if (repository.startsWith(LIBRARY_REPOSITORY_PREFIX)) { // If Docker Hub and repository has 'library/' prefix, remove the 'library/' prefix. referenceString.append(repository.substring(LIBRARY_REPOSITORY_PREFIX.length())); } else { // Use just repository if Docker Hub. referenceString.append(repository); } // Use tag if not the default tag. if (!DEFAULT_TAG.equals(tag)) { // Append with "@tag" instead of ":tag" if tag is a digest referenceString.append(isTagDigest() ? '@' : ':').append(tag); } return referenceString.toString(); }