diff --git a/docs/serving/samples/hello-world/helloworld-scala/Dockerfile b/docs/serving/samples/hello-world/helloworld-scala/Dockerfile index 6cf5f4729..c73e3a254 100644 --- a/docs/serving/samples/hello-world/helloworld-scala/Dockerfile +++ b/docs/serving/samples/hello-world/helloworld-scala/Dockerfile @@ -1,5 +1,5 @@ # Use an SBT image matching the Scala and JDK version. -FROM hseeberger/scala-sbt:8u265_1.4.2_2.12.12 as builder +FROM hseeberger/scala-sbt:8u265_1.4.2_2.13.3 as builder # Copy local code to the container image. WORKDIR /app @@ -16,7 +16,7 @@ RUN sbt assembly FROM openjdk:8-jre-alpine # Copy the jar to the production image from the builder stage. -COPY --from=builder /app/target/scala-2.12/helloworld-*.jar /helloworld.jar +COPY --from=builder /app/target/scala-2.13/helloworld-*.jar /helloworld.jar # Run the web service on container startup. CMD ["java", "-Djava.security.egd=file:/dev/./urandom", "-jar", "/helloworld.jar"] diff --git a/docs/serving/samples/hello-world/helloworld-scala/README.md b/docs/serving/samples/hello-world/helloworld-scala/README.md index 2e2f55f79..272c3978c 100644 --- a/docs/serving/samples/hello-world/helloworld-scala/README.md +++ b/docs/serving/samples/hello-world/helloworld-scala/README.md @@ -27,7 +27,7 @@ cd knative-docs/docs/serving/samples/hello-world/helloworld-scala ## Configuring the Service descriptor -Importantly, in [helloworld-scala.yaml](./helloworld-scala.yaml) **change the +Importantly, in [service.yaml](./service.yaml) **change the image reference to match up with your designated repository**, i.e. replace `{username}` with your Dockerhub username in the example below. diff --git a/docs/serving/samples/hello-world/helloworld-scala/build.sbt b/docs/serving/samples/hello-world/helloworld-scala/build.sbt index 51238f066..87848a3ca 100644 --- a/docs/serving/samples/hello-world/helloworld-scala/build.sbt +++ b/docs/serving/samples/hello-world/helloworld-scala/build.sbt @@ -4,14 +4,14 @@ name := "helloworld-scala" version := "0.0.1" -scalaVersion := "2.12.8" +scalaVersion := "2.13.3" -mainClass in Compile := Some("klang.HelloWorldScala") +mainClass in Compile := Some("example.HelloWorldScala") scalacOptions ++= Seq("-encoding", "UTF-8") -lazy val akkaVersion = "2.5.16" -lazy val akkaHttpVersion = "10.1.5" +lazy val akkaVersion = "2.6.10" +lazy val akkaHttpVersion = "10.2.1" libraryDependencies ++= Seq( "com.typesafe.akka" %% "akka-actor" % akkaVersion, diff --git a/docs/serving/samples/hello-world/helloworld-scala/helloworld-scala.yaml b/docs/serving/samples/hello-world/helloworld-scala/service.yaml similarity index 61% rename from docs/serving/samples/hello-world/helloworld-scala/helloworld-scala.yaml rename to docs/serving/samples/hello-world/helloworld-scala/service.yaml index 85fdf2c25..4c8160c52 100644 --- a/docs/serving/samples/hello-world/helloworld-scala/helloworld-scala.yaml +++ b/docs/serving/samples/hello-world/helloworld-scala/service.yaml @@ -9,7 +9,5 @@ spec: containers: - image: docker.io/{username}/helloworld-scala env: - - name: MESSAGE - value: "Scala & Akka on Knative says hello!" - - name: HOST - value: "localhost" + - name: TARGET + value: "Scala Sample v1" diff --git a/docs/serving/samples/hello-world/helloworld-scala/src/main/resources/application.conf b/docs/serving/samples/hello-world/helloworld-scala/src/main/resources/application.conf index d85dbb527..c8fabceaf 100644 --- a/docs/serving/samples/hello-world/helloworld-scala/src/main/resources/application.conf +++ b/docs/serving/samples/hello-world/helloworld-scala/src/main/resources/application.conf @@ -3,6 +3,6 @@ helloworld { host = ${?HOST} port = 8080 port = ${?PORT} - message = "Hello World!" - message = ${?MESSAGE} + target = "World" + target = ${?TARGET} } diff --git a/docs/serving/samples/hello-world/helloworld-scala/src/main/scala/klang/HelloWorldScala.scala b/docs/serving/samples/hello-world/helloworld-scala/src/main/scala/example/HelloWorldScala.scala similarity index 81% rename from docs/serving/samples/hello-world/helloworld-scala/src/main/scala/klang/HelloWorldScala.scala rename to docs/serving/samples/hello-world/helloworld-scala/src/main/scala/example/HelloWorldScala.scala index feeaf0f05..a386da443 100644 --- a/docs/serving/samples/hello-world/helloworld-scala/src/main/scala/klang/HelloWorldScala.scala +++ b/docs/serving/samples/hello-world/helloworld-scala/src/main/scala/example/HelloWorldScala.scala @@ -1,4 +1,4 @@ -package klang +package example import akka.actor.ActorSystem import akka.event.LoggingAdapter @@ -15,8 +15,6 @@ object HelloWorldScala { def main(args: Array[String]): Unit = { // Creates and initializes an Akka Actor System implicit val system: ActorSystem = ActorSystem("HelloWorldScala") - // Creates and initializes a Materializer to be used for the Akka HTTP Server - implicit val mat: Materializer = ActorMaterializer() // Specifies where any Futures in this code will execute implicit val ec: ExecutionContext = system.dispatcher // Obtains a logger to be used for the sample @@ -25,7 +23,7 @@ object HelloWorldScala { val config = system.settings.config // These are read from the application.conf file under `resources` - val message = config.getString("helloworld.message") + val target = config.getString("helloworld.target") val host = config.getString("helloworld.host") val port = config.getInt("helloworld.port") @@ -34,13 +32,13 @@ object HelloWorldScala { path("") { get { log.info("Received request to HelloWorldScala") - complete(HttpEntity(`text/html(UTF-8)`, message)) + complete(HttpEntity(`text/html(UTF-8)`, s"Hello $target!")) } } // Here we create the Http server, and bind it to the host and the port, // so we can serve requests using the route(s) we defined previously. - val binding = Http().bindAndHandle(serviceRoute, host, port) andThen { + val binding = Http().newServerAt(host, port).bind(serviceRoute) andThen { case Success(sb) => log.info("Bound: {}", sb) case Failure(t) =>