Skip to content

Commit

Permalink
Merge pull request #663 from gemini-hlsw/navigate-ui-package
Browse files Browse the repository at this point in the history
Use navigate-ui package
  • Loading branch information
hugo-vrijswijk authored Sep 6, 2024
2 parents 32fc769 + e153c1d commit 26f3340
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 23 deletions.
2 changes: 1 addition & 1 deletion .scalafix.conf
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
include ".scalafix-common.conf"
OrganizeImports.removeUnused = false
OrganizeImports.removeUnused = true
4 changes: 0 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,6 @@ deploy_navigate_server/docker:publishLocal

# Running in Test and Production

## Composing

The `noirlab/gpp-nav` image must be composed with the images from [`navigate-ui`](https://github.com/gemini-hlsw/navigate-ui) and its server in order to run. Also, a shared volume will be needed for `navigate-server` to be able to server the static files from `navigate-ui`.

## Configuration

Deployment needs configuration that can be shared in the repos, like the TLS certificate and its key. For this, the server expects a directory called `conf/local` to be mounted in the container. A local directory must be [bind mounted](https://docs.docker.com/storage/bind-mounts/) into the container, providing a local `app.conf` and other needed files.
Expand Down
7 changes: 3 additions & 4 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,8 @@ lazy val navigate_web_server = project
Http4sCirce,
GrackleRoutes,
Natchez,
LucumaSchemas
LucumaSchemas,
NavigateUi
) ++
Http4sClient ++ Http4s ++ PureConfig ++ Logging.value ++ MUnit.value ++ Grackle.value,
// Supports launching the server in the background
Expand All @@ -146,9 +147,7 @@ lazy val navigate_web_server = project
buildInfoKeys ++= Seq[BuildInfoKey](name, version, buildInfoBuildNumber),
buildInfoOptions += BuildInfoOption.BuildTime,
buildInfoObject := "OcsBuildInfo",
buildInfoPackage := "navigate.web.server",
// Make UI available in development mode, as long as navigate-ui is in a sibling directory.
javaOptions += "-Dnavigate.ui.path=../../../../navigate-ui"
buildInfoPackage := "navigate.web.server"
)
.dependsOn(navigate_server)
.dependsOn(navigate_model % "compile->compile;test->test")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import cats.effect.Sync
import cats.syntax.all.*
import fs2.compression.Compression
import fs2.io.file.Files
import fs2.io.file.Path
import org.http4s.CacheDirective.*
import org.http4s.Header
import org.http4s.HttpRoutes
Expand All @@ -23,7 +22,7 @@ import org.http4s.server.middleware.GZip
import scala.concurrent.duration.*

class StaticRoutes[F[_]: Sync: Compression: Files]:
private val DistDir: String = "dist"
private val NavigateUiBase = "/navigate-ui"

private val OneYear: Int = 365 * 24 * 60 * 60 // One year in seconds

Expand All @@ -32,13 +31,7 @@ class StaticRoutes[F[_]: Sync: Compression: Files]:
)

def localFile(path: String, req: Request[F]): OptionT[F, Response[F]] =
OptionT
.liftF(uiBaseDir)
.flatMap: dir =>
StaticFile.fromPath(
Path.fromNioPath(dir.resolve(DistDir).resolve(path.stripPrefix("/"))),
req.some
)
StaticFile.fromResource(NavigateUiBase + path, Some(req))

extension (req: Request[F])
def endsWith(exts: String*): Boolean = exts.exists(req.pathInfo.toString.endsWith)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,3 @@ def baseDir[F[_]: Sync]: F[Path] = Sync[F].delay:
val appPath =
Paths.get(this.getClass.getProtectionDomain.getCodeSource.getLocation.toURI).getParent.getParent
if (Files.exists(appPath)) appPath else Paths.get(System.getProperty("user.home"))

def uiBaseDir[F[_]: Sync]: F[Path] =
Sync[F]
.delay(Paths.get(System.getProperty("navigate.ui.path")))
.handleErrorWith(_ => baseDir[F])
3 changes: 3 additions & 0 deletions project/Settings.scala
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ object Settings {
// Lucuma
val lucumaCore = "0.104.0"
val lucumaSchemas = "0.96.0"
val navigateUi = "0.1.2"

val grackle = "0.18.1"

Expand Down Expand Up @@ -176,6 +177,8 @@ object Settings {
)
val LucumaSchemas = "edu.gemini" %% "lucuma-schemas" % LibraryVersions.lucumaSchemas

val NavigateUi = "edu.gemini" % "navigate-ui" % LibraryVersions.navigateUi

val Grackle = Def.setting(
Seq(
"org.typelevel" %% "grackle-core" % LibraryVersions.grackle,
Expand Down

0 comments on commit 26f3340

Please sign in to comment.