Skip to content

Commit

Permalink
portainer: don't pull image, updates
Browse files Browse the repository at this point in the history
  • Loading branch information
lhns committed Nov 15, 2022
1 parent 16ad48c commit 0b4fee6
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 19 deletions.
3 changes: 2 additions & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ ThisBuild / name := (server / name).value
name := (ThisBuild / name).value

val V = new {
val betterMonadicFor = "0.3.1"
val cats = "2.9.0"
val catsEffect = "3.4.0"
val circe = "0.14.3"
Expand All @@ -25,7 +26,7 @@ lazy val commonSettings: Seq[Setting[_]] = Seq(
sys.env.get("CI_VERSION").collect { case Tag(tag) => tag }
.getOrElse("0.0.1-SNAPSHOT")
},
addCompilerPlugin("com.olegpy" %% "better-monadic-for" % "0.3.1"),
addCompilerPlugin("com.olegpy" %% "better-monadic-for" % V.betterMonadicFor),
libraryDependencies ++= Seq(
"ch.qos.logback" % "logback-classic" % V.logbackClassic % Test,
"de.lolhens" %% "munit-tagless-final" % V.munitTaglessFinal % Test,
Expand Down
2 changes: 1 addition & 1 deletion project/build.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
sbt.version=1.7.3
sbt.version=1.8.0
13 changes: 8 additions & 5 deletions server/src/main/scala/de/lhns/kubedeploy/Config.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package de.lhns.kubedeploy

import cats.data.OptionT
import cats.effect.Sync
import cats.effect.std.Env
import de.lhns.kubedeploy.model.DeployTarget
import io.circe.Codec
import io.circe.generic.semiauto._
Expand All @@ -9,9 +12,9 @@ case class Config(targets: Seq[DeployTarget])
object Config {
implicit val codec: Codec[Config] = deriveCodec

lazy val fromEnv: Config =
Option(System.getenv("CONFIG"))
.toRight(new IllegalArgumentException("Missing variable: CONFIG"))
.flatMap(io.circe.config.parser.decode[Config](_))
.toTry.get
def fromEnv[F[_] : Sync]: F[Config] =
OptionT(Env.make[F].get("CONFIG"))
.toRight(new IllegalArgumentException("Missing environment variable: CONFIG"))
.subflatMap(io.circe.config.parser.decode[Config](_))
.rethrowT
}
24 changes: 13 additions & 11 deletions server/src/main/scala/de/lhns/kubedeploy/Main.scala
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import org.http4s.server.middleware.ErrorAction
import org.log4s.getLogger

import java.net.ProxySelector
import scala.concurrent.duration._
import scala.util.chaining._

object Main extends IOApp {
Expand All @@ -35,18 +36,18 @@ object Main extends IOApp {

setDefaultTrustManager(jreTrustManagerWithEnvVar)

applicationResource(Config.fromEnv).use(_ => IO.never)
applicationResource.use(_ => IO.never)
}

def applicationResource(config: Config): Resource[IO, Unit] =
def applicationResource: Resource[IO, Unit] =
for {
_ <- Resource.eval(IO(logger.info(s"CONFIG: ${config.asJson.spaces2}")))
config <- Resource.eval(Config.fromEnv[IO])
_ = logger.info(s"CONFIG: ${config.asJson.spaces2}")
client <- JdkHttpClient.simple[IO]
backends = loadBackends(config, client)
routes = new KubedeployRoutes(backends)
_ <- serverResource(
host"0.0.0.0",
port"8080",
SocketAddress(host"0.0.0.0", port"8080"),
routes.toRoutes.orNotFound
)
} yield ()
Expand All @@ -62,14 +63,15 @@ object Main extends IOApp {
throw new RuntimeException("invalid target: " + target.id)
}.toMap

def serverResource(host: Host, port: Port, http: HttpApp[IO]): Resource[IO, Server] =
EmberServerBuilder.default[IO]
.withHost(host)
.withPort(port)
def serverResource[F[_] : Async](socketAddress: SocketAddress[Host], http: HttpApp[F]): Resource[F, Server] =
EmberServerBuilder.default[F]
.withHost(socketAddress.host)
.withPort(socketAddress.port)
.withHttpApp(ErrorAction.log(
http = http,
messageFailureLogAction = (t, msg) => IO(logger.debug(t)(msg)),
serviceErrorLogAction = (t, msg) => IO(logger.error(t)(msg))
messageFailureLogAction = (t, msg) => Async[F].delay(logger.debug(t)(msg)),
serviceErrorLogAction = (t, msg) => Async[F].delay(logger.error(t)(msg))
))
.withShutdownTimeout(1.second)
.build
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ class PortainerDeployBackend(
StackFileContent: String,
Env: Seq[EnvVar],
Prune: Boolean,
PullImage: Boolean,
)

object StackFileUpdate {
Expand Down Expand Up @@ -126,7 +127,8 @@ class PortainerDeployBackend(
StackFileUpdate(
StackFileContent = stackFile,
Env = stack.value.Env,
Prune = true
Prune = false,
PullImage = false,
)
})((acc, action) => acc.map { stackFileUpdate =>
action match {
Expand Down

0 comments on commit 0b4fee6

Please sign in to comment.