Skip to content

Commit

Permalink
feat: add initial implementation for images already on disk
Browse files Browse the repository at this point in the history
  • Loading branch information
mattdibi committed Feb 16, 2024
1 parent 91730bd commit 757435c
Showing 1 changed file with 44 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import org.eclipse.kura.KuraErrorCode;
import org.eclipse.kura.KuraException;
import org.eclipse.kura.configuration.ConfigurableComponent;
import org.eclipse.kura.configuration.Password;
import org.eclipse.kura.container.orchestration.ContainerConfiguration;
import org.eclipse.kura.container.orchestration.ContainerInstanceDescriptor;
import org.eclipse.kura.container.orchestration.ContainerOrchestrationService;
Expand All @@ -47,6 +48,7 @@
import com.github.dockerjava.api.command.InspectImageResponse;
import com.github.dockerjava.api.command.PullImageCmd;
import com.github.dockerjava.api.command.PullImageResultCallback;
import com.github.dockerjava.api.exception.NotFoundException;
import com.github.dockerjava.api.model.AuthConfig;
import com.github.dockerjava.api.model.Bind;
import com.github.dockerjava.api.model.Container;
Expand Down Expand Up @@ -272,6 +274,48 @@ public Optional<String> getContainerIdByName(String name) {
return Optional.empty();
}

@Override
public Optional<String> getImageIdByName(String imageName, String imageTag) {
if (!testConnection()) {
throw new IllegalStateException(UNABLE_TO_CONNECT_TO_DOCKER_CLI);
}
if (Objects.isNull(imageName) || imageName.isEmpty() || Objects.isNull(imageTag) || imageTag.isEmpty()) {
throw new IllegalArgumentException(PARAMETER_CANNOT_BE_NULL);
}

try {
return Optional.of(this.dockerClient.inspectImageCmd(imageName + ":" + imageTag).getImageId());
} catch (NotFoundException e) {
logger.debug("Image {}:{} not found on disk.", imageName, imageTag);
}

// What do we do here?
// ...? TODO

return Optional.empty();
}

@Override
public Optional<String> getImageIdByName(String imageName, String imageTag, String username, Password password) {
if (!testConnection()) {
throw new IllegalStateException(UNABLE_TO_CONNECT_TO_DOCKER_CLI);
}
if (Objects.isNull(imageName) || imageName.isEmpty() || Objects.isNull(imageTag) || imageTag.isEmpty()) {
throw new IllegalArgumentException(PARAMETER_CANNOT_BE_NULL);
}

try {
return Optional.of(this.dockerClient.inspectImageCmd(imageName + ":" + imageTag).getImageId());
} catch (NotFoundException e) {
logger.debug("Image {}:{} not found on disk.", imageName, imageTag);
}

// What do we do here?
// ...? TODO

return Optional.empty();
}

@Override
public void startContainer(String id) throws KuraException {
checkRequestEnv(id);
Expand Down

0 comments on commit 757435c

Please sign in to comment.