Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Anon patch #178

Merged
merged 2 commits into from
Dec 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
.bloop
.bsp
.sbt
.vscode
*.gch
.cache
target
Expand All @@ -16,3 +17,5 @@ frontend-build/node_modules
node_modules
.idea
postgres-data

.history
1 change: 1 addition & 0 deletions .sbtopts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
-J-Xmx4g
12 changes: 12 additions & 0 deletions .scalafix.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
OrganizeImports {
coalesceToWildcardImportThreshold = 3 # Int.MaxValue
expandRelative = false
groupExplicitlyImportedImplicitsSeparately = false
groupedImports = Explode
groups = ["re:javax?\\.", "scala.", "*"]
importSelectorsOrder = Ascii
importsOrder = Ascii
removeUnused = false
}
OrganizeImports.targetDialect = Scala3
OrganizeImports.removeUnused = true
17 changes: 15 additions & 2 deletions .scalafmt.conf
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
version = "3.8.3"

runner.dialect = scala3
rewrite.scala3.insertEndMarkerMinLines = 10
rewrite.scala3.removeOptionalBraces = true
Expand All @@ -9,9 +10,21 @@ fileOverride {
"glob:**.sbt" {
runner.dialect = scala212source3
}

"glob:**/project/**.*" {
"glob:**/project/*.scala" {
runner.dialect = scala212source3
}

"glob:**/project/plugins.sbt" {
runner.dialect = scala212source3
newlines.topLevelStatementBlankLines = [
{
blanks = 1,
minBreaks = 0
}
]
}
}

rewrite {
trailingCommas.style = "always"
}
11 changes: 7 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ This is a full-stack Scala application (job posting board), made with the follow
The app used to be deployed on

1. Platform.sh but I've run out of the free trial plan
2. Heroku but they discontinued the free flans for everyone
2. Heroku but they discontinued the free plans for everyone

and now the app is deployed to the lovely Fly.io and here's the [**live version**](https://jobby-web.fly.dev/)

Expand All @@ -30,10 +30,11 @@ It's a companion repo for my [4-part blog post series](https://blog.indoorvivant
Easiest way to run it is:

```
docker run -p 5432:5432 -e POSTGRES_PASSWORD=mysecretpassword -e POSTGRES_DB=jobby -d postgres
docker run --name jobby -p 5439:5432 -e POSTGRES_USER=jobby -e POSTGRES_PASSWORD=mysecretpassword -e POSTGRES_DB=jobby -d postgres

```

Take note of the password (`mysecretpassword`) and database (`jobby`), you will need to configure the app .
Take note of the user, password, database (`jobby`) and host port (`5439`), if you wish to reconfigure the connection .

### Running

Expand All @@ -52,9 +53,11 @@ The following settings are respected, and can be either be set as environment va
deployments), or read from the `jobby.opts` file at the root of the project, for example:

```properties
PG_USER=jobby
PG_PASSWORD=mysecretpassword
PG_DB=jobby
LOCAL_DEPLOYMENT=true
PG_PORT=5439
```

