-
Notifications
You must be signed in to change notification settings - Fork 626
bake: add unixtimestampparse and formattimestamp functions #3286
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -38,8 +38,9 @@ title: Bake standard library functions | |
| | [`flatten`](#flatten) | Transforms a list, set, or tuple value into a tuple by replacing any given elements that are themselves sequences with a flattened tuple of all of the nested elements concatenated together. | | ||
| | [`floor`](#floor) | Returns the greatest whole number that is less than or equal to the given value. | | ||
| | [`format`](#format) | Constructs a string by applying formatting verbs to a series of arguments, using a similar syntax to the C function \"printf\". | | ||
| | [`formatdate`](#formatdate) | Formats a timestamp given in RFC 3339 syntax into another timestamp in some other machine-oriented time syntax, as described in the format string. | | ||
| | [`formatdate`](#formatdate) | Deprecated: use formattimestamp instead. Formats a timestamp given in RFC 3339 syntax into another timestamp in some other machine-oriented time syntax, as described in the format string. | | ||
| | [`formatlist`](#formatlist) | Constructs a list of strings by applying formatting verbs to a series of arguments, using a similar syntax to the C function \"printf\". | | ||
| | [`formattimestamp`](#formattimestamp) | Formats a timestamp string in RFC 3339 syntax or a unix timestamp integer into another timestamp in some other machine-oriented time syntax, as described in the format string. | | ||
| | [`greaterthan`](#greaterthan) | Returns true if and only if the second number is greater than the first. | | ||
| | [`greaterthanorequalto`](#greaterthanorequalto) | Returns true if and only if the second number is greater than or equal to the first. | | ||
| | [`hasindex`](#hasindex) | Returns true if if the given collection can be indexed with the given key without producing an error, or false otherwise. | | ||
|
|
@@ -104,6 +105,7 @@ title: Bake standard library functions | |
| | [`trimspace`](#trimspace) | Removes any consecutive space characters (as defined by Unicode) from the start and end of the given string. | | ||
| | [`trimsuffix`](#trimsuffix) | Removes the given suffix from the start of the given string, if present. | | ||
| | [`try`](#try) | Variadic function that tries to evaluate all of is arguments in sequence until one succeeds, in which case it returns that result, or returns an error if none of them succeed. | | ||
| | [`unixtimestampparse`](#unixtimestampparse) | Given a unix timestamp integer, will parse and return an object representation of that date and time. A unix timestamp is the number of seconds elapsed since January 1, 1970 UTC. | | ||
| | [`upper`](#upper) | Returns the given string with all Unicode letters translated to their uppercase equivalents. | | ||
| | [`urlencode`](#urlencode) | Applies URL encoding to a given string. | | ||
| | [`uuidv4`](#uuidv4) | Generates and returns a Type-4 UUID in the standard hexadecimal string format. | | ||
|
|
@@ -532,6 +534,10 @@ target "webapp-dev" { | |
|
|
||
| ## `formatdate` | ||
|
|
||
| > [!WARNING] | ||
| > Deprecated: use `formattimestamp` instead. `formatdate` only accepts RFC3339 | ||
| > timestamp strings. | ||
|
|
||
| ```hcl | ||
| # docker-bake.hcl | ||
| target "webapp-dev" { | ||
|
|
@@ -543,6 +549,28 @@ target "webapp-dev" { | |
| } | ||
| ``` | ||
|
|
||
| ## `formattimestamp` | ||
|
|
||
| Formats either an RFC3339 timestamp string or a unix timestamp integer. | ||
|
|
||
| ```hcl | ||
| # docker-bake.hcl | ||
| variable "SOURCE_DATE_EPOCH" { | ||
| type = number | ||
| default = 1690328596 | ||
| } | ||
|
|
||
| target "default" { | ||
| dockerfile = "Dockerfile" | ||
| labels = { | ||
| "org.opencontainers.image.created" = formattimestamp("YYYY-MM-DD'T'hh:mm:ssZ", SOURCE_DATE_EPOCH) # => "2023-07-25T23:43:16Z" | ||
| } | ||
| args = { | ||
| build_date = formattimestamp("YYYY-MM-DD", "2025-09-16T12:00:00Z") # => "2025-09-16" | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| ## `formatlist` | ||
|
|
||
| ```hcl | ||
|
|
@@ -1409,6 +1437,40 @@ target "webapp-dev" { | |
| } | ||
| ``` | ||
|
|
||
| ## `unixtimestampparse` | ||
|
|
||
| The returned object has the following attributes: | ||
| * `year` (Number) The year for the unix timestamp. | ||
| * `year_day` (Number) The day of the year for the unix timestamp, in the range 1-365 for non-leap years, and 1-366 in leap years. | ||
| * `day` (Number) The day of the month for the unix timestamp. | ||
| * `month` (Number) The month of the year for the unix timestamp. | ||
| * `month_name` (String) The name of the month for the unix timestamp (ex. "January"). | ||
| * `weekday` (Number) The day of the week for the unix timestamp. | ||
| * `weekday_name` (String) The name of the day for the unix timestamp (ex. "Sunday"). | ||
| * `hour` (Number) The hour within the day for the unix timestamp, in the range 0-23. | ||
| * `minute` (Number) The minute offset within the hour for the unix timestamp, in the range 0-59. | ||
| * `second` (Number) The second offset within the minute for the unix timestamp, in the range 0-59. | ||
| * `rfc3339` (String) The RFC3339 format string. | ||
| * `iso_year` (Number) The ISO 8601 year number. | ||
| * `iso_week` (Number) The ISO 8601 week number. | ||
|
|
||
| ```hcl | ||
|
Member
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. how about I'm also ok for special formatting for rfc3399 for less verbosity.
Member
Author
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. I looked at forking
Member
Author
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. Updated with new |
||
| # docker-bake.hcl | ||
| variable "SOURCE_DATE_EPOCH" { | ||
| type = number | ||
| default = 1690328596 | ||
| } | ||
|
|
||
| target "default" { | ||
| args = { | ||
| SOURCE_DATE_EPOCH = SOURCE_DATE_EPOCH | ||
| } | ||
| labels = { | ||
| "org.opencontainers.image.created" = unixtimestampparse(SOURCE_DATE_EPOCH).rfc3339 | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| ## `upper` | ||
|
|
||
| ```hcl | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.