@Override public Image getImage(final String imageIdOrName) { checkNotNull(imageIdOrName); if (imageIdOrName.startsWith("sha256")) { // less efficient than just inspectImage but listImages return repoTags return find(listImages(), new Predicate<Image>() { @Override public boolean apply(Image input) { // Only attempt match on id as we should try to pull again anyway if using name return input.id().equals(imageIdOrName); } }, null); } // Image is not cached or getting image by name so try to pull it api.getImageApi().createImage(CreateImageOptions.Builder.fromImage(imageIdOrName)); // as above this ensure repotags are returned return find(listImages(), createPredicateMatchingRepoTags(imageIdOrName), null); }
@Override public Image getImage(final String imageIdOrName) { checkNotNull(imageIdOrName); if (imageIdOrName.startsWith("sha256")) { // less efficient than just inspectImage but listImages return repoTags return find(listImages(), new Predicate<Image>() { @Override public boolean apply(Image input) { // Only attempt match on id as we should try to pull again anyway if using name return input.id().equals(imageIdOrName); } }, null); } // Image is not cached or getting image by name so try to pull it api.getImageApi().createImage(CreateImageOptions.Builder.fromImage(imageIdOrName)); // as above this ensure repotags are returned return find(listImages(), createPredicateMatchingRepoTags(imageIdOrName), null); }
@Override public Image getImage(final String imageIdOrName) { checkNotNull(imageIdOrName); if (imageIdOrName.startsWith("sha256")) { // less efficient than just inspectImage but listImages return repoTags return find(listImages(), new Predicate<Image>() { @Override public boolean apply(Image input) { // Only attempt match on id as we should try to pull again anyway if using name return input.id().equals(imageIdOrName); } }, null); } // Image is not cached or getting image by name so try to pull it api.getImageApi().createImage(CreateImageOptions.Builder.fromImage(imageIdOrName)); // as above this ensure repotags are returned return find(listImages(), createPredicateMatchingRepoTags(imageIdOrName), null); }
@Override public Image getImage(final String imageIdOrName) { checkNotNull(imageIdOrName); if (imageIdOrName.startsWith("sha256")) { // less efficient than just inspectImage but listImages return repoTags return find(listImages(), new Predicate<Image>() { @Override public boolean apply(Image input) { // Only attempt match on id as we should try to pull again anyway if using name return input.id().equals(imageIdOrName); } }, null); } // Image is not cached or getting image by name so try to pull it api.getImageApi().createImage(CreateImageOptions.Builder.fromImage(imageIdOrName)); // as above this ensure repotags are returned return find(listImages(), new Predicate<Image>() { @Override public boolean apply(Image input) { for (String tag : input.repoTags()) { if (tag.equals(imageIdOrName) || tag.equals(imageIdOrName + ":latest")) { return true; } } return false; } }, null); }
@Test public void testCreateImage() { InputStream createImageStream = api().createImage(CreateImageOptions.Builder.fromImage(DEFAULT_IMAGE).tag(DEFAULT_TAG)); consumeStream(createImageStream); }
@BeforeClass protected void init() { if (api.getImageApi().inspectImage(ALPINE_IMAGE_TAG) == null) { CreateImageOptions options = CreateImageOptions.Builder.fromImage(ALPINE_IMAGE_TAG); InputStream createImageStream = api.getImageApi().createImage(options); consumeStream(createImageStream); } image = api.getImageApi().inspectImage(ALPINE_IMAGE_TAG); assertNotNull(image); }
public void testCreateImage() throws Exception { MockWebServer server = mockWebServer(new MockResponse().setResponseCode(200)); ImageApi api = api(DockerApi.class, server.getUrl("/").toString()).getImageApi(); try { api.createImage(CreateImageOptions.Builder.fromImage("base")); assertSent(server, "POST", "/images/create?fromImage=base"); } finally { server.shutdown(); } }
@BeforeClass protected void init() { if (api.getImageApi().inspectImage(ALPINE_IMAGE_TAG) == null) { CreateImageOptions options = CreateImageOptions.Builder.fromImage(ALPINE_IMAGE_TAG); InputStream createImageStream = api.getImageApi().createImage(options); consumeStream(createImageStream); } image = api.getImageApi().inspectImage(ALPINE_IMAGE_TAG); assertNotNull(image); Config containerConfig = Config.builder().image(image.id()) .cmd(ImmutableList.of("/bin/sh", "-c", "touch hello; while true; do echo hello world; sleep 1; done")) .build(); container = api.getContainerApi().createContainer("miscApiTest", containerConfig); assertNotNull(container); api.getContainerApi().startContainer(container.id()); assertTrue(api.getContainerApi().inspectContainer(container.id()).state().running()); }
@BeforeClass protected void init() { if (api.getImageApi().inspectImage(ALPINE_IMAGE_TAG) == null) { CreateImageOptions options = CreateImageOptions.Builder.fromImage(ALPINE_IMAGE_TAG); InputStream createImageStream = api.getImageApi().createImage(options); consumeStream(createImageStream); } image = api.getImageApi().inspectImage(ALPINE_IMAGE_TAG); assertNotNull(image); Config containerConfig = Config.builder().image(image.id()) .cmd(ImmutableList.of("sh", "-c", "touch hello; while true; do echo hello world; sleep 1; done")) .build(); container = api.getContainerApi().createContainer("jclouds-test-network", containerConfig); api.getContainerApi().startContainer(container.id()); container = api.getContainerApi().inspectContainer(container.id()); }
protected Template buildTemplate(TemplateBuilder templateBuilder) { String imageName = SSHABLE_IMAGE + ":" + SSHABLE_IMAGE_TAG; org.jclouds.docker.domain.Image image = imageApi().inspectImage(imageName); if (image == null) { CreateImageOptions options = CreateImageOptions.Builder.fromImage(SSHABLE_IMAGE).tag(SSHABLE_IMAGE_TAG); imageApi().createImage(options); } image = imageApi().inspectImage(imageName); defaultImage = client.getImage(image.id()); DockerTemplateOptions options = new DockerTemplateOptions(); options.env(ImmutableList.of("ROOT_PASS=password")); options.overrideLoginCredentials(LoginCredentials.builder().identity("root").credential("password").build()); template = templateBuilder.imageId(defaultImage.getId()).options(options).build(); return template; }