Move Docker build into sbt using git info for the version number.
Centralise the generation of the ETL Docker image in the sbt main build
and use the "git describe" output as versioning for it.
Remove the version from the ETL fat jar name since it is going to be inside
the docker container anyway.
Change-Id: Ia4a9aeed95303062a5e1df9007e08bfe18dfb676
diff --git a/Dockerfile b/Dockerfile
deleted file mode 100644
index 8916af5..0000000
--- a/Dockerfile
+++ /dev/null
@@ -1,6 +0,0 @@
-FROM gerritforge/jw2017-spark
-
-RUN apk add --no-cache wget
-RUN mkdir -p /app
-
-COPY ./target/scala-2.11/GerritAnalytics-assembly-1.0.jar /app
diff --git a/README.md b/README.md
index ff410db..7fc13ee 100644
--- a/README.md
+++ b/README.md
@@ -10,7 +10,7 @@
```
bin/spark-submit \
--conf spark.es.nodes=es.mycompany.com \
- $JARS/SparkAnalytics-assembly-1.0.jar \
+ $JARS/SparkAnalytics-assembly.jar \
--since 2000-06-01 \
--aggregate email_hour \
--url http://gerrit.mycompany.com \
@@ -65,11 +65,9 @@
## Distribute as Docker Container
-To Distribute the `gerritforge/spark-gerrit-analytics-etl` docker container just run:
+To build the `gerritforge/spark-gerrit-analytics-etl` docker container just run `sbt docker`. If you want to distribute
+use `sbt dockerBuildAndPush`.
- ```bash
- sbt clean assembly
- docker-compose -f analytics-etl.yaml build
- docker push
- docker push gerritforge/spark-gerrit-analytics-etl:1.0
- ```
+The build and distribution override the `latest` image tag too
+
+Remember to create an annotated tag for a relase. The tag is used to define the docker image tag too
\ No newline at end of file
diff --git a/analytics-etl.yaml b/analytics-etl.yaml
deleted file mode 100644
index 8876d3b..0000000
--- a/analytics-etl.yaml
+++ /dev/null
@@ -1,9 +0,0 @@
-version: '3'
-
-services:
-
- analytics-etl:
- build: .
- image: gerritforge/spark-gerrit-analytics-etl:1.0
-
-
diff --git a/build.sbt b/build.sbt
index f59493c..fb95c41 100644
--- a/build.sbt
+++ b/build.sbt
@@ -1,6 +1,13 @@
-name := "GerritAnalytics"
+import sbt.Keys.version
-version := "1.0"
+enablePlugins(GitVersioning)
+enablePlugins(DockerPlugin)
+
+git.useGitDescribe := true
+
+organization := "gerritforge"
+
+name := "GerritAnalytics"
scalaVersion := "2.11.8"
@@ -24,4 +31,28 @@
mainClass in (Compile,run) := Some("com.gerritforge.analytics.job.Main")
-parallelExecution in Test := false
\ No newline at end of file
+parallelExecution in Test := false
+
+dockerfile in docker := {
+ val artifact: File = assembly.value
+ val artifactTargetPath = s"/app/${name.value}-assembly.jar"
+
+ new Dockerfile {
+ from("gerritforge/jw2017-spark")
+ runRaw("apk add --no-cache wget")
+ runRaw("mkdir -p /app")
+ add(artifact, artifactTargetPath )
+ }
+}
+
+imageNames in docker := Seq(
+ ImageName(s"${organization.value}/spark-gerrit-analytics-etl:latest"),
+
+ ImageName(
+ namespace = Some(organization.value),
+ repository = "spark-gerrit-analytics-etl",
+ tag = Some(version.value)
+ )
+)
+
+buildOptions in docker := BuildOptions(cache = false)
\ No newline at end of file
diff --git a/project/docker.sbt b/project/docker.sbt
new file mode 100644
index 0000000..b8343b2
--- /dev/null
+++ b/project/docker.sbt
@@ -0,0 +1 @@
+addSbtPlugin("se.marcuslonnberg" % "sbt-docker" % "1.5.0")
\ No newline at end of file
diff --git a/project/git.sbt b/project/git.sbt
new file mode 100644
index 0000000..e8972cf
--- /dev/null
+++ b/project/git.sbt
@@ -0,0 +1 @@
+addSbtPlugin("com.typesafe.sbt" % "sbt-git" % "0.9.3")
\ No newline at end of file