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

bake: add timestamp function #1214

Merged
merged 1 commit into from
Aug 1, 2022
Merged

Conversation

jedevc
Copy link
Collaborator

@jedevc jedevc commented Jul 18, 2022

Fix #1201.

Terraform includes a timestamp function to get the current time. go-cty has imported a number of the timestamp functions to it's standard library in zclconf/go-cty#37, however, this was one was not included:

All but one of the "impure" functions fit into the cryptographic and filesystem categories I covered already anyway. The remaining one is timestamp, and I think it would be overkill to establish a new codebase just for that so maybe again it's sufficient to just copy-paste it into another application that needs it, as long as that application is prepared to deal with a function that doesn't return a stable result.

The result isn't fully stable, but user's should expect that, and can assign the result to a top-level variable and use that as a consistent timestamp throughout the file.

Terraform includes a timestamp function to get the current time. go-cty
has imported a number of the timestamp functions to it's standard
library, however, this was one was not included.

This patch simply pulls in the TimestampFunc from Terraform's
internal/lang/funcs/datetime.go to allow easily fetching the current
time in bake.

Signed-off-by: Justin Chadwell <[email protected]>
Copy link
Member

@crazy-max crazy-max left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SGTM

@tonistiigi
Copy link
Member

Shouldn't a "timestamp" be a number?

@crazy-max
Copy link
Member

Shouldn't a "timestamp" be a number?

Strictly speaking I agree, but terraform returns a UTC timestamp string in RFC 3339 format: https://www.terraform.io/language/functions/timestamp

@jedevc
Copy link
Collaborator Author

jedevc commented Jul 21, 2022

Personally I'd rather keep consistency with how terraform does this (since we also import a bunch of functions from their stdlib). But I do agree, I think as a variable would make more sense (even if it's not a number, but a RFC 3339 string).

@tonistiigi tonistiigi merged commit 19641ec into docker:master Aug 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

bake-hcl: add function to access current time / build time
3 participants