Search in sources :

Example 1 with AuthConfig

use of com.github.dockerjava.api.model.AuthConfig in project camel by apache.

the class AsyncDockerProducer method executePullImageRequest.

/**
     * Produces a pull image request
     *
     * @param client
     * @param message
     * @return
     */
private PullImageCmd executePullImageRequest(DockerClient client, Message message) {
    LOGGER.debug("Executing Docker Pull Image Request");
    String repository = DockerHelper.getProperty(DockerConstants.DOCKER_REPOSITORY, configuration, message, String.class);
    ObjectHelper.notNull(repository, "Repository must be specified");
    PullImageCmd pullImageCmd = client.pullImageCmd(repository);
    String registry = DockerHelper.getProperty(DockerConstants.DOCKER_REGISTRY, configuration, message, String.class);
    if (registry != null) {
        pullImageCmd.withRegistry(registry);
    }
    String tag = DockerHelper.getProperty(DockerConstants.DOCKER_TAG, configuration, message, String.class);
    if (tag != null) {
        pullImageCmd.withTag(tag);
    }
    AuthConfig authConfig = client.authConfig();
    if (authConfig != null) {
        pullImageCmd.withAuthConfig(authConfig);
    }
    return pullImageCmd;
}
Also used : PullImageCmd(com.github.dockerjava.api.command.PullImageCmd) AuthConfig(com.github.dockerjava.api.model.AuthConfig)

Example 2 with AuthConfig

use of com.github.dockerjava.api.model.AuthConfig in project camel by apache.

the class DockerProducer method executeAuthRequest.

/*********************
     * General Requests
     ********************/
/**
     * Produces a Authorization request
     *
     * @param client
     * @param message
     * @return
     */
private AuthCmd executeAuthRequest(DockerClient client, Message message) {
    LOGGER.debug("Executing Docker Auth Request");
    AuthCmd authCmd = client.authCmd();
    AuthConfig authConfig = client.authConfig();
    if (authCmd != null) {
        authCmd.withAuthConfig(authConfig);
    }
    return authCmd;
}
Also used : AuthConfig(com.github.dockerjava.api.model.AuthConfig) AuthCmd(com.github.dockerjava.api.command.AuthCmd)

Example 3 with AuthConfig

use of com.github.dockerjava.api.model.AuthConfig in project camel by apache.

the class AsyncDockerProducer method executePushImageRequest.

/**
     * Produces a push image request
     *
     * @param client
     * @param message
     * @return
     */
private PushImageCmd executePushImageRequest(DockerClient client, Message message) {
    LOGGER.debug("Executing Docker Push Image Request");
    String name = DockerHelper.getProperty(DockerConstants.DOCKER_NAME, configuration, message, String.class);
    ObjectHelper.notNull(name, "Image name must be specified");
    PushImageCmd pushImageCmd = client.pushImageCmd(name);
    String tag = DockerHelper.getProperty(DockerConstants.DOCKER_TAG, configuration, message, String.class);
    if (tag != null) {
        pushImageCmd.withTag(tag);
    }
    AuthConfig authConfig = client.authConfig();
    if (authConfig != null) {
        pushImageCmd.withAuthConfig(authConfig);
    }
    return pushImageCmd;
}
Also used : PushImageCmd(com.github.dockerjava.api.command.PushImageCmd) AuthConfig(com.github.dockerjava.api.model.AuthConfig)

Example 4 with AuthConfig

use of com.github.dockerjava.api.model.AuthConfig in project vespa by vespa-engine.

the class DockerImpl method pullImageAsyncIfNeeded.

