Libki / libki-server

Libki Server
Other
55 stars 28 forks source link

Datetime problems #297

Open fribeiro-keeps opened 1 year ago

fribeiro-keeps commented 1 year ago

Using Libki r23.04 version with Docker and with both LIBKI_TZ and TZ variables as Europe/Lisbon, the logs datetime is 1 hour behind my actual datetime. This impacts the reserve's system, once I have to set the reservation start date to one hour in the past. Also, when the reserve popup opens, the preset hour is one hour before. I've checked the date of both Libki and DB containers and also mysql datetime. All of those are correct.

kylemhall commented 1 year ago

So the logs in the logs table are an hour behind? Are timestamps in other tables correct?

fribeiro-keeps commented 1 year ago

All tables are one hour behind. Clients, users, logs, etc...

kylemhall commented 1 year ago

How are you deploying docker? Can you run the date command from your Libki server? Does that command output the correct time?

fribeiro-keeps commented 1 year ago

Yes. The command output is Tue May 2 09:51:07 WEST 2023 and in the logs table have 2023-05-02 08:51:07

kylemhall commented 1 year ago

How are you deploying Libki? If you get into the mysql cli and run SELECT NOW() does what you get back match the logs time or the system time?

fribeiro-keeps commented 1 year ago

I'm using a Dockerfile FROM libki/libki-server:r23.04 and a docker compose to start the libki-server and mariadb containers. The SELECT NOW() matches the system time (one hour later than the logs time)

kylemhall commented 1 year ago

It certainly seems like your logs are set to UTC rather than Europe/Lisbon as you intend since you are one our ahead of UTC. Does that make sense?

If your system and database are both set to your local timezone, I would suggest your remove the timezone from your config altogether. That should make Libki default to your local timezone.

fribeiro-keeps commented 1 year ago

If only the logs were in UTC I wouldn't mind that much. The problem is that the time of reservations is also in UTC. I removed all the timezones from the docker config and the times are all in UTC. That is, a reservation for 9AM is considered as 8AM UTC.

kylemhall commented 1 year ago

@fribeiro-keeps so removing the TZ/LIBKI_TZ environment variables made no change?

When you are checking the date, are you checking it from the host server or from inside the docker container? Can you try setting TZ/LIBKI_TZ again and run date from inside the container?

kylemhall commented 1 year ago

I just tested by setting only TZ to Europe/Lisbon using the following alias:

alias libki-docker-lisbon='docker run --name libki --publish 0.0.0.0:3000:3000 --mount type=bind,source=/home/libki/repos/libki/libki-server,target=/app --network libki-net -e '\''LIBKI_INSTANCE=demo'\'' -e '\''LIBKI_DB_DSN=dbi:mysql:libki;host=libki-mariadb;port=3306'\'' -e '\''LIBKI_DB_USER=root'\'' -e '\''LIBKI_DB_PASSWORD=password'\'' -e '\''LIBKI_DB_HOST=libki-mariadb'\'' -e '\''LIBKI_DB_PORT=3306'\'' -e '\''LIBKI_DB_DATABASE=libki'\'' -e '\''TZ=Europe/Lisbon'\'' --rm -it libki/libki-server:latest bash'

Testing with this, both the system and database times matched up with your actual time in Lisbon. I'm running my Debian on my Docker host if that makes a difference. Are you using the Debian image or the Alpine image?

fribeiro-keeps commented 1 year ago

@fribeiro-keeps so removing the TZ/LIBKI_TZ environment variables made no change?

Container cmd date and SELECT NOW() were UTC instead of Europe/Lisbon. So, without any timezone environmental variables, the Libki default is UTC and not my local timezone.

When you are checking the date, are you checking it from the host server or from inside the docker container? Can you try setting TZ/LIBKI_TZ again and run date from inside the container?

I'm checking date inside the container and the output is Europe/Lisbon time.

Are you using the Debian image or the Alpine image?

I'm using Debian 11

Testing with this, both the system and database times matched up with your actual time in Lisbon.

What about the dates of logs table? Is it Lisbon time or UTC?

kylemhall commented 1 year ago

The dates in my logs table were in Lisbon time. When I checked the mysql timezone it was set to system time rather than a specific timezone.

The big difference I see is that I'm only setting TZ, and not LIBKI_TZ. Can you try only setting TZ to see if that makes a difference?

fribeiro-keeps commented 1 year ago

I'm trying only with TZ and all remains the same. The mysql timezone is set to system time. However, the tables dates are still in UTC when my date cmd is WEST.

kylemhall commented 1 year ago

Can you post your docker compose file here?

fribeiro-keeps commented 1 year ago

Here it is (added the TXT extension to upload in this comment): docker-compose.yml.txt

Thank you for your help!

kylemhall commented 1 year ago

@fribeiro-keeps I see in your compose file you reference Dockerfile.libki

Is that one of the official Dockerfiles or is it a custom Dockerfile? If so can you post it here?

fribeiro-keeps commented 1 year ago

Oh yes, sorry. It's a custom Dockerfile but only with a few packages installation. Dockerfile.libki.txt

kylemhall commented 1 year ago

Thanks! Since your dockerfile references other scripts, I used your docker-compose file with the base image from your dockerfile ( libki/libki-server:r23.04 ). Using libki/libki-server:r23.04 with your docker-compose file I was able to launch and test. For better or worse, everything lines up time wise.

I can only come to the conclusion that the issue is either something about the server you are running on, or the customization your have made to the Libki dockerfile.

Screenshot 2023-05-10 at 9 25 30 AM
fribeiro-keeps commented 1 year ago

Hey Kyle!

Just noticed that none of the docker-compose variables are available at Libki.pm when service starts. This might be related with the fact that libki service is managed by plack. If I print the variables inside the container, it's right. But if I print it inside Libki.pm, the ENV variable contains only this:

$VAR1 = {
          'LC_TIME' => '',
          'LANGUAGE' => '',
          'LC_COLLATE' => '',
          'LC_ALL' => '',
          'LC_MEASUREMENT' => '',
          'SERVER_STARTER_PORT' => '3000=5',
          'LC_NUMERIC' => '',
          'SHLVL' => '1',
          'LC_PAPER' => '',
          'PLACK_ENV' => 'production',
          'LC_NAME' => '',
          '_' => '/usr/local/bin/start_server',
          'LANG' => '',
          'LC_MONETARY' => '',
          'LC_MESSAGES' => '',
          'SERVER_STARTER_GENERATION' => '5',
          'TERM' => '',
          'LC_TELEPHONE' => '',
          'LC_IDENTIFICATION' => '',
          'LC_CTYPE' => '',
          'PWD' => '/',
          'LC_ADDRESS' => '',
          'PATH' => '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin'
        };

Is there a way to provide environmental variables to plack?