From c746b50316234c9d0c70fb160dbc10181d2fdda2 Mon Sep 17 00:00:00 2001 From: David Francoeur Date: Fri, 5 Jan 2024 00:05:13 -0500 Subject: [PATCH] two publish --- build.sbt | 93 ++++++++++++++++++++---------------------- scripts/build-image.sh | 8 +++- 2 files changed, 51 insertions(+), 50 deletions(-) diff --git a/build.sbt b/build.sbt index 2da9470..6c68608 100644 --- a/build.sbt +++ b/build.sbt @@ -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")) @@ -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" @@ -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 - ) diff --git a/scripts/build-image.sh b/scripts/build-image.sh index 15a0b99..13da4d8 100755 --- a/scripts/build-image.sh +++ b/scripts/build-image.sh @@ -13,4 +13,10 @@ fi set -u (cd modules/frontend; npm i && npm run build) -sbt "backend / Docker / $BACKEND_PUBLISH; backendDependencies / Docker / $BACKEND_PUBLISH" \ No newline at end of file +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" \ No newline at end of file