AWS
CircleCI
timezone

CircleCIでタイムゾーン変更

More than 1 year has passed since last update.


Why

タイムゾーンがサーバとDBで違う場合にCircleCIでのテスト環境を揃えたい


What


  • サーバがAsia/Tokyo

  • DBがUTC

AWSのEC2/RDSを使ってるとよくある構成(RDSも最近はTZ設定できるけど)


How


circle.yml

machine:

timezone:
Asia/Tokyo
database:
pre:
- mysql -e "system date; show variables like '%time_zone%'; select now();"
- mysql -e "set GLOBAL time_zone = '+00:00';"
- mysql -e "system date; show variables like '%time_zone%'; select now();"


Result

$ mysql -e "system date; show variables like '%time_zone%'; select now();"

Tue Jan 24 20:32:47 JST 2017
+------------------+--------+
| Variable_name | Value |
+------------------+--------+
| system_time_zone | JST |
| time_zone | SYSTEM |
+------------------+--------+
+---------------------+
| now() |
+---------------------+
| 2017-01-24 20:32:47 |
+---------------------+

$ mysql -e "set GLOBAL time_zone = '+00:00';"

$ mysql -e "system date; show variables like '%time_zone%'; select now();"
Tue Jan 24 20:32:51 JST 2017
+------------------+--------+
| Variable_name | Value |
+------------------+--------+
| system_time_zone | JST |
| time_zone | +00:00 |
+------------------+--------+
+---------------------+
| now() |
+---------------------+
| 2017-01-24 11:32:51 |
+---------------------+