Skip to content
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 Healthcheck to ContainerConfigurationTemplate #1217

Merged
merged 26 commits into from
Nov 30, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
a567a47
Add Healthcheck to ContainerConfigurationTemplate
TadCordle Oct 31, 2018
908765f
Merge branch 'master' of github.com:GoogleContainerTools/jib into i67…
TadCordle Nov 1, 2018
f73577c
Add tests (ImageToJsonTranslatorTest is broken)
TadCordle Nov 1, 2018
6718905
Fix all tests
TadCordle Nov 1, 2018
cea22bb
Fix weird spacing
TadCordle Nov 5, 2018
bc16229
Use TimeUnit argument
TadCordle Nov 6, 2018
40a842b
Duration
TadCordle Nov 6, 2018
8099923
Store image format on Image
TadCordle Nov 6, 2018
5f17e67
Add StartPeriod
TadCordle Nov 7, 2018
d1458ec
Merge branch 'master' of github.com:GoogleContainerTools/jib into i67…
TadCordle Nov 9, 2018
e9ed69f
Merge branch 'master' of github.com:GoogleContainerTools/jib into i67…
TadCordle Nov 9, 2018
9e590c0
Use new class
TadCordle Nov 9, 2018
72ed180
Not nullable
TadCordle Nov 12, 2018
2b63733
Feedback
TadCordle Nov 20, 2018
c0a9167
Merge branch 'master' of github.com:GoogleContainerTools/jib into i67…
TadCordle Nov 20, 2018
a73936a
Better preparation for inheriting
TadCordle Nov 20, 2018
034c20f
Add argument checks
TadCordle Nov 20, 2018
ca9982b
Update javadoc
TadCordle Nov 20, 2018
7eec75c
Remove ability to add parameters to inherited command
TadCordle Nov 26, 2018
456c316
Simplify
TadCordle Nov 27, 2018
e5d72f2
More simplifying
TadCordle Nov 28, 2018
406df93
Merge branch 'master' of github.com:GoogleContainerTools/jib into i67…
TadCordle Nov 28, 2018
064e79d
Fix leftover merge conflict
TadCordle Nov 30, 2018
63b9f21
Merge branch 'master' of github.com:GoogleContainerTools/jib into i67…
TadCordle Nov 30, 2018
de2ea7a
Feedback
TadCordle Nov 30, 2018
3c29c2f
Move empty string check to shell only
TadCordle Nov 30, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Simplify
  • Loading branch information
TadCordle committed Nov 27, 2018
commit 456c3163d5eaebccb7f9dd5a2fe93cc9c5a3f553
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ public class DockerHealthCheck {
/** Builds the immutable {@link DockerHealthCheck}. */
public static class Builder {

@Nullable private final ImmutableList<String> command;
private final ImmutableList<String> command;
@Nullable private Duration interval;
@Nullable private Duration timeout;
@Nullable private Duration startPeriod;
@Nullable private Integer retries;

private Builder(@Nullable ImmutableList<String> command) {
private Builder(ImmutableList<String> command) {
this.command = command;
}

Expand Down Expand Up @@ -106,7 +106,7 @@ public static DockerHealthCheck disabled() {
* @return the new {@link DockerHealthCheck}
*/
public static DockerHealthCheck inherited() {
return new DockerHealthCheck(null, null, null, null, null);
return new DockerHealthCheck(ImmutableList.of(), null, null, null, null);
}

/**
Expand Down Expand Up @@ -147,14 +147,14 @@ public static Builder builderWithShellCommand(String command) {
return new Builder(ImmutableList.of("CMD-SHELL", command));
}

@Nullable private final ImmutableList<String> command;
private final ImmutableList<String> command;
@Nullable private final Duration interval;
@Nullable private final Duration timeout;
@Nullable private final Duration startPeriod;
@Nullable private final Integer retries;

private DockerHealthCheck(
@Nullable ImmutableList<String> command,
ImmutableList<String> command,
@Nullable Duration interval,
@Nullable Duration timeout,
@Nullable Duration startPeriod,
Expand All @@ -172,8 +172,8 @@ private DockerHealthCheck(
*
* @return the healthcheck command
*/
public Optional<List<String>> getCommand() {
return Optional.ofNullable(command);
public List<String> getCommand() {
return command;
}

/**
Expand Down Expand Up @@ -222,6 +222,6 @@ public Optional<Integer> getRetries() {
* @return {@code true} if the health check should be inherited, {@code false} if not
*/
public boolean isInherited() {
return command == null || command.isEmpty();
return command.isEmpty();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public static class Builder<T extends Layer> {
@Nullable private Instant created;
@Nullable private ImmutableList<String> entrypoint;
@Nullable private ImmutableList<String> programArguments;
private DockerHealthCheck healthCheck = DockerHealthCheck.disabled();
private DockerHealthCheck healthCheck = DockerHealthCheck.inherited();
@Nullable private ImmutableList<Port> exposedPorts;
@Nullable private ImmutableList<AbsoluteUnixPath> volumes;
@Nullable private String workingDirectory;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ public Blob getContainerConfigurationBlob() {
// Healthcheck is not supported by OCI
TadCordle marked this conversation as resolved.
Show resolved Hide resolved
DockerHealthCheck healthCheck = image.getHealthCheck();
if (image.getImageFormat() == V22ManifestTemplate.class) {
template.setContainerHealthTest(healthCheck.getCommand().orElse(ImmutableList.of()));
template.setContainerHealthTest(healthCheck.getCommand());
healthCheck
.getInterval()
.ifPresent(interval -> template.setContainerHealthInterval(interval.toNanos()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,39 +47,33 @@ public void testBuild_parameters() {
@Test
public void testBuild_propagated() {
DockerHealthCheck healthCheck = DockerHealthCheck.inherited();
Assert.assertFalse(healthCheck.getCommand().isPresent());
Assert.assertTrue(healthCheck.isInherited());
}

@Test
public void testBuild_execArray() {
DockerHealthCheck healthCheck =
DockerHealthCheck.builderWithExecCommand("test", "command").build();
Assert.assertTrue(healthCheck.getCommand().isPresent());
Assert.assertEquals(ImmutableList.of("CMD", "test", "command"), healthCheck.getCommand().get());
Assert.assertEquals(ImmutableList.of("CMD", "test", "command"), healthCheck.getCommand());
}

@Test
public void testBuild_execList() {
DockerHealthCheck healthCheck =
DockerHealthCheck.builderWithExecCommand(ImmutableList.of("test", "command")).build();
Assert.assertTrue(healthCheck.getCommand().isPresent());
Assert.assertEquals(ImmutableList.of("CMD", "test", "command"), healthCheck.getCommand().get());
Assert.assertEquals(ImmutableList.of("CMD", "test", "command"), healthCheck.getCommand());
}

@Test
public void testBuild_shell() {
DockerHealthCheck healthCheck =
DockerHealthCheck.builderWithShellCommand("shell command").build();
Assert.assertTrue(healthCheck.getCommand().isPresent());
Assert.assertEquals(
ImmutableList.of("CMD-SHELL", "shell command"), healthCheck.getCommand().get());
Assert.assertEquals(ImmutableList.of("CMD-SHELL", "shell command"), healthCheck.getCommand());
}

@Test
public void testDisabled() {
DockerHealthCheck healthCheck = DockerHealthCheck.disabled();
Assert.assertTrue(healthCheck.getCommand().isPresent());
Assert.assertEquals(ImmutableList.of("NONE"), healthCheck.getCommand().get());
Assert.assertEquals(ImmutableList.of("NONE"), healthCheck.getCommand());
}
}