endpoint modifications
continuous-integration/drone/push Build is passing Details

production
Override-6 2 years ago
parent 0f71299ebd
commit 17a6e7aa48

@ -1,31 +0,0 @@
kind: pipeline
type: docker
name: Deployment
trigger:
branch:
- production
- dev
steps:
- name: 'Unit Tests'
image: ubuntu:latest
commands:
- apt update && apt install openjdk-11-jdk -y
- ./gradlew :test
- name: deploy to server
image: ubuntu:latest
depends_on:
- 'Unit Tests'
environment:
SSH_PRIVATE_KEY:
from_secret: ???
SSH_PUBLIC_KEY:
from_secret: ???
USER:
from_secret: ???
IP:
from_secret: ???
commands:
- drone/deliver.sh $DRONE_BRANCH

@ -11,7 +11,7 @@ import zio.http.model.Status
import scala.collection.mutable
class Endpoint(hostname: String, port: Int) extends ZIOAppDefault {
class Endpoint(port: Int) extends ZIOAppDefault {
private val handlers = mutable.HashMap.empty[String, APIRequestHandler]
@ -46,7 +46,7 @@ class Endpoint(hostname: String, port: Int) extends ZIOAppDefault {
val configLayer = ServerConfig.live(config)
Server.install(app).flatMap { port =>
LOG.info(s"Listening API entries on $hostname:$port")
LOG.info(s"Listening API entries on $port")
ZIO.never
}.provide(configLayer, Server.live)
}

@ -4,7 +4,7 @@ plugins {
id 'scala'
id 'application' //for 'run' task
id 'com.adarshr.test-logger' version '3.2.0' //fancy prints during tests
id 'com.github.johnrengelman.shadow' version '7.1.2' //for optimised jar
id 'com.github.johnrengelman.shadow' version '7.1.2' //for building optimised jar
}
final var scalaVersion = "2.13"

@ -0,0 +1,29 @@
kind: pipeline
type: docker
name: Deployment
trigger:
branch:
- production
- dev
- drone-setup
steps:
- name: Unit tests
image: amazoncorretto:11
commands:
- echo
- ./gradlew :test
- name: Deploy
image: amazoncorretto:11
depends_on:
- 'Unit tests'
environment:
SSH_PRIVATE_KEY:
from_secret: SSH_PRIVATE
SSH_PUBLIC_KEY:
from_secret: SSH_PUBLIC
commands:
- chmod 777 drone/deliver.sh
- drone/deliver.sh $DRONE_BRANCH

@ -1 +1 @@
endpoint.url=localhost:48485
endpoint.url=48485

@ -10,23 +10,21 @@ object EndpointSetup {
final val EndpointUrl = "endpoint.url"
final val EndpointUrlDefault = s"localhost:48485"
def setupEndpoint(): Endpoint = {
def setupEndpoint(config: Properties): Endpoint = {
Main.LOG.debug("Initializing API endpoint...")
val endpoint = createEndpoint()
val endpoint = createEndpoint(config)
endpoint.bind("counter")(IncrementHandler)
endpoint
}
private def createEndpoint(): Endpoint = {
val properties = new Properties()
val in = getClass.getClassLoader.getResourceAsStream("server.properties")
properties.load(in)
val (hostname, port) = properties
private def createEndpoint(config: Properties): Endpoint = {
val port = config
.getProperty(EndpointUrl, EndpointUrlDefault) match {
case s"$ip:$port" => (ip, port.toInt)
case v => throw new InternalBasketServerException(s"$EndpointUrl property value is wrong: $v must be <ip>:<port>/[endpointPath]")
case s"$port" if port.toIntOption.isDefined => port.toInt
case v =>
throw new InternalBasketServerException(s"$EndpointUrl property value is wrong: $v must be integer")
}
new Endpoint(hostname, port)
new Endpoint(port)
}
}

@ -5,6 +5,8 @@ import org.apache.logging.log4j.LogManager
import zio._
import java.lang
import java.nio.file.{Files, Path}
import java.util.Properties
import scala.io.StdIn
import scala.util.control.NonFatal
@ -13,8 +15,19 @@ object Main {
def main(args: Array[String]): Unit = {
LOG.info("Starting server")
val endpoint = EndpointSetup.setupEndpoint()
val runtime = Runtime.default
val config = retrieveConfig
db(config)
api(config)
LOG.info("Server successfully started")
}
private def db(config: Properties): Unit = new Thread({ () =>
}, "Database").start()
//TODO
private def api(config: Properties): Unit = new Thread({ () =>
val endpoint = EndpointSetup.setupEndpoint(config)
val runtime = Runtime.default
Unsafe.unsafe { implicit u =>
runtime.unsafe.run(endpoint.run).catchSome {
case NonFatal(e) =>
@ -22,9 +35,18 @@ object Main {
throw e
}
}
LOG.info("Server successfully started")
println("enter to exit")
StdIn.readLine()
}: Runnable, "API").start()
private def retrieveConfig: Properties = {
val configFile = Path.of("server.properties")
if (Files.notExists(configFile)) {
val in = getClass.getResourceAsStream("/server.properties")
Files.writeString(configFile, new String(in.readAllBytes()))
}
val in = Files.newInputStream(configFile)
val properties = new Properties()
properties.load(in)
properties
}
//add a shutdown hook to log when the server is about to get killed