* `PG_PASSWORD`, `PG_HOST`, `PG_DB`, `PG_USER`, `PG_PORT` - variables to configure access to Postgres
Expand Down Expand Up @@ -98,4 +101,4 @@ b) Run Vite's development server:
```

And (3) is achieved by the configuration in `frontend-build/vite.config.js`. **Make sure to start
the server on port 9999**
the server on port 9999**
115 changes: 75 additions & 40 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -1,28 +1,27 @@
import org.scalajs.linker.interface.Report
import org.scalajs.linker.interface.ModuleSplitStyle
import org.scalajs.linker.interface.{ModuleSplitStyle, Report}
import smithy4s.codegen.Smithy4sCodegenPlugin

Global / onChangedBuildSource := ReloadOnSourceChanges

val Versions = new {
val http4sBlaze = "0.23.14"
val http4s = "0.23.18"
val Scala = "3.3.4"
val skunk = "0.5.1"
val upickle = "2.0.0"
val scribe = "3.11.1"
val Scala = "3.6.2"
val skunk = "1.0.0-M8"
val upickle = "3.1.4"
val scribe = "3.15.2"
val http4sDom = "0.2.7"
val jwt = "9.2.0"
val Flyway = "9.22.3"
val jwt = "10.0.1"
val FlywayPG = "11.0.1"
val Postgres = "42.7.4"
val TestContainers = "0.41.4"
val Weaver = "0.8.4"
val WeaverPlaywright = "0.0.5"
val Laminar = "15.0.1"
val waypoint = "6.0.0"
val Laminar = "17.2.0"
val waypoint = "9.0.0"
val scalacss = "1.0.0"
val monocle = "3.2.0"
val circe = "0.14.5"
val circe = "0.14.10"
val macroTaskExecutor = "1.1.1"
}

Expand Down Expand Up @@ -53,21 +52,21 @@ lazy val app = projectMatrix
dockerBaseImage := Config.DockerBaseImage,
Docker / packageName := Config.DockerImageName,
libraryDependencies ++= Seq(
"org.http4s" %% "http4s-blaze-server" % Versions.http4sBlaze,
"org.http4s" %% "http4s-ember-server" % Versions.http4s,
"org.postgresql" % "postgresql" % Versions.Postgres,
"org.flywaydb" % "flyway-core" % Versions.Flyway
"org.http4s" %% "http4s-blaze-server" % Versions.http4sBlaze,
"org.http4s" %% "http4s-ember-server" % Versions.http4s,
"org.postgresql" % "postgresql" % Versions.Postgres,
"org.flywaydb" % "flyway-database-postgresql" % Versions.FlywayPG,
),
Compile / resourceGenerators += {
Def.task[Seq[File]] {
copyAll(
frontendBundle.value,
(Compile / resourceManaged).value / "assets"
(Compile / resourceManaged).value / "assets",
)
}
},
reStart / baseDirectory := (ThisBuild / baseDirectory).value,
run / baseDirectory := (ThisBuild / baseDirectory).value
run / baseDirectory := (ThisBuild / baseDirectory).value,
)

def copyAll(location: File, outDir: File) = {
Expand All @@ -81,23 +80,28 @@ def copyAll(location: File, outDir: File) = {
}
}

val scalacSettings = Seq(
scalacOptions += "-Wunused:all",
)

lazy val backend = projectMatrix
.in(file("modules/backend"))
.dependsOn(shared)
.defaultAxes(defaults*)
.jvmPlatform(Seq(Versions.Scala))
.settings(
scalaVersion := Versions.Scala,
scalaVersion := Versions.Scala,
scalacSettings,
Compile / doc / sources := Seq.empty,
libraryDependencies ++= Seq(
("com.disneystreaming.smithy4s" %% "smithy4s-http4s" % smithy4sVersion.value),
"com.disneystreaming.smithy4s" %% "smithy4s-http4s" % smithy4sVersion.value,
"com.disneystreaming.smithy4s" %% "smithy4s-http4s-swagger" % smithy4sVersion.value,
"com.github.jwt-scala" %% "jwt-upickle" % Versions.jwt,
"com.lihaoyi" %% "upickle" % Versions.upickle,
"com.outr" %% "scribe" % Versions.scribe,
"com.outr" %% "scribe-cats" % Versions.scribe,
"com.outr" %% "scribe-slf4j" % Versions.scribe,
"org.tpolecat" %% "skunk-core" % Versions.skunk
"org.tpolecat" %% "skunk-core" % Versions.skunk,
),
libraryDependencies ++=
Seq(
Expand All @@ -110,7 +114,7 @@ lazy val backend = projectMatrix
"org.http4s" %% "http4s-ember-server" % Versions.http4s,
"org.http4s" %% "http4s-ember-client" % Versions.http4s,
"org.postgresql" % "postgresql" % Versions.Postgres,
"org.flywaydb" % "flyway-core" % Versions.Flyway
"org.flywaydb" % "flyway-database-postgresql" % Versions.FlywayPG,
).map(_ % Test),
testFrameworks += new TestFramework("weaver.framework.CatsEffect"),
Test / fork := true,
Expand All @@ -119,10 +123,10 @@ lazy val backend = projectMatrix
Def.task[Seq[File]] {
copyAll(
frontendBundle.value,
(Test / resourceManaged).value / "assets"
(Test / resourceManaged).value / "assets",
)
}
}
},
)

lazy val shared = projectMatrix
Expand All @@ -132,29 +136,31 @@ lazy val shared = projectMatrix
.jsPlatform(Seq(Versions.Scala))
.enablePlugins(Smithy4sCodegenPlugin)
.settings(
scalacSettings,
libraryDependencies ++= Seq(
"com.disneystreaming.smithy4s" %%% "smithy4s-http4s" % smithy4sVersion.value,
"io.lemonlabs" %%% "scala-uri" % "4.0.3"
"com.indoorvivants" %%% "scala-uri" % "4.1.0",
),
Compile / doc / sources := Seq.empty
Compile / doc / sources := Seq.empty,
)

lazy val frontend = projectMatrix
.in(file("modules/frontend"))
.customRow(
Seq(Versions.Scala),
axisValues = Seq(VirtualAxis.js, BuildStyle.SingleFile),
Seq.empty
Seq.empty,
)
.customRow(
Seq(Versions.Scala),
axisValues = Seq(VirtualAxis.js, BuildStyle.Modules),
Seq.empty
Seq.empty,
)
.defaultAxes((defaults :+ VirtualAxis.js)*)
.dependsOn(shared)
.enablePlugins(ScalaJSPlugin, BundleMonPlugin)
.settings(
scalacSettings,
scalaJSUseMainModuleInitializer := true,
scalaJSLinkerConfig := {
val config = scalaJSLinkerConfig.value
Expand All @@ -164,7 +170,7 @@ lazy val frontend = projectMatrix
config
.withModuleSplitStyle(
ModuleSplitStyle
.SmallModulesFor(List(s"${Config.BasePackage}.frontend"))
.SmallModulesFor(List(s"${Config.BasePackage}.frontend")),
)
.withModuleKind(ModuleKind.ESModule)
.withOutputPatterns(OutputPatterns.fromJSFile("%s.mjs"))
Expand All @@ -178,17 +184,17 @@ lazy val frontend = projectMatrix
"io.circe" %%% "circe-core" % Versions.circe,
"io.circe" %%% "circe-parser" % Versions.circe,
"org.http4s" %%% "http4s-dom" % Versions.http4sDom,
"org.scala-js" %%% "scala-js-macrotask-executor" % Versions.macroTaskExecutor
)
"org.scala-js" %%% "scala-js-macrotask-executor" % Versions.macroTaskExecutor,
),
)

lazy val defaults =
Seq(VirtualAxis.scalaABIVersion(Versions.Scala), VirtualAxis.jvm)

lazy val frontendModules = taskKey[(Report, File)]("")
ThisBuild / frontendModules := (Def.taskIf {
ThisBuild / frontendModules := Def.taskIf {
def proj = frontend.finder(BuildStyle.Modules)(
Versions.Scala
Versions.Scala,
)

if (isRelease)
Expand All @@ -197,12 +203,12 @@ ThisBuild / frontendModules := (Def.taskIf {
else
(proj / Compile / fastLinkJS).value.data ->
(proj / Compile / fastLinkJS / scalaJSLinkerOutputDirectory).value
}).value
}.value

lazy val frontendBundle = taskKey[File]("")
ThisBuild / frontendBundle := (Def.taskIf {
ThisBuild / frontendBundle := Def.taskIf {
def proj = frontend.finder(BuildStyle.SingleFile)(
Versions.Scala
Versions.Scala,
)

if (isRelease) {
Expand All @@ -212,7 +218,7 @@ ThisBuild / frontendBundle := (Def.taskIf {
val res = (proj / Compile / fastLinkJS).value
(proj / Compile / fastLinkJS / scalaJSLinkerOutputDirectory).value
}
}).value
}.value

lazy val isRelease = sys.env.get("RELEASE").contains("yesh")

Expand All @@ -221,17 +227,46 @@ addCommandAlias("stubTests", "backend/testOnly jobby.tests.stub.*")
addCommandAlias("unitTests", "backend/testOnly jobby.tests.unit.*")
addCommandAlias(
"fastTests",
"backend/testOnly jobby.tests.stub.* jobby.tests.unit.*"
"backend/testOnly jobby.tests.stub.* jobby.tests.unit.*",
)
addCommandAlias(
"integrationTests",
"backend/testOnly jobby.tests.integration.*"
"backend/testOnly jobby.tests.integration.*",
)
addCommandAlias(
"frontendTests",
"backend/testOnly jobby.tests.frontend.*"
"backend/testOnly jobby.tests.frontend.*",
)

val scalafixRules = Seq(
"OrganizeImports",
"DisableSyntax",
"LeakingImplicitClassVal",
"NoValInForComprehension",
).mkString(" ")

val CICommands = Seq(
"clean",
"scalafixEnable",
"compile",
"test",
"scalafmtCheckAll",
"scalafmtSbtCheck",
s"scalafix --check $scalafixRules",
).mkString(";")

val PrepareCICommands = Seq(
"scalafixEnable",
s"scalafix --rules $scalafixRules",
s"Test/scalafix --rules $scalafixRules",
"scalafmtAll",
"scalafmtSbt",
).mkString(";")

addCommandAlias("ci", CICommands)

addCommandAlias("preCI", PrepareCICommands)

lazy val buildFrontend = taskKey[Unit]("")

buildFrontend := {
Expand All @@ -251,7 +286,7 @@ buildFrontend := {
ThisBuild / concurrentRestrictions ++= {
if (sys.env.contains("CI")) {
Seq(
Tags.limitAll(4)
Tags.limitAll(4),
)
} else Seq.empty
}
5 changes: 5 additions & 0 deletions jobby.opts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
PG_USER=jobby
PG_PASSWORD=mysecretpassword
PG_DB=jobby
LOCAL_DEPLOYMENT=true
PG_PORT=5439
2 changes: 1 addition & 1 deletion modules/app/src/main/scala/app.scala
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ object Main extends IOApp:
}.toMap

def run(args: List[String]) =
import natchez.Trace.Implicits.noop
import org.typelevel.otel4s.trace.Tracer.Implicits.noop

val logger = scribe.cats.io

Expand Down
2 changes: 1 addition & 1 deletion modules/backend/src/main/scala/FlyIOLoader.scala
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class FlyIOLoader(env: Map[String, String]):
user = userName,
password = Some(password),
database = dbName,
ssl = false
ssl = false,
)
}.toOption

Expand Down
Loading
Loading