Skip to content

Commit

Permalink
two publish
Browse files Browse the repository at this point in the history
  • Loading branch information
daddykotex committed Jan 5, 2024
1 parent 9448eb6 commit c746b50
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 50 deletions.
93 changes: 44 additions & 49 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,12 @@ lazy val smithyClasspath = settingKey[Seq[ModuleID]](
lazy val smithyClasspathDir = settingKey[String](
"""Path of the smithy classpath directory (where we mount the config and the jars)"""
)
lazy val dockerTagOverride = settingKey[Option[String]](
"""Override for the docker image tag."""
)

lazy val root = (project in file("."))
.aggregate(api, frontend, backend, backendDependencies)
.aggregate(api, frontend, backend)

lazy val api = (project in file("modules/api"))

Expand Down Expand Up @@ -142,8 +145,10 @@ lazy val backend = (project in file("modules/backend"))
"software.amazon.smithy" % "smithy-model" % smithyVersion,
"org.http4s" %% "http4s-ember-server" % http4sVersion
),
smithyClasspath := Seq.empty,
smithyClasspathDir := "smithy-classpath",
smithyClasspath := Seq(
"com.disneystreaming.smithy4s" % "smithy4s-protocol" % smithy4sVersion.value
),
Compile / resourceGenerators += Def.task {
val dir = frontend.base
val distDir = dir / "dist"
Expand All @@ -167,58 +172,48 @@ lazy val backend = (project in file("modules/backend"))
Docker / dockerExposedPorts := List(9000),
Docker / packageName := "smithy4s-code-generation",
Docker / dockerRepository := Some("daddykotex"),
dockerAliases ++= {
val sha = sys.env.get("GITHUB_SHA").map(_.take(10))
val latests = Seq(
dockerTagOverride := None,
dockerUpdateLatest := true,
dockerAliases := {
val flyAlias =
dockerAlias.value
.withName("morning-bird-7081")
.withRegistryHost(Option("registry.fly.io"))
)
val shas = sha.toSeq.flatMap { s =>
Seq(
dockerAlias.value.withTag(Some(s)),
dockerAlias.value
.withTag(Some(s))
.withName("morning-bird-7081")
.withRegistryHost(Option("registry.fly.io"))
)

dockerTagOverride.value match {
case Some(tagOverride) =>
val v = version.value
val preciseTag = s"$tagOverride-$v"
val allTags =
if (dockerUpdateLatest.value) Seq(preciseTag, tagOverride)
else Seq(preciseTag)
allTags.flatMap(tag =>
Seq(
dockerAlias.value.withTag(Some(tag)),
flyAlias.withTag(Some(tag))
)
)
case None =>
val latests =
if (dockerUpdateLatest.value)
Seq(
dockerAlias.value.withTag(Some("latest")),
flyAlias.withTag(Some("latest"))
)
else Seq.empty
Seq(dockerAlias.value, flyAlias) ++ latests
}
// val flyLatestAlias =
// if (dockerUpdateLatest.value) Seq(flyAlias.withTag(Some("latest")))
// else Seq.empty

latests ++ shas
// val taggedAlias = dockerTagPrefixes.value.flatMap { s =>
// Seq(
// dockerAlias.value.withTag(Some(s)),
// flyAlias.withTag(Some(s))
// )
// }
// Seq(flyAlias) ++ flyLatestAlias ++ taggedAlias
},
Docker / version := "latest",
dockerBaseImage := "eclipse-temurin:17.0.6_10-jre"
)

/** This is a project that's only intented to be a copy of backend but that
* builds in an image with some dependencies for the smithy-classpath.
*/
lazy val backendDependencies = project
.enablePlugins(DockerPlugin)
.settings(smithyClasspathSettings)
.settings(
smithyClasspath := Seq(
"com.disneystreaming.alloy" % "alloy-core" % "0.2.8",
"com.disneystreaming.smithy4s" % "smithy4s-protocol" % smithy4sVersion.value
),
smithyClasspathDir := "smithy-classpath",
Docker / packageName := "smithy4s-code-generation",
Docker / dockerRepository := Some("daddykotex"),
dockerAliases := {
val beAlias = (backend / dockerAlias).value
val sha = sys.env.get("GITHUB_SHA").map(_.take(10))
val tags =
sha.map(s => s"with-dependencies-$s").toSeq ++ Seq("with-dependencies")
tags.flatMap { t =>
Seq(
dockerAlias.value.withTag(Some(t)),
dockerAlias.value
.withTag(Some(t))
.withName("morning-bird-7081")
.withRegistryHost(Option("registry.fly.io"))
)
}
},
dockerEntrypoint := (backend / dockerEntrypoint).value,
dockerBaseImage := (backend / dockerAlias).value.toString
)
8 changes: 7 additions & 1 deletion scripts/build-image.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,10 @@ fi
set -u

(cd modules/frontend; npm i && npm run build)
sbt "backend / Docker / $BACKEND_PUBLISH; backendDependencies / Docker / $BACKEND_PUBLISH"
publish_backend="backend / Docker / $BACKEND_PUBLISH"
sbt "$publish_backend"


tag_override="set backend / dockerTagOverride := Some(\"with-dependencies\")"
smithy_classpath="set backend / smithyClasspath ++= Seq(\"com.disneystreaming.alloy\" % \"alloy-core\" % \"0.2.8\")"
sbt "$tag_override; $smithy_classpath; $publish_backend"

0 comments on commit c746b50

Please sign in to comment.