diff --git a/build.sbt b/build.sbt index 0bfbee98..4584918b 100644 --- a/build.sbt +++ b/build.sbt @@ -198,6 +198,10 @@ lazy val http4sCommons = project Dependencies.http4sServer ++ Dependencies.tapirHttp4sServer ) + .dependsOn( + commons % "compile->compile;test->test", + http4sBorer % "compile->compile;test->test" + ) lazy val redisClient = project .in(file("modules/redis-client")) diff --git a/flake.nix b/flake.nix index 900bd648..b040580d 100644 --- a/flake.nix +++ b/flake.nix @@ -77,7 +77,7 @@ container = pkgs.mkShellNoCC (queueNameConfig // { RS_SOLR_HOST = "rsdev-cnt"; - RS_SOLR_URL = "http://rsdev-cnt:8983/solr"; + RS_SOLR_URL = "http://rsdev-cnt:8983"; RS_SOLR_CORE = "rsdev-test"; RS_REDIS_HOST = "rsdev-cnt"; RS_REDIS_PORT = "6379"; @@ -102,7 +102,7 @@ // { RS_SOLR_HOST = "localhost"; RS_SOLR_PORT = "18983"; - RS_SOLR_URL = "http://localhost:18983/solr"; + RS_SOLR_URL = "http://localhost:18983"; RS_SOLR_CORE = "rsdev-test"; RS_REDIS_HOST = "localhost"; RS_REDIS_PORT = "16379"; diff --git a/modules/commons/src/main/scala/io/renku/search/common/CurrentVersion.scala b/modules/commons/src/main/scala/io/renku/search/common/CurrentVersion.scala new file mode 100644 index 00000000..884414e1 --- /dev/null +++ b/modules/commons/src/main/scala/io/renku/search/common/CurrentVersion.scala @@ -0,0 +1,42 @@ +/* + * Copyright 2024 Swiss Data Science Center (SDSC) + * A partnership between École Polytechnique Fédérale de Lausanne (EPFL) and + * Eidgenössische Technische Hochschule Zürich (ETHZ). + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.renku.search.common + +import io.bullet.borer.Decoder +import io.bullet.borer.Encoder +import io.bullet.borer.derivation.MapBasedCodecs + +final case class CurrentVersion( + name: String, + version: String, + headCommit: String, + describedVersion: String +) + +object CurrentVersion: + + given Encoder[CurrentVersion] = MapBasedCodecs.deriveEncoder + given Decoder[CurrentVersion] = MapBasedCodecs.deriveDecoder + + lazy val get: CurrentVersion = CurrentVersion( + name = "renku-search", + version = io.renku.search.BuildInfo.version, + headCommit = io.renku.search.BuildInfo.gitHeadCommit.getOrElse(""), + describedVersion = io.renku.search.BuildInfo.gitDescribedVersion.getOrElse("") + ) diff --git a/modules/http4s-commons/src/main/scala/io/renku/search/http/routes/OperationRoutes.scala b/modules/http4s-commons/src/main/scala/io/renku/search/http/routes/OperationRoutes.scala index 88b1a3e0..3e71e03d 100644 --- a/modules/http4s-commons/src/main/scala/io/renku/search/http/routes/OperationRoutes.scala +++ b/modules/http4s-commons/src/main/scala/io/renku/search/http/routes/OperationRoutes.scala @@ -23,8 +23,10 @@ import cats.syntax.all.* import org.http4s.HttpRoutes import sttp.tapir.* import sttp.tapir.server.http4s.Http4sServerInterpreter +import io.renku.search.common.CurrentVersion +import io.renku.search.http.borer.TapirBorerJson -object OperationRoutes { +object OperationRoutes extends TapirBorerJson { private def pingEndpoint[F[_]: Async] = endpoint.get .in("ping") @@ -32,6 +34,15 @@ object OperationRoutes { .description("Ping") .serverLogic[F](_ => "pong".asRight[Unit].pure[F]) + + private given Schema[CurrentVersion] = Schema.derived + + private def versionEndpoint[F[_]: Async] = + endpoint.get.in("version") + .out(borerJsonBody[CurrentVersion]) + .description("Return version information") + .serverLogicSuccess[F](_ => CurrentVersion.get.pure[F]) + def apply[F[_]: Async]: HttpRoutes[F] = - Http4sServerInterpreter[F]().toRoutes(List(pingEndpoint)) + Http4sServerInterpreter[F]().toRoutes(List(pingEndpoint, versionEndpoint)) }