Import time/tzdata (#6038)

Standard OPA images are based on cc-dynamic from Chainguard Images:

https://github.com/chainguard-images/images/blob/main/images/cc-dynamic/README.md

(now deprecated, see: https://github.com/open-policy-agent/opa/issues/6037)

This image doesn't include tzdata.

Our static images however are based on static.

https://github.com/chainguard-images/images/blob/main/images/static/README.md

This build includes tzdata:

https://github.com/chainguard-images/images/blob/main/images/static/configs/latest.apko.yaml#L8

How to see this:

```
$ docker run -it openpolicyagent/opa:0.53.1-static eval 'time.clock([time.now_ns(), "Asia/Shanghai"])'
{
  "result": [
    {
      "expressions": [
        {
          "value": [
            17,
            54,
            3
          ],
          "text": "time.clock([time.now_ns(), \"Asia/Shanghai\"])",
          "location": {
            "row": 1,
            "col": 1
          }
        }
      ]
    }
  ]
}

$ docker run -it openpolicyagent/opa:0.53.1 eval 'time.clock([time.now_ns(), "Asia/Shanghai"])'
{}
```

How to test this change:

```
make ci-build-linux ci-build-linux-static
make image-quick-amd64
docker run -it openpolicyagent/opa:0.54.0-dev eval 'time.clock([time.now_ns(), "Asia/Shanghai"])'
docker run -it openpolicyagent/opa:0.54.0-dev-static eval 'time.clock([time.now_ns(), "Asia/Shanghai"])'
```

You should see that both images provide the expected output. This shows
that `time/tzdata` is being used in the non-static image as expected.
These steps will not work as expected on main.

Signed-off-by: Charlie Egan <charlie@styra.com>
This commit is contained in:
Charlie Egan
2023-06-22 15:23:05 +01:00
committed by GitHub
parent 623b056092
commit 54d041d6b1
2 changed files with 3 additions and 1 deletions
+2 -1
View File
@@ -701,7 +701,8 @@ Timezones can be specified as
* "UTC" or "", which are equivalent to not passing a timezone (i.e. will return as UTC)
* "Local", which will use the local timezone.
Note that the opa executable will need access to the timezone files in the environment it is running in (see the [Go `time.LoadLocation()`](https://pkg.go.dev/time#LoadLocation) documentation for more information).
Note that OPA will use the `time/tzdata` data if none is present on the runtime filesystem (see the
[Go `time.LoadLocation()`](https://pkg.go.dev/time#LoadLocation) documentation for more information).
#### Timestamp Parsing
+1
View File
@@ -12,6 +12,7 @@ import (
"strconv"
"sync"
"time"
_ "time/tzdata" // this is needed to have LoadLocation when no filesystem tzdata is available
"github.com/open-policy-agent/opa/ast"
"github.com/open-policy-agent/opa/topdown/builtins"