Skip to content
This repository was archived by the owner on Apr 8, 2021. It is now read-only.
Open
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
34 changes: 33 additions & 1 deletion src/main/g8/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,38 @@

TODO: CO-176: Add detailed documentation to the template project

## Compilation

Compile the project by running:

```bash
> sbt compile
```

## Testing

Run the unit tests for the project by running:

```bash
> sbt test
```

Run the integration tests for the project by running:

```bash
> sbt dockerComposeUp # Start the docker environment
> sbt it:test # Run the integration tests
> sbt dockerComposeDown # Clean up the docker environment
```

Verify the formatting for the project by running:

```bash
> sbt verify
```

This runs scalastyle and scalafmt checks on all files.

<!--
Created from version $akka_template_version$ of https://github.com/cakesolutions/akka-http-template.g8
-->
-->
9 changes: 8 additions & 1 deletion src/main/g8/build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ lazy val serverMain = project
.settings(
name := "server",
mainClass in Compile :=
Some("$organisation_domain$.$organisation$.$name$.server.ServerMain"),
Some("$package$.server.ServerMain"),
libraryDependencies ++= Seq(
Akka.contrib,
Akka.Http.jsonSpray,
Expand All @@ -43,3 +43,10 @@ lazy val serverMain = project
lazy val root = project
.in(file("."))
.aggregate(core, serverMain)

// This runs the same checks as the Verification stage of the Jenkins pipeline.
addCommandAlias(
"verify",
";scalastyle;test:scalastyle;it:scalastyle " +
";sbt:scalafmt::test;scalafmt::test;test:scalafmt::test;it:scalafmt::test"
)
1 change: 1 addition & 0 deletions src/main/g8/default.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ name=CHANGE_ME
project_description=CHANGE_ME
organisation_domain=net
organisation=cakesolutions
package=$organisation_domain$.$organisation$.$name$
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package $organisation_domain$.$organisation$.$name$.core.actor
package $package$.core.actor

import com.github.levkhomich.akka.tracing.{ActorTracing, TracingActorLogging}

Expand Down Expand Up @@ -31,5 +31,4 @@ trait CommonActor extends ActorTracing with TracingActorLogging {
log.warning(s"Unhandled message: \$msg")
super.unhandled(msg)
}

}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package $organisation_domain$.$organisation$.$name$.core.api
package $package$.core.api

import scala.concurrent.{ExecutionContext, Future}

Expand All @@ -12,7 +12,7 @@ import eu.timepit.refined.api.Refined
import eu.timepit.refined.numeric._
import monix.eval.Task

import $organisation_domain$.$organisation$.$name$.core.application.ApplicationGlobalContext
import $package$.core.application.ApplicationGlobalContext

/**
* Common Http handler bootstrapping.
Expand Down Expand Up @@ -56,8 +56,7 @@ object BaseHttpHandler {
Http().bindAndHandle(Route.handlerFlow(route), hostname, port.value)

def httpCleanUp: Task[Unit] = Task.deferFutureAction { implicit ec =>
httpSocketBind
.flatMap(_.unbind())
httpSocketBind.flatMap(_.unbind()).map(_ => ())
}

Task
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package $organisation_domain$.$organisation$.$name$.core.api
package $package$.core.api

import scala.util.control.NonFatal

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package $organisation_domain$.$organisation$.$name$.core.api
package $package$.core.api

import akka.event.LoggingAdapter
import akka.http.scaladsl.model.StatusCodes.NotFound
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package $organisation_domain$.$organisation$.$name$.core.application
package $package$.core.application

import java.util.concurrent.atomic.AtomicBoolean

Expand All @@ -16,7 +16,7 @@ import monix.eval.Task
import monix.execution.{Cancelable, Scheduler}
import org.slf4j.LoggerFactory

import $organisation_domain$.$organisation$.$name$.core.utils.ValueDiscard
import $package$.core.utils.ValueDiscard

// \$COVERAGE-OFF\$

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package $organisation_domain$.$organisation$.$name$.core.application
package $package$.core.application

import akka.actor.ActorSystem
import akka.event.LoggingAdapter
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package $organisation_domain$.$organisation$.$name$.core.application
package $package$.core.application

import java.lang.management.ManagementFactory

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package $organisation_domain$.$organisation$.$name$.core.application.workflow
package $package$.core.application.workflow

import scala.concurrent.duration.{FiniteDuration, TimeUnit}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package $organisation_domain$.$organisation$.$name$.core.application.workflow
package $package$.core.application.workflow

/**
* Exception message indicating that a task's retry logic has failed.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package $organisation_domain$.$organisation$.$name$.core.application.workflow
package $package$.core.application.workflow

import scala.concurrent.duration._

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package $organisation_domain$.$organisation$.$name$.core.application.workflow
package $package$.core.application.workflow

package internal

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package $organisation_domain$.$organisation$.$name$.core.application.workflow
package $package$.core.application.workflow

package internal

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package $organisation_domain$.$organisation$.$name$.core.application
package $package$.core.application

import monix.eval.Task

import $organisation_domain$.$organisation$.$name$.core.application.workflow.internal._
import $package$.core.application.workflow.internal._

/**
* Package object for adding retry logic to tasks.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package $organisation_domain$.$organisation$.$name$.core.config
package $package$.core.config

import cakesolutions.config.ValueError
import cats.data.NonEmptyList
import net.cakesolutions.config.ValueError

/**
* Exception case class that holds the configuration failures that occured
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package $organisation_domain$.$organisation$.$name$.core.utils
package $package$.core.utils

/**
* Function that allows values to be discarded in a visible way.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package $organisation_domain$.$organisation$.$name$.core.application.workflow
package $package$.core.application.workflow

import scala.concurrent.duration._
import scala.util.Random
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package $organisation_domain$.$organisation$.$name$.core.application.workflow
package $package$.core.application.workflow

import scala.concurrent.duration._

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package $organisation_domain$.$organisation$.$name$.core.application.workflow
package $package$.core.application.workflow

package internal

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package $organisation_domain$.$organisation$.$name$.core.config
package $package$.core.config

import scala.util.Try

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package $organisation_domain$.$organisation$.$name$
package $package$

import akka.http.scaladsl.Http
import akka.http.scaladsl.model.HttpRequest
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package $organisation_domain$.$organisation$.$name$
package $package$

import scala.concurrent.ExecutionContext

Expand All @@ -7,20 +7,19 @@ import akka.stream.ActorMaterializer
import com.typesafe.config.Config
import org.scalatest.{AsyncFreeSpec, Matchers}

import $organisation_domain$.$organisation$.$name$.core.config.ConfigHelper
import $organisation_domain$.$organisation$.$name$.server.config.ValidatedServerConfig
import $package$.core.config.ConfigHelper
import $package$.server.config.ValidatedServerConfig

object RestApiIntegrationTest {

val requiredEnvVars: Map[String, String] = {
// In CI environments, we use the eth0 or local-ipv4 address of the slave
// instead of localhost
val appHost = sys.env.getOrElse("CI_HOST", "localhost")

Map(
"SERVER_HOST" -> appHost,
"SERVER_PORT" -> "9000",
"ZIPKIN_HOST" -> appHost,
"ZIPKIN_PORT" -> "9410"
"SERVER_PORT" -> "9000"
)
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
package $organisation_domain$.$organisation$.$name$.server
package $package$.server

import akka.http.scaladsl.server.Directives._
import cats.data.Validated
import com.typesafe.config.Config
import monix.eval.Task

import $organisation_domain$.$organisation$.$name$.core.api.BaseHttpHandler
import $organisation_domain$.$organisation$.$name$.core.application.{ApplicationBootstrapping, ApplicationGlobalContext}
import $organisation_domain$.$organisation$.$name$.core.config.ConfigurationFailure
import $organisation_domain$.$organisation$.$name$.server.api.{CoreRoutes, SwaggerRoutes}
import $organisation_domain$.$organisation$.$name$.server.config.ValidatedServerConfig
import $organisation_domain$.$organisation$.$name$.server.config.ValidatedServerConfig.ServerConfig
import $package$.core.api.BaseHttpHandler
import $package$.core.application.{ApplicationBootstrapping, ApplicationGlobalContext}
import $package$.core.config.ConfigurationFailure
import $package$.server.api.{CoreRoutes, SwaggerRoutes}
import $package$.server.config.ValidatedServerConfig
import $package$.server.config.ValidatedServerConfig.ServerConfig

// \$COVERAGE-OFF\$

/**
* Service boostrapping.
* Service bootstrapping.
*/
object ServerMain extends ApplicationBootstrapping {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package $organisation_domain$.$organisation$.$name$.server.api
package $package$.server.api

import akka.http.scaladsl.model.{ContentTypes, HttpEntity}
import akka.http.scaladsl.server.Directives._
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package $organisation_domain$.$organisation$.$name$.server.api
package $package$.server.api

import akka.http.scaladsl.model.{ContentTypes, StatusCodes, Uri}
import akka.http.scaladsl.server.Directives._
import akka.http.scaladsl.server.Route

import $organisation_domain$.$organisation$.$name$.server.config.ValidatedServerConfig
import $package$.server.config.ValidatedServerConfig

/**
* Factory defining the Swagger documentation endpoints.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
package $organisation_domain$.$organisation$.$name$.server.config
package $package$.server.config

import cakesolutions.config._
import cats.Applicative
import cats.data.{NonEmptyList => NEL, Validated}
import cats.syntax.cartesian._
import com.typesafe.config.Config
import eu.timepit.refined._
import eu.timepit.refined.api.Refined
import eu.timepit.refined.auto._
import eu.timepit.refined.numeric._
import eu.timepit.refined.string._
import net.cakesolutions.config._

/**
* Validated server configuration.
Expand Down Expand Up @@ -50,10 +49,13 @@ object ValidatedServerConfig {
implicit config: Config
): Validated[NEL[ValueFailure], ServerConfig] = {
via[ServerConfig]("server") { implicit config =>
(unchecked[SwaggerPathString]("swagger-ui.path") |@|
(unchecked[String](required("host", "NOT_SET")) |@|
unchecked[PositiveInt](required("port", "NOT_SET")))
.map(new HttpConfig(_, _) {})).map(new ServerConfig(_, _) {})
Applicative[ValidationFailure].map2(
unchecked[SwaggerPathString]("swagger-ui.path"),
Applicative[ValidationFailure].map2(
unchecked[String](required("host", "NOT_SET")),
unchecked[PositiveInt](required("port", "NOT_SET"))
)(new HttpConfig(_, _) {})
)(new ServerConfig(_, _) {})
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package $organisation_domain$.$organisation$.$name$.server.api
package $package$.server.api

import akka.http.scaladsl.testkit.ScalatestRouteTest
import org.scalatest.{Matchers, WordSpec}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package $organisation_domain$.$organisation$.$name$.server.api
package $package$.server.api

import akka.http.scaladsl.server.Route
import akka.http.scaladsl.testkit.ScalatestRouteTest
import cats.data.Validated
import com.typesafe.config.Config
import org.scalatest.{Matchers, WordSpec}

import $organisation_domain$.$organisation$.$name$.core.config.{ConfigHelper, ConfigurationFailure}
import $organisation_domain$.$organisation$.$name$.server.config.ValidatedServerConfig
import $organisation_domain$.$organisation$.$name$.server.config.ValidatedServerConfig.ServerConfig
import $package$.core.config.{ConfigHelper, ConfigurationFailure}
import $package$.server.config.ValidatedServerConfig
import $package$.server.config.ValidatedServerConfig.ServerConfig

object SwaggerRoutesSpec {
val requiredEnvVars: Map[String, String] =
Expand Down
Loading