bake: add unixtimestampparse function
fixes https://github.com/docker/buildx/issues/3197
Adds unixtimestampparse similar to terraform unix_timestamp_parse function.
cc @sdavids
One uses SOURCE_DATE_EPOCH as follows:
$ SOURCE_DATE_EPOCH=0 docker buildx bake
$ SOURCE_DATE_EPOCH=42 docker buildx bake
Does this PR support this use case?
SOURCE_DATE_EPOCH is used to pass a fixed timestamp from the outside into the build.
—
Having this rfc3339parse function is appreciated as well …
One uses
SOURCE_DATE_EPOCHas follows:$ SOURCE_DATE_EPOCH=0 docker buildx bake $ SOURCE_DATE_EPOCH=42 docker buildx bakeDoes this PR support this use case?
SOURCE_DATE_EPOCHis used to pass a fixed timestamp from the outside into the build.
This is already supported as a standardized environment variable
Edit: We only have docs for it in https://docs.docker.com/build/ci/github-actions/reproducible-builds/ but I think we should also have some for build and bake. Maybe in https://docs.docker.com/build/building/variables/#build-tool-configuration-variables. cc @ArthurFlag
Maybe I was not clear enough in #3197:
$ SOURCE_DATE_EPOCH=0 docker buildx bake
labels = {
"org.opencontainers.image.created" = "how do I get SOURCE_DATE_EPOCH as an RFC3339-formatted string here"
}
The label should look like "org.opencontainers.image.created"="1970-01-01T00:00:00.000Z" and not "org.opencontainers.image.created"="0"
Maybe I was not clear enough in #3197:
$ SOURCE_DATE_EPOCH=0 docker buildx bakelabels = { "org.opencontainers.image.created" = "how do I get SOURCE_DATE_EPOCH as an RFC3339-formatted string here" }The label should look like
"org.opencontainers.image.created"="1970-01-01T00:00:00.000Z"and not"org.opencontainers.image.created"="0"
Pushed extra commit to add unixtimestampparse similar to terraform unix_timestamp_parse function and update examples in docs: https://github.com/crazy-max/buildx/blob/bake-rdc339parse/docs/bake-stdlib.md#-rfc3339parse
(looks like github skipped my main review message, reposing in case it doesn't appear)
Still somewhat confused about this.
- what is the use case for
rfc4449parse? We would want to theSOURCE_DATE_EPOCHto be the source of truth that is picked up from env as that is the convention and that is already unix.
Removed rfc4449parse func and just keep unixtimestampparse one to be consistent with Terraform unix_timestamp_parse function func.
- Is returning a big struct like these new functions do some kind of convention. Can't find anything similar from current stdlib. The current convention seems to be
formatdate. If we don't want to modifyformatdateto have the capability to take date as UNIX timestamp (and maybe to return it) then would it make sense to add a new function, eg.formattimestampthat is the superset of the existing function (and then hide/deprecate the previousformatdate).
Yes I think as follow-up we could have a formattimestamp func.