This project provides a simple time-server that returns the current UTC time when a client connects to it. It allows to convert the time to a different time zone (using the Olsen format) if one is specified. It is useful for testing purposes only and should not be used in production environments.
The server is implemented using Spring-Boot and provides a REST API to retrieve the current time:
-
/api/time
returns the current UTC time. -
/api/time?timeZone={zone}
returns the current time in the specified time zone. The time zone must be specified using the Olsen format.
The most relevant features tested are:
- It is configured to execute the CI/CD pipeline using GitHub Actions.
- It contains a Dockerfile to build a Docker image and deploy it to a Docker registry.
- Maven is used to build the project, generate the JAR file and the Docker image, and deploy the JAR file to Maven Central and the Docker image to a Docker registry.
The project can be built using Maven 3.6.3 or higher and Java 17 or higher. Executing the following command will
generate a self-contained JAR file in the target
directory:
mvn clean package
The project also provides a Dockerfile to build a Docker image. The image can be built using Maven and
deployed to a Docker registry. Currently only docker.io
is supported, but you can easily change it by modifying the
docker.url
property in the pom.xml
file. You also need to provide the credentials to access the registry. You can
do it by setting the DOCKER_HUB_USERNAME
and DOCKER_HUB_TOKEN
properties in the settings.xml
file or by setting
environment variables with the same name.
The following command will build the JAR file and the Docker image, and deploy them to Maven Central and the Docker registry:
mvn clean package source:jar javadoc:jar install deploy
Using the self-contained JAR file is the simplest way to run the server. You only need to execute the following command:
java -jar time-server-<version>.jar
If you prefer to use Docker, you can run the server using the following command:
docker pull dattack/time-server:<version>
docker run -p 8080:8080 dattack/time-server:<version>
Code is under the Apache Licence v2.