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

Allow more timezone formats #2320

Merged
merged 7 commits into from
Mar 12, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 3 additions & 0 deletions jib-gradle-plugin/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,14 @@ All notable changes to this project will be documented in this file.

### Changed

- `jib.container.creationTime` now accepts more timezone formats:`+HHmm`. This allows for easier configuration of creationTime by external systems. ([#2320](https://github.com/GoogleContainerTools/jib/issues/2320))

### Fixed

## 2.1.0

### Added

- Additionally reads credentials from `~/.docker/.dockerconfigjson` and legacy Docker config (`~/.docker/.dockercfg`). Also searches for `$HOME/.docker/*` (in addition to current `System.get("user.home")/.docker/*`). This may help retrieve credentials, for example, on Kubernetes. ([#2260](https://github.com/GoogleContainerTools/jib/issues/2260))
- New skaffold configuration options that modify how jib's build config is presented to skaffold ([#2292](https://github.com/GoogleContainerTools/jib/pull/2292)):
- `jib.skaffold.watch.buildIncludes`: a list of build files to watch
Expand Down
3 changes: 3 additions & 0 deletions jib-maven-plugin/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,14 @@ All notable changes to this project will be documented in this file.

### Changed

- `<container><creationTime>` now accepts more timezone formats:`+HHmm`. This allows for easier configuration of creationTime by external systems. ([#2320](https://github.com/GoogleContainerTools/jib/issues/2320))

### Fixed

## 2.1.0

### Added

- Additionally reads credentials from `~/.docker/.dockerconfigjson` and legacy Docker config (`~/.docker/.dockercfg`). Also searches for `$HOME/.docker/*` (in addition to current `System.get("user.home")/.docker/*`). This may help retrieve credentials, for example, on Kubernetes. ([#2260](https://github.com/GoogleContainerTools/jib/issues/2260))
- New skaffold configuration options that modify how jib's build config is presented to skaffold ([#2292](https://github.com/GoogleContainerTools/jib/pull/2292)):
- `<watch><buildIncludes>`: a list of build files to watch
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import java.nio.file.Paths;
import java.time.Instant;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeFormatterBuilder;
import java.time.format.DateTimeParseException;
import java.util.ArrayList;
import java.util.HashSet;
Expand Down Expand Up @@ -730,9 +731,16 @@ static Instant getCreationTime(String configuredCreationTime, ProjectProperties
return Instant.now();

default:
return DateTimeFormatter.ISO_DATE_TIME.parse(configuredCreationTime, Instant::from);
DateTimeFormatter formatter =
new DateTimeFormatterBuilder()
.append(DateTimeFormatter.ISO_DATE_TIME) // parses isoStrict
// add ability to parse with no ":" in tz
.optionalStart()
.appendOffset("+HHmm", "+0000")
.optionalEnd()
.toFormatter();
return formatter.parse(configuredCreationTime, Instant::from);
chanseokoh marked this conversation as resolved.
Show resolved Hide resolved
}

} catch (DateTimeParseException ex) {
throw new InvalidCreationTimeException(configuredCreationTime, configuredCreationTime, ex);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import com.google.cloud.tools.jib.api.RegistryImage;
import com.google.cloud.tools.jib.configuration.BuildContext;
import com.google.cloud.tools.jib.configuration.ImageConfiguration;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.google.common.io.Resources;
Expand Down Expand Up @@ -908,11 +909,52 @@ public void testGetCreationTime_useCurrentTimestamp() throws InvalidCreationTime

@Test
public void testGetCreationTime_isoDateTimeValue() throws InvalidCreationTimeException {
Instant time =
PluginConfigurationProcessor.getCreationTime(
"2011-12-03T10:15:30+09:00", projectProperties);
Instant expected = DateTimeFormatter.ISO_DATE_TIME.parse("2011-12-03T01:15:30Z", Instant::from);
Assert.assertEquals(expected, time);
List<String> validTimeStamps =
ImmutableList.of(
"2011-12-03T10:15:30+09:00",
"2011-12-03T10:15:30+09:00[Asia/Tokyo]",
"2011-12-02T16:15:30-09:00",
"2011-12-03T10:15:30+0900",
"2011-12-02T16:15:30-0900",
"2011-12-03T10:15:30+09",
"2011-12-02T16:15:30-09",
"2011-12-03T01:15:30Z");
for (String timeString : validTimeStamps) {
Instant time = PluginConfigurationProcessor.getCreationTime(timeString, projectProperties);
Assert.assertEquals("for " + timeString, expected, time);
}
}

@Test
public void testGetCreationTime_isoDateTimeValueTimeZoneRegionOnlyAllowedForMostStrict8601Mode() {
List<String> invalidTimeStamps =
ImmutableList.of(
"2011-12-03T01:15:30+0900[Asia/Tokyo]", "2011-12-03T01:15:30+09[Asia/Tokyo]");
for (String timeString : invalidTimeStamps) {
try {
PluginConfigurationProcessor.getCreationTime(timeString, projectProperties);
// this is the expected behavior, not specifically designed like this for any reason, feel
// free to change this behavior and update the test
Assert.fail(
"creationTime should fail if region specified when zone not in HH:MM mode - "
chanseokoh marked this conversation as resolved.
Show resolved Hide resolved
+ timeString);
} catch (InvalidCreationTimeException ex) {
// pass
}
}
}

@Test
public void testGetCreationTime_isoDateTimeValueRequiresTimeZone() {
try {
PluginConfigurationProcessor.getCreationTime("2011-12-03T01:15:30", projectProperties);
// this is the expected behavior, not specifically designed like this for any reason, feel
// free to change this behavior and update the test
Assert.fail("getCreationTime should fail if timezone not specified");
} catch (InvalidCreationTimeException ex) {
// pass
}
}

@Test
Expand Down