-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add core 'ports' functionality to docker context exporter, fix cross-platform Dockerfile write inconsistency #438
Merged
Merged
Changes from 19 commits
Commits
Show all changes
36 commits
Select commit
Hold shift + click to select a range
0b82cf6
Add core changes for exposed port configuration
TadCordle dd44f8b
Update integration tests
TadCordle fcfa21a
Javadoc
TadCordle 39c34a4
Merge branch 'master' of github.com:GoogleContainerTools/jib into add…
TadCordle ac8d674
Merge branch 'master' of github.com:GoogleContainerTools/jib into add…
TadCordle 218bce1
Feedback
TadCordle 5e68c1b
Add core exportPorts functionality to docker context exporter
TadCordle d60d7eb
Remove EmptyStruct
TadCordle 6b7fba5
Feedback
TadCordle fefd342
Add support for udp
TadCordle 7fa64bb
Use builders and expand imports
TadCordle a71e7bb
i m p o r t s
TadCordle 519d720
Merge branch 'add_ports_config' of github.com:GoogleContainerTools/ji…
TadCordle 901c7d8
Feedback/protocol test
TadCordle cc25cd4
Use regex for splitting
TadCordle 7c6f7f1
Stray newline stuff
TadCordle d2ab9d8
Merge branch 'add_ports_config' of github.com:GoogleContainerTools/ji…
TadCordle c13c6c2
Merge branch 'master' of github.com:GoogleContainerTools/jib into por…
TadCordle bfec9bd
?
TadCordle fb2fc0b
??
TadCordle c8dc74d
Try generating dockerfile from string instead of template file
TadCordle 1a71919
Try specifying carriage return
TadCordle ddf8336
Revert "Try specifying carriage return"
TadCordle aab244a
Revert "Try generating dockerfile from string instead of template file"
TadCordle 964d85a
testing
TadCordle 9185594
Try another thing
TadCordle da15400
hm
TadCordle 165a0d3
maybe
TadCordle 213d32c
Try reading/writing line by line
TadCordle 8036cb3
Consolidate joinAsJsonArray
TadCordle 0324e2a
Remove template, cleanup
TadCordle a0aed3d
Add javadoc example for makeDockerfile()
TadCordle 0c550c8
Use ObjectMapper
TadCordle 5c19ef5
Remove one line function
TadCordle b68aebb
Move makeExposeInstructions to makeDockerfile
TadCordle b9bd25a
Merge branch 'master' of github.com:GoogleContainerTools/jib into por…
TadCordle File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,6 +31,7 @@ | |
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.regex.Matcher; | ||
import java.util.stream.Collectors; | ||
import javax.annotation.Nullable; | ||
|
||
/** | ||
|
@@ -46,12 +47,53 @@ | |
*/ | ||
public class DockerContextGenerator { | ||
|
||
/** | ||
* Formats a list for the Dockerfile's ENTRYPOINT or CMD. | ||
* | ||
* @see <a | ||
* href="https://docs.docker.com/engine/reference/builder/#exec-form-entrypoint-example">https://docs.docker.com/engine/reference/builder/#exec-form-entrypoint-example</a> | ||
* @param items the list of items to join into an array. | ||
* @return a string in the format: ["item1","item2",...] | ||
*/ | ||
@VisibleForTesting | ||
static String joinAsJsonArray(List<String> items) { | ||
StringBuilder resultString = new StringBuilder("["); | ||
boolean firstComponent = true; | ||
for (String item : items) { | ||
if (!firstComponent) { | ||
resultString.append(','); | ||
} | ||
|
||
// Escapes quotes. | ||
item = item.replaceAll("\"", Matcher.quoteReplacement("\\\"")); | ||
|
||
resultString.append('"').append(item).append('"'); | ||
firstComponent = false; | ||
} | ||
resultString.append(']'); | ||
|
||
return resultString.toString(); | ||
} | ||
|
||
/** | ||
* Builds a list of Dockerfile "EXPOSE" instructions. | ||
* | ||
* @param exposedPorts the list of ports numbers/ranges to expose | ||
* @return a string containing an EXPOSE instruction for each of the entries | ||
*/ | ||
@VisibleForTesting | ||
static String makeExposeItems(List<String> exposedPorts) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
return String.join( | ||
"\n", exposedPorts.stream().map(port -> "EXPOSE " + port).collect(Collectors.toList())); | ||
} | ||
|
||
private final SourceFilesConfiguration sourceFilesConfiguration; | ||
|
||
@Nullable private String baseImage; | ||
private List<String> jvmFlags = Collections.emptyList(); | ||
private String mainClass = ""; | ||
private List<String> javaArguments = Collections.emptyList(); | ||
private List<String> exposedPorts = Collections.emptyList(); | ||
|
||
public DockerContextGenerator(SourceFilesConfiguration sourceFilesConfiguration) { | ||
this.sourceFilesConfiguration = sourceFilesConfiguration; | ||
|
@@ -102,6 +144,17 @@ public DockerContextGenerator setJavaArguments(List<String> javaArguments) { | |
return this; | ||
} | ||
|
||
/** | ||
* Sets the exposed ports. | ||
* | ||
* @param exposedPorts the list of port numbers/port ranges to expose | ||
* @return this | ||
*/ | ||
public DockerContextGenerator setExposedPorts(List<String> exposedPorts) { | ||
this.exposedPorts = exposedPorts; | ||
return this; | ||
} | ||
|
||
/** | ||
* Creates the Docker context in {@code #targetDirectory}. | ||
* | ||
|
@@ -159,38 +212,11 @@ String makeDockerfile() throws IOException { | |
"@@DEPENDENCIES_PATH_ON_IMAGE@@", sourceFilesConfiguration.getDependenciesPathOnImage()) | ||
.replace("@@RESOURCES_PATH_ON_IMAGE@@", sourceFilesConfiguration.getResourcesPathOnImage()) | ||
.replace("@@CLASSES_PATH_ON_IMAGE@@", sourceFilesConfiguration.getClassesPathOnImage()) | ||
.replace("@@EXPOSE_INSTRUCTIONS@@", makeExposeItems(exposedPorts)) | ||
.replace( | ||
"@@ENTRYPOINT@@", | ||
joinAsJsonArray( | ||
EntrypointBuilder.makeEntrypoint(sourceFilesConfiguration, jvmFlags, mainClass))) | ||
.replace("@@CMD@@", joinAsJsonArray(javaArguments)); | ||
} | ||
|
||
/** | ||
* Formats a list for the Dockerfile's ENTRYPOINT or CMD. | ||
* | ||
* @see <a | ||
* href="https://docs.docker.com/engine/reference/builder/#exec-form-entrypoint-example">https://docs.docker.com/engine/reference/builder/#exec-form-entrypoint-example</a> | ||
* @param items the list of items to join into an array. | ||
* @return a string in the format: ["item1","item2",...] | ||
*/ | ||
@VisibleForTesting | ||
static String joinAsJsonArray(List<String> items) { | ||
StringBuilder resultString = new StringBuilder("["); | ||
boolean firstComponent = true; | ||
for (String item : items) { | ||
if (!firstComponent) { | ||
resultString.append(','); | ||
} | ||
|
||
// Escapes quotes. | ||
item = item.replaceAll("\"", Matcher.quoteReplacement("\\\"")); | ||
|
||
resultString.append('"').append(item).append('"'); | ||
firstComponent = false; | ||
} | ||
resultString.append(']'); | ||
|
||
return resultString.toString(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doing a join would avoid this
first
logic: