| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,17 +1,16 @@ | |||
| 1 | 1 | package com.github.dockerjava.api.command; | |
| 2 | 2 | ||
| 3 | + import com.github.dockerjava.api.model.AuthConfigurations; | ||
| 4 | + import com.github.dockerjava.api.model.BuildResponseItem; | ||
| 5 | + | ||
| 6 | + import javax.annotation.CheckForNull; | ||
| 7 | + import javax.annotation.Nonnull; | ||
| 3 | 8 | import java.io.File; | |
| 4 | 9 | import java.io.InputStream; | |
| 5 | 10 | import java.net.URI; | |
| 6 | 11 | import java.util.Map; | |
| 7 | 12 | import java.util.Set; | |
| 8 | 13 | ||
| 9 | - import javax.annotation.CheckForNull; | ||
| 10 | - import javax.annotation.Nonnull; | ||
| 11 | - | ||
| 12 | - import com.github.dockerjava.api.model.AuthConfigurations; | ||
| 13 | - import com.github.dockerjava.api.model.BuildResponseItem; | ||
| 14 | - | ||
| 15 | 14 | /** | |
| 16 | 15 | * Build an image from Dockerfile. | |
| 17 | 16 | * <p> | |
@@ -145,6 +144,12 @@ public interface BuildImageCmd extends AsyncDockerCmd<BuildImageCmd, BuildRespon | |||
| 145 | 144 | @CheckForNull | |
| 146 | 145 | String getTarget(); | |
| 147 | 146 | ||
| 147 | + /** | ||
| 148 | + * @since {@link RemoteApiVersion#VERSION_1_28} | ||
| 149 | + */ | ||
| 150 | + @CheckForNull | ||
| 151 | + Set<String> getExtraHosts(); | ||
| 152 | + | ||
| 148 | 153 | // setters | |
| 149 | 154 | ||
| 150 | 155 | /** | |
@@ -223,6 +228,11 @@ public interface BuildImageCmd extends AsyncDockerCmd<BuildImageCmd, BuildRespon | |||
| 223 | 228 | */ | |
| 224 | 229 | BuildImageCmd withTarget(String target); | |
| 225 | 230 | ||
| 231 | + /** | ||
| 232 | + * @since {@link RemoteApiVersion#VERSION_1_28} | ||
| 233 | + */ | ||
| 234 | + BuildImageCmd withExtraHosts(Set<String> extraHosts); | ||
| 235 | + | ||
| 226 | 236 | @Override | |
| 227 | 237 | default BuildImageResultCallback start() { | |
| 228 | 238 | return exec(new BuildImageResultCallback()); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -79,6 +79,7 @@ public class RemoteApiVersion implements Serializable { | |||
| 79 | 79 | ||
| 80 | 80 | public static final RemoteApiVersion VERSION_1_26 = RemoteApiVersion.create(1, 26); | |
| 81 | 81 | public static final RemoteApiVersion VERSION_1_27 = RemoteApiVersion.create(1, 27); | |
| 82 | + public static final RemoteApiVersion VERSION_1_28 = RemoteApiVersion.create(1, 28); | ||
| 82 | 83 | public static final RemoteApiVersion VERSION_1_29 = RemoteApiVersion.create(1, 29); | |
| 83 | 84 | public static final RemoteApiVersion VERSION_1_30 = RemoteApiVersion.create(1, 30); | |
| 84 | 85 | public static final RemoteApiVersion VERSION_1_31 = RemoteApiVersion.create(1, 31); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,7 +1,12 @@ | |||
| 1 | 1 | package com.github.dockerjava.core.command; | |
| 2 | 2 | ||
| 3 | - import static com.google.common.base.Preconditions.checkNotNull; | ||
| 3 | + import com.github.dockerjava.api.command.BuildImageCmd; | ||
| 4 | + import com.github.dockerjava.api.model.AuthConfigurations; | ||
| 5 | + import com.github.dockerjava.api.model.BuildResponseItem; | ||
| 6 | + import com.github.dockerjava.core.dockerfile.Dockerfile; | ||
| 7 | + import com.github.dockerjava.core.util.FilePathUtil; | ||
| 4 | 8 | ||
| 9 | + import javax.annotation.CheckForNull; | ||
| 5 | 10 | import java.io.File; | |
| 6 | 11 | import java.io.IOException; | |
| 7 | 12 | import java.io.InputStream; | |
@@ -10,13 +15,7 @@ | |||
| 10 | 15 | import java.util.Map; | |
| 11 | 16 | import java.util.Set; | |
| 12 | 17 | ||
| 13 | - import com.github.dockerjava.api.command.BuildImageCmd; | ||
| 14 | - import com.github.dockerjava.api.model.AuthConfigurations; | ||
| 15 | - import com.github.dockerjava.api.model.BuildResponseItem; | ||
| 16 | - import com.github.dockerjava.core.dockerfile.Dockerfile; | ||
| 17 | - import com.github.dockerjava.core.util.FilePathUtil; | ||
| 18 | - | ||
| 19 | - import javax.annotation.CheckForNull; | ||
| 18 | + import static com.google.common.base.Preconditions.checkNotNull; | ||
| 20 | 19 | ||
| 21 | 20 | /** | |
| 22 | 21 | * Build an image from Dockerfile. | |
@@ -72,6 +71,8 @@ public class BuildImageCmdImpl extends AbstrAsyncDockerCmd<BuildImageCmd, BuildR | |||
| 72 | 71 | ||
| 73 | 72 | private String target; | |
| 74 | 73 | ||
| 74 | + private Set<String> extraHosts; | ||
| 75 | + | ||
| 75 | 76 | public BuildImageCmdImpl(BuildImageCmd.Exec exec) { | |
| 76 | 77 | super(exec); | |
| 77 | 78 | } | |
@@ -218,6 +219,11 @@ public Long getShmsize() { | |||
| 218 | 219 | return shmsize; | |
| 219 | 220 | } | |
| 220 | 221 | ||
| 222 | + @Override | ||
| 223 | + public Set<String> getExtraHosts() { | ||
| 224 | + return extraHosts; | ||
| 225 | + } | ||
| 226 | + | ||
| 221 | 227 | // setters | |
| 222 | 228 | ||
| 223 | 229 | /** | |
@@ -402,6 +408,12 @@ public BuildImageCmd withTarget(String target) { | |||
| 402 | 408 | return this; | |
| 403 | 409 | } | |
| 404 | 410 | ||
| 411 | + @Override | ||
| 412 | + public BuildImageCmd withExtraHosts(Set<String> extraHosts) { | ||
| 413 | + this.extraHosts = extraHosts; | ||
| 414 | + return this; | ||
| 415 | + } | ||
| 416 | + | ||
| 405 | 417 | @Override | |
| 406 | 418 | public void close() { | |
| 407 | 419 | super.close(); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -117,6 +117,10 @@ protected Void execute0(BuildImageCmd command, ResultCallback<BuildResponseItem> | |||
| 117 | 117 | webTarget = webTarget.queryParam("target", command.getTarget()); | |
| 118 | 118 | } | |
| 119 | 119 | ||
| 120 | + if (command.getExtraHosts() != null) { | ||
| 121 | + webTarget = webTarget.queryParamsSet("extrahosts", command.getExtraHosts()); | ||
| 122 | + } | ||
| 123 | + | ||
| 120 | 124 | LOGGER.trace("POST: {}", webTarget); | |
| 121 | 125 | ||
| 122 | 126 | InvocationBuilder builder = resourceWithOptionalAuthConfig(command, webTarget.request()) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -31,6 +31,7 @@ | |||
| 31 | 31 | import static com.github.dockerjava.core.RemoteApiVersion.VERSION_1_21; | |
| 32 | 32 | import static com.github.dockerjava.core.RemoteApiVersion.VERSION_1_23; | |
| 33 | 33 | import static com.github.dockerjava.core.RemoteApiVersion.VERSION_1_27; | |
| 34 | + import static com.github.dockerjava.core.RemoteApiVersion.VERSION_1_28; | ||
| 34 | 35 | import static com.github.dockerjava.junit.DockerMatchers.isGreaterOrEqual; | |
| 35 | 36 | import static org.apache.commons.io.FileUtils.writeStringToFile; | |
| 36 | 37 | import static org.hamcrest.MatcherAssert.assertThat; | |
@@ -331,6 +332,23 @@ public void quiet() { | |||
| 331 | 332 | LOG.info("Image Inspect: {}", inspectImageResponse.toString()); | |
| 332 | 333 | } | |
| 333 | 334 | ||
| 335 | + @Test | ||
| 336 | + public void extraHosts() { | ||
| 337 | + assumeThat(dockerRule, isGreaterOrEqual(VERSION_1_28)); | ||
| 338 | + | ||
| 339 | + File baseDir = fileFromBuildTestResource("labels"); | ||
| 340 | + | ||
| 341 | + String imageId = dockerRule.getClient() | ||
| 342 | + .buildImageCmd(baseDir) | ||
| 343 | + .withExtraHosts(new HashSet<>(Arrays.asList("host1"))) | ||
| 344 | + .start() | ||
| 345 | + .awaitImageId(); | ||
| 346 | + | ||
| 347 | + InspectImageResponse inspectImageResponse = dockerRule.getClient().inspectImageCmd(imageId).exec(); | ||
| 348 | + assertThat(inspectImageResponse, not(nullValue())); | ||
| 349 | + LOG.info("Image Inspect: {}", inspectImageResponse.toString()); | ||
| 350 | + } | ||
| 351 | + | ||
| 334 | 352 | public void dockerfileNotInBaseDirectory() throws Exception { | |
| 335 | 353 | File baseDirectory = fileFromBuildTestResource("dockerfileNotInBaseDirectory"); | |
| 336 | 354 | File dockerfile = fileFromBuildTestResource("dockerfileNotInBaseDirectory/dockerfileFolder/Dockerfile"); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments