Java Code Examples for com.spotify.docker.client.DockerClient#build()

The following examples show how to use com.spotify.docker.client.DockerClient#build() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PushPullIT.java    From docker-client with Apache License 2.0 6 votes vote down vote up
@Test
public void testPushHubPublicImageWithAuth() throws Exception {
  // Push an image to a public repo on Docker Hub and check it succeeds
  final String dockerDirectory = Resources.getResource("dockerDirectory").getPath();
  final RegistryAuth registryAuth = RegistryAuth.builder()
      .username(HUB_AUTH_USERNAME)
      .password(HUB_AUTH_PASSWORD)
      .build();
  final DockerClient client = DefaultDockerClient
      .fromEnv()
      .registryAuthSupplier(new FixedRegistryAuthSupplier(
          registryAuth, RegistryConfigs.create(singletonMap(HUB_NAME, registryAuth))))
      .build();

  client.build(Paths.get(dockerDirectory), HUB_PUBLIC_IMAGE);
  client.push(HUB_PUBLIC_IMAGE);
}
 
Example 2
Source File: PushPullIT.java    From docker-client with Apache License 2.0 6 votes vote down vote up
@Test
public void testPushHubPrivateImageWithAuth() throws Exception {
  // Push an image to a private repo on Docker Hub and check it succeeds
  final String dockerDirectory = Resources.getResource("dockerDirectory").getPath();
  final RegistryAuth registryAuth = RegistryAuth.builder()
      .username(HUB_AUTH_USERNAME)
      .password(HUB_AUTH_PASSWORD)
      .build();
  final DockerClient client = DefaultDockerClient
      .fromEnv()
      .registryAuthSupplier(new FixedRegistryAuthSupplier(
          registryAuth, RegistryConfigs.create(singletonMap(HUB_NAME, registryAuth))))
      .build();

  client.build(Paths.get(dockerDirectory), HUB_PRIVATE_IMAGE);
  client.push(HUB_PRIVATE_IMAGE);
}
 
Example 3
Source File: PushPullIT.java    From docker-client with Apache License 2.0 5 votes vote down vote up
@Test
public void testPushHubPublicImageWithAuthFromConfig() throws Exception {
  // Push an image to a public repo on Docker Hub and check it succeeds
  final String dockerDirectory = Resources.getResource("dockerDirectory").getPath();
  final DockerClient client = DefaultDockerClient
      .fromEnv()
      .registryAuthSupplier(new ConfigFileRegistryAuthSupplier(
          new DockerConfigReader(),
          Paths.get(Resources.getResource("dockerConfig/dxia4Config.json").toURI())))
      .build();

  client.build(Paths.get(dockerDirectory), HUB_PUBLIC_IMAGE);
  client.push(HUB_PUBLIC_IMAGE);
}
 
Example 4
Source File: PushPullIT.java    From docker-client with Apache License 2.0 5 votes vote down vote up
@Test
public void testBuildHubPrivateImageWithAuth() throws Exception {
  final String dockerDirectory = Resources.getResource("dockerDirectoryNeedsAuth").getPath();
  final RegistryAuth registryAuth = RegistryAuth.builder()
      .username(HUB_AUTH_USERNAME2)
      .password(HUB_AUTH_PASSWORD2)
      .build();
  final DockerClient client = DefaultDockerClient
      .fromEnv()
      .registryAuthSupplier(new FixedRegistryAuthSupplier(
          registryAuth, RegistryConfigs.create(singletonMap(HUB_NAME, registryAuth))))
      .build();

  client.build(Paths.get(dockerDirectory), "testauth", BuildParam.pullNewerImage());
}
 
Example 5
Source File: BuildMojo.java    From docker-maven-plugin with Apache License 2.0 5 votes vote down vote up
private void buildImage(final DockerClient docker, final String buildDir,
                        final DockerClient.BuildParam... buildParams)
    throws MojoExecutionException, DockerException, IOException, InterruptedException {
  getLog().info("Building image " + imageName);
  docker.build(Paths.get(buildDir), imageName, new AnsiProgressHandler(), buildParams);
  getLog().info("Built " + imageName);
}