langgenius / dify-sandbox

A lightweight, fast, and secure code execution environment that supports multiple programming languages
https://docs.dify.ai/development/backend/sandbox
Apache License 2.0
434 stars 97 forks source link

how to change the default time zone #50

Closed lordk911 closed 2 months ago

lordk911 commented 2 months ago

when : image

it will use the default UTC timezone

when : image

will got error:operation not permitted

lordk911 commented 2 months ago

I deploy dify use k8s helm : https://github.com/douban/charts/tree/master/charts/dify

I've set the sandbox container env:

- name: TZ
      value: "Asia/Shanghai"

and go into the container:

image

But why In dify when exec code in python it still use UTC timezone

lordk911 commented 2 months ago

1、go into the containser anf exec : ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime , can work it out

Yeuoly commented 2 months ago

Thanks so much for reporting this, I have fixed it.

sknightq commented 1 month ago

@Yeuoly I set the TZ environment in dockerfile,but still not work. In dockerfile

# 设置时区为上海
ENV TZ=Asia/Shanghai

RUN rm -rf /var/lib/apt/lists/* \
    && chmod +x /main \
    && chmod +x /env \
    && pip3 install jinja2 requests httpx PySocks httpx[socks] \
    && wget -O /opt/node-v20.11.1-linux-x64.tar.xz https://npmmirror.com/mirrors/node/v20.11.1/node-v20.11.1-linux-x64.tar.xz \
    && tar -xvf /opt/node-v20.11.1-linux-x64.tar.xz -C /opt \
    && ln -s /opt/node-v20.11.1-linux-x64/bin/node /usr/local/bin/node \
    && rm -f /opt/node-v20.11.1-linux-x64.tar.xz \
    && /env \
    && rm -f /env \
    && ln -fs /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \
    && echo Asia/Shanghai > /etc/timezone \
    && dpkg-reconfigure --frontend noninteractive tzdata \
    && rm -rf /var/lib/apt/lists/*

My Code Request:

// request
{
    "language":"nodejs",
    "code":"console.log(new Date('2024-10-03 15:26:49').getTime())"
}
// response
{
    "code": 200,
    "message": "success",
    "data": {
        "error": "",
        "stdout": "1727969209000\n"
    }
}
// console.log(new Date(1727969209000)) // Thu Oct 03 2024 23:26:49 GMT+0800 (China Standard Time)