DEV Community

Yasuhiro Matsuda
Yasuhiro Matsuda

Posted on

AWS Fargateを利用した時刻固定したシステムテストの方法について

この記事は先日英語版で投稿したHow to system test with fixed time on Fargateの日本語訳です。

AWS Fargateでの時刻を固定したシステムテストをどのように実現していますか?

aws ecs execute-commandを使用してコンテナにログインし、dateコマンドを使用して時刻を変更しようとしても、AWS Fargateでは特権コンテナがサポートされていないため、次のエラーが発生して変更することができません。

date: cannot set date: Operation not permitted

ところが、libfaketime を使用するとシステム時刻を調整することができます。
バージョンは古いですが、Keycloak 19.0.2のイメージで検証したDockerfileを以下に示します。

FROM quay.io/keycloak/keycloak:19.0.2 AS builder

USER root

RUN microdnf install -y git make gcc
RUN git clone https://github.com/wolfcw/libfaketime.git
WORKDIR /libfaketime/src
RUN make install
ENV LD_PRELOAD=/usr/local/lib/faketime/libfaketime.so.1

ENV FAKETIME="2025-04-24 10:30:00"
RUN date

WORKDIR /opt/keycloak

ENTRYPOINT [ "/opt/keycloak/bin/kc.sh" ]
Enter fullscreen mode Exit fullscreen mode

上記で作成されたイメージから実行されたコンテナに以下のように入ってdateコマンドを実行すると、FAKETIME変数で指定した値が固定されていることがわかります。

% aws ecs execute-command --cluster _clustername_ --task _taskID_ --interactive --command "/bin/bash"

The Session Manager plugin was installed successfully. Use the AWS CLI to start a session.

Starting session with SessionId: ecs-execute-command-xxxxxxxxx
[root@ip-NNN-NNN-NNN-NNN keycloak]# date
Thu Apr 24 10:30:00 UTC 2025
Enter fullscreen mode Exit fullscreen mode

ぜひ試してみてください。

Top comments (0)

Image of Docusign

🛠️ Bring your solution into Docusign. Reach over 1.6M customers.

Docusign is now extensible. Overcome challenges with disconnected products and inaccessible data by bringing your solutions into Docusign and publishing to 1.6M customers in the App Center.

Learn more