@Override
public boolean pullImageAsyncIfNeeded(final DockerImage image) {
    try {
        synchronized (monitor) {
            if (scheduledPulls.contains(image))
                return true;
            if (imageIsDownloaded(image))
                return false;
            scheduledPulls.add(image);
            PullImageCmd pullImageCmd = dockerClient.pullImageCmd(image.asString());
            dockerRegistryCredentialsSupplier.flatMap(credentialsSupplier -> credentialsSupplier.getCredentials(image)).map(credentials -> new AuthConfig().withRegistryAddress(credentials.registry.toString()).withUsername(credentials.username).withPassword(credentials.password)).ifPresent(pullImageCmd::withAuthConfig);
            logger.log(LogLevel.INFO, "Starting download of " + image.asString());
            pullImageCmd.exec(new ImagePullCallback(image));
            return true;
        }
    } catch (RuntimeException e) {
        numberOfDockerDaemonFails.add();
        throw new DockerException("Failed to pull image '" + image.asString() + "'", e);
    }
}
Also used : Arrays(java.util.Arrays) NotModifiedException(com.github.dockerjava.api.exception.NotModifiedException) Dimensions(com.yahoo.vespa.hosted.dockerapi.metrics.Dimensions) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ExecStartResultCallback(com.github.dockerjava.core.command.ExecStartResultCallback) Inject(com.google.inject.Inject) HashMap(java.util.HashMap) ExecCreateCmdResponse(com.github.dockerjava.api.command.ExecCreateCmdResponse) DockerClientException(com.github.dockerjava.api.exception.DockerClientException) DockerClient(com.github.dockerjava.api.DockerClient) InetAddress(java.net.InetAddress) HashSet(java.util.HashSet) MetricReceiverWrapper(com.yahoo.vespa.hosted.dockerapi.metrics.MetricReceiverWrapper) ResultCallbackTemplate(com.github.dockerjava.core.async.ResultCallbackTemplate) DockerClientConfig(com.github.dockerjava.core.DockerClientConfig) DockerClientImpl(com.github.dockerjava.core.DockerClientImpl) NetworkAddressInterface(com.yahoo.vespa.hosted.dockerapi.DockerNetworkCreator.NetworkAddressInterface) Duration(java.time.Duration) Map(java.util.Map) LogLevel(com.yahoo.log.LogLevel) CounterWrapper(com.yahoo.vespa.hosted.dockerapi.metrics.CounterWrapper) InspectImageResponse(com.github.dockerjava.api.command.InspectImageResponse) DefaultDockerClientConfig(com.github.dockerjava.core.DefaultDockerClientConfig) PullImageResultCallback(com.github.dockerjava.core.command.PullImageResultCallback) NotFoundException(com.github.dockerjava.api.exception.NotFoundException) PullImageCmd(com.github.dockerjava.api.command.PullImageCmd) AuthConfig(com.github.dockerjava.api.model.AuthConfig) InspectExecResponse(com.github.dockerjava.api.command.InspectExecResponse) ExecStartCmd(com.github.dockerjava.api.command.ExecStartCmd) Set(java.util.Set) Statistics(com.github.dockerjava.api.model.Statistics) IOException(java.io.IOException) GuardedBy(javax.annotation.concurrent.GuardedBy) Logger(java.util.logging.Logger) InspectContainerResponse(com.github.dockerjava.api.command.InspectContainerResponse) Collectors(java.util.stream.Collectors) Defaults.getDefaults(com.yahoo.vespa.defaults.Defaults.getDefaults) Image(com.github.dockerjava.api.model.Image) Network(com.github.dockerjava.api.model.Network) TimeUnit(java.util.concurrent.TimeUnit) Inet6Address(java.net.Inet6Address) CountDownLatch(java.util.concurrent.CountDownLatch) List(java.util.List) Stream(java.util.stream.Stream) InspectContainerCmd(com.github.dockerjava.api.command.InspectContainerCmd) JerseyDockerCmdExecFactory(com.github.dockerjava.jaxrs.JerseyDockerCmdExecFactory) Optional(java.util.Optional) Collections(java.util.Collections) PullImageCmd(com.github.dockerjava.api.command.PullImageCmd) AuthConfig(com.github.dockerjava.api.model.AuthConfig)

Aggregations

AuthConfig (com.github.dockerjava.api.model.AuthConfig)4 PullImageCmd (com.github.dockerjava.api.command.PullImageCmd)2 DockerClient (com.github.dockerjava.api.DockerClient)1 AuthCmd (com.github.dockerjava.api.command.AuthCmd)1 ExecCreateCmdResponse (com.github.dockerjava.api.command.ExecCreateCmdResponse)1 ExecStartCmd (com.github.dockerjava.api.command.ExecStartCmd)1 InspectContainerCmd (com.github.dockerjava.api.command.InspectContainerCmd)1 InspectContainerResponse (com.github.dockerjava.api.command.InspectContainerResponse)1 InspectExecResponse (com.github.dockerjava.api.command.InspectExecResponse)1 InspectImageResponse (com.github.dockerjava.api.command.InspectImageResponse)1 PushImageCmd (com.github.dockerjava.api.command.PushImageCmd)1 DockerClientException (com.github.dockerjava.api.exception.DockerClientException)1 NotFoundException (com.github.dockerjava.api.exception.NotFoundException)1 NotModifiedException (com.github.dockerjava.api.exception.NotModifiedException)1 Image (com.github.dockerjava.api.model.Image)1 Network (com.github.dockerjava.api.model.Network)1 Statistics (com.github.dockerjava.api.model.Statistics)1 DefaultDockerClientConfig (com.github.dockerjava.core.DefaultDockerClientConfig)1 DockerClientConfig (com.github.dockerjava.core.DockerClientConfig)1 DockerClientImpl (com.github.dockerjava.core.DockerClientImpl)1