如何使用 sbt-native-packager 设置 Docker Registry
Posted
技术标签:
【中文标题】如何使用 sbt-native-packager 设置 Docker Registry【英文标题】:How to set the Docker Registry with sbt-native-packager 【发布时间】:2020-11-07 21:09:13 【问题描述】:我正在尝试使用 sbt-native-packager 和以下 build.sbt
构建 Docker 映像(尝试将映像发布到本地存储库)
val sparkVersion = "2.4.5"
scalaVersion in ThisBuild := "2.12.0"
val sparkLibs = Seq(
"org.apache.spark" %% "spark-core" % sparkVersion,
"org.apache.spark" %% "spark-sql" % sparkVersion
)
// JAR build settings
lazy val commonSettings = Seq(
organization := "dzlab",
version := "0.1",
scalaSource in Compile := baseDirectory.value / "src",
scalaSource in Test := baseDirectory.value / "test",
resourceDirectory in Test := baseDirectory.value / "test" / "resources",
javacOptions ++= Seq(),
scalacOptions ++= Seq(
"-deprecation",
"-feature",
"-language:implicitConversions",
"-language:postfixOps"
),
libraryDependencies ++= sparkLibs
)
// Docker Image build settings
dockerBaseImage := "gcr.io/spark-operator/spark:v" + sparkVersion
lazy val root = (project in file("."))
.enablePlugins(
DockerPlugin,
JavaAppPackaging
)
.settings(
name := "spark-k8s",
commonSettings,
dockerAliases ++= Seq(
dockerAlias.value.withRegistryHost(Some("localhost:5000"))
),
mainClass in (Compile, run) := Some("dzlab.SparkJob")
)
SBT 和打包器版本
$ cat project/plugins.sbt
addSbtPlugin("com.typesafe.sbt" % "sbt-native-packager" % "1.0.0")
$ cat project/build.properties
sbt.version=0.13.18
当我尝试运行打包程序时
$ sbt docker:publish
[info] Loading global plugins from /Users/dzlab/.sbt/0.13/plugins
[info] Loading project definition from /Users/dzlab/Projects/spark-k8s/project
/Users/dzlab/Projects/spark-k8s/build.sbt:39: error: not found: value dockerAliases
dockerAliases ++= Seq(
^
sbt.compiler.EvalException: Type error in expression
[error] sbt.compiler.EvalException: Type error in expression
[error] Use 'last' for the full log.
Project loading failed: (r)etry, (q)uit, (l)ast, or (i)gnore? q
它无法识别 dockerAliases
不知道为什么,因为它是发布设置的一部分。
设置 Docker 注册表的正确方法是什么??
【问题讨论】:
【参考方案1】:你的 sbt-native-packager 版本已经过时了,就像你的 sbt 版本一样。该版本中不存在该 SettingKey。
比较:sbt-native-packager 1.0 与 sbt-native-packager 1.7.4
【讨论】:
以上是关于如何使用 sbt-native-packager 设置 Docker Registry的主要内容,如果未能解决你的问题,请参考以下文章
如何使用 sbt-native-packager 设置 docker 镜像名称
如何使用 sbt-native-packager 创建基本项目设置
如何使用 sbt-native-packager 更改通用 zip 文件名
如何使用 sbt-native-packager 创建 Upstart Zip 包?