Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Universal Base Image #343

Merged
merged 10 commits into from
Apr 27, 2020
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,11 @@ Now you can disable root by setting `api.root.enabled` to `false` in `/etc/horiz
- detect if a pattern is updated with service that has userInput w/o default values, and give warning
- Consider changing all creates to POST, and update (via put/patch) return codes to 200

## Changes in 2.21.0

- Exchange API now uses Red Hat's Universal Base Image (UBI) 8 Minimal instead of Debian.
- SBT Native Packager updated to version 1.7.0 from 1.5.1.

## Changes in 2.20.0

- Issue 321: Updates to NodeStatus resource to support edge clusters
Expand Down
160 changes: 98 additions & 62 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -4,85 +4,121 @@
// Looking at https://github.com/sbt/sbt/releases , it's clear there are significant changes in 1.3.x, including with the class loader.

// This plugin is for building the docker image of our exchange svr
import scala.io.Source
import com.typesafe.sbt.packager.docker._

enablePlugins(JavaAppPackaging, DockerPlugin)

// For latest versions, see https://mvnrepository.com/
lazy val akkaHttpVersion = "10.1.10" // as of 11/19/2019 this is the latest version
lazy val akkaVersion = "2.5.26" // released 10/2019. Version 2.6.0 was released 11/2019

import scala.io.Source
val versionFunc = () => {
val versFile = Source.fromFile("src/main/resources/version.txt")
val versText = versFile.getLines.next()
versFile.close()
versText
}

lazy val root = (project in file(".")).
settings(
//inThisBuild(List( // <- this is to have global settings across multiple sub-projects, but we only have 1 project
organization := "com.horizon",
scalaVersion := "2.12.10", // tried updating to scala 2.13.1, but got many compile errors in intellij related to JavaConverters being deprecated
//)),
name := "Exchange API",
version := versionFunc(),
//version := "2.0.0",
resolvers += Classpaths.typesafeReleases,
lazy val root = (project in file("."))
.settings(
//inThisBuild(List( // <- this is to have global settings across multiple sub-projects, but we only have 1 project
organization := "com.horizon",
scalaVersion := "2.12.10", // tried updating to scala 2.13.1, but got many compile errors in intellij related to JavaConverters being deprecated
//)),
name := "Exchange API",
version := versionFunc(),
//version := "2.0.0",
resolvers += Classpaths.typesafeReleases,

// Sbt uses Ivy for dependency resolution, so it supports its version syntax: http://ant.apache.org/ivy/history/latest-milestone/ivyfile/dependency.html#revision
libraryDependencies ++= Seq(
"com.typesafe.akka" %% "akka-http" % akkaHttpVersion,
"com.typesafe.akka" %% "akka-http-xml" % akkaHttpVersion,
"com.typesafe.akka" %% "akka-stream" % akkaVersion,
//"com.typesafe.akka" %% "akka-http-spray-json" % akkaHttpVersion,
"de.heikoseeberger" %% "akka-http-jackson" % "1.29.1", // version 1.30.0 pulls in akka 2.6.1 and akkahttp 10.1.11
//"com.typesafe.akka" %% "akka-http-jackson" % akkaHttpVersion, <- can not find any recent documentation on how to use this
// Sbt uses Ivy for dependency resolution, so it supports its version syntax: http://ant.apache.org/ivy/history/latest-milestone/ivyfile/dependency.html#revision
libraryDependencies ++= Seq(
"com.typesafe.akka" %% "akka-http" % akkaHttpVersion,
"com.typesafe.akka" %% "akka-http-xml" % akkaHttpVersion,
"com.typesafe.akka" %% "akka-stream" % akkaVersion,
//"com.typesafe.akka" %% "akka-http-spray-json" % akkaHttpVersion,
"de.heikoseeberger" %% "akka-http-jackson" % "1.29.1", // version 1.30.0 pulls in akka 2.6.1 and akkahttp 10.1.11
//"com.typesafe.akka" %% "akka-http-jackson" % akkaHttpVersion, <- can not find any recent documentation on how to use this

"org.json4s" %% "json4s-native" % "latest.release",
"org.json4s" %% "json4s-jackson" % "latest.release",
"org.json4s" %% "json4s-native" % "latest.release",
"org.json4s" %% "json4s-jackson" % "latest.release",

"javax.ws.rs" % "javax.ws.rs-api" % "2.0.1", // this is from 8/2014. Version 2.1.1 from 9/2018 gets an error loading
"org.glassfish.jersey.core" % "jersey-common" % "latest.release", // required at runtime by javax.ws.rs-api
"com.github.swagger-akka-http" %% "swagger-akka-http" % "latest.release", // the 9/2019 versions of these 2 cause incompatible warings,but the 6/2019 versions give exceptions
"com.github.swagger-akka-http" %% "swagger-scala-module" % "latest.release",
"io.swagger.core.v3" % "swagger-core" % "latest.release",
"io.swagger.core.v3" % "swagger-annotations" % "latest.release",
"io.swagger.core.v3" % "swagger-models" % "latest.release",
"io.swagger.core.v3" % "swagger-jaxrs2" % "latest.release",
"javax.ws.rs" % "javax.ws.rs-api" % "2.0.1", // this is from 8/2014. Version 2.1.1 from 9/2018 gets an error loading
"org.glassfish.jersey.core" % "jersey-common" % "latest.release", // required at runtime by javax.ws.rs-api
"com.github.swagger-akka-http" %% "swagger-akka-http" % "latest.release", // the 9/2019 versions of these 2 cause incompatible warings,but the 6/2019 versions give exceptions
"com.github.swagger-akka-http" %% "swagger-scala-module" % "latest.release",
"io.swagger.core.v3" % "swagger-core" % "latest.release",
"io.swagger.core.v3" % "swagger-annotations" % "latest.release",
"io.swagger.core.v3" % "swagger-models" % "latest.release",
"io.swagger.core.v3" % "swagger-jaxrs2" % "latest.release",

"com.typesafe.slick" %% "slick" % "latest.release",
"com.typesafe.slick" %% "slick-hikaricp" % "latest.release",
"com.github.tminglei" %% "slick-pg" % "latest.release",
"com.github.tminglei" %% "slick-pg_json4s" % "latest.release",
"org.postgresql" % "postgresql" % "latest.release",
"com.zaxxer" % "HikariCP" % "latest.release",
"org.slf4j" % "slf4j-api" % "1.7.26", // these 2 seem to be needed by slick
"ch.qos.logback" % "logback-classic" % "1.2.3",
"com.mchange" % "c3p0" % "latest.release",
"org.scalaj" %% "scalaj-http" % "latest.release",
"com.typesafe" % "config" % "latest.release",
"org.mindrot" % "jbcrypt" % "latest.release",
"com.pauldijou" %% "jwt-core" % "latest.release",
"com.github.cb372" %% "scalacache-guava" % "latest.release",
"com.osinka.i18n" %% "scala-i18n" % "latest.release",
"com.typesafe.slick" %% "slick" % "latest.release",
"com.typesafe.slick" %% "slick-hikaricp" % "latest.release",
"com.github.tminglei" %% "slick-pg" % "latest.release",
"com.github.tminglei" %% "slick-pg_json4s" % "latest.release",
"org.postgresql" % "postgresql" % "latest.release",
"com.zaxxer" % "HikariCP" % "latest.release",
"org.slf4j" % "slf4j-api" % "1.7.26", // these 2 seem to be needed by slick
"ch.qos.logback" % "logback-classic" % "1.2.3",
"com.mchange" % "c3p0" % "latest.release",
"org.scalaj" %% "scalaj-http" % "latest.release",
"com.typesafe" % "config" % "latest.release",
"org.mindrot" % "jbcrypt" % "latest.release",
"com.pauldijou" %% "jwt-core" % "latest.release",
"com.github.cb372" %% "scalacache-guava" % "latest.release",
"com.osinka.i18n" %% "scala-i18n" % "latest.release",

"com.typesafe.akka" %% "akka-http-testkit" % akkaHttpVersion % Test,
"com.typesafe.akka" %% "akka-testkit" % akkaVersion % Test,
"com.typesafe.akka" %% "akka-stream-testkit" % akkaVersion % Test,
"com.typesafe.akka" %% "akka-http-testkit" % akkaHttpVersion % Test,
"com.typesafe.akka" %% "akka-testkit" % akkaVersion % Test,
"com.typesafe.akka" %% "akka-stream-testkit" % akkaVersion % Test,

"org.scalatest" %% "scalatest" % "latest.release" % "test",
"org.scalatestplus" %% "junit-4-12" % "latest.release" % "test",
"org.scalacheck" %% "scalacheck" % "latest.release" % "test",
"junit" % "junit" % "latest.release" % "test"
),
scalacOptions ++= Seq("-unchecked", "-deprecation", "-feature"),
//javaOptions ++= Seq("-Djava.security.auth.login.config=src/main/resources/jaas.config", "-Djava.security.policy=src/main/resources/auth.policy")
"org.scalatest" %% "scalatest" % "latest.release" % "test",
"org.scalatestplus" %% "junit-4-12" % "latest.release" % "test",
"org.scalacheck" %% "scalacheck" % "latest.release" % "test",
"junit" % "junit" % "latest.release" % "test"
),
scalacOptions ++= Seq("-unchecked", "-deprecation", "-feature"),
//javaOptions ++= Seq("-Djava.security.auth.login.config=src/main/resources/jaas.config", "-Djava.security.policy=src/main/resources/auth.policy")

// These settings are for the sbt-native-packager plugin building the docker image. See: https://sbt-native-packager.readthedocs.io/en/stable/formats/docker.html
packageName in Docker := "openhorizon/amd64_exchange-api",
daemonUser in Docker := "exchangeuser",
dockerExposedPorts ++= Seq(8080),
dockerBaseImage := "openjdk:8-jre",
dockerEnvVars := Map("JAVA_OPTS" -> "") // this is here so JAVA_OPTS can be overridden on the docker run cmd with a value like: -Xmx1G
//dockerEntrypoint ++= Seq("-Djava.security.auth.login.config=src/main/resources/jaas.config") // <- had trouble getting this to work
)
// These settings are for the sbt-native-packager plugin building the docker image. See: https://sbt-native-packager.readthedocs.io/en/stable/formats/docker.html
packageName in Docker := "openhorizon/amd64_exchange-api",
daemonUser in Docker := "exchangeuser",
daemonGroup in Docker := "exchangegroup",
daemonGroupGid in Docker := some("1001"),
dockerExposedPorts ++= Seq(8080),
dockerBaseImage := "registry.access.redhat.com/ubi8-minimal:latest",
dockerEnvVars := Map("JAVA_OPTS" -> ""), // this is here so JAVA_OPTS can be overridden on the docker run cmd with a value like: -Xmx1G
//dockerEntrypoint ++= Seq("-Djava.security.auth.login.config=src/main/resources/jaas.config") // <- had trouble getting this to work
dockerCommands := Seq(Cmd("FROM", dockerBaseImage.value ++ " as stage0"),
Cmd("LABEL", "snp-multi-stage='intermediate'"),
Cmd("LABEL", "snp-multi-stage-id='6466ecf3-c305-40bb-909a-47e60bded33d'"),
Cmd("WORKDIR", "/opt/docker"),
Cmd("COPY", "1/opt /1/opt"),
Cmd("COPY", "2/opt /2/opt"),
Cmd("USER", "root"),
Cmd("RUN", "chmod -R u=rX,g=rX /1/opt/docker /2/opt/docker && chmod u+x,g+x /1/opt/docker/bin/exchange-api"),
Cmd("FROM", dockerBaseImage.value),
//Cmd("LABEL", "description=''"),
//Cmd("LABEL", "io.k8s.description=''"),
//Cmd("LABEL", "io.k8s.display-name=''"),
//Cmd("LABEL", "io.openshift.tags=''"),
//Cmd("LABEL", "name='openhorizon/amd64_exchange-api'"),
//Cmd("LABEL", "release=''"),
//Cmd("LABEL", "summery=''"),
//Cmd("LABEL", "vendor=''"),
//Cmd("LABEL", "version=''"),
Cmd("RUN", "mkdir -p /run/user/$UID && microdnf update -y --nodocs && microdnf install -y --nodocs shadow-utils java-1.8.0-openjdk && microdnf clean all"),
Cmd("USER", "root"),
Cmd("RUN", "id -u " ++ (daemonUser in Docker).value ++ " 1>/dev/null 2>&1 || ((getent group 1001 1>/dev/null 2>&1 || (type groupadd 1>/dev/null 2>&1 && groupadd -g 1001 " ++ (daemonGroup in Docker).value ++ " || addgroup -g 1001 -S " ++ (daemonGroup in Docker).value ++ ")) && (type useradd 1>/dev/null 2>&1 && useradd --system --create-home --uid 1001 --gid 1001 " ++ (daemonUser in Docker).value ++ " || adduser -S -u 1001 -G " ++ (daemonGroup in Docker).value ++ " " ++ (daemonUser in Docker).value ++ "))"),
Cmd("WORKDIR", "/opt/docker"),
Cmd("COPY --from=stage0 --chown=exchangeuser:exchangegroup", "/1/opt/docker /opt/docker"),
Cmd("COPY --from=stage0 --chown=exchangeuser:exchangegroup", "/2/opt/docker /opt/docker"),
Cmd("COPY --from=stage0 --chown=" ++ (daemonUser in Docker).value ++ ":" ++ (daemonGroup in Docker).value, "/1/opt/docker /opt/docker"),
Cmd("COPY --from=stage0 --chown=" ++ (daemonUser in Docker).value ++ ":" ++ (daemonGroup in Docker).value, "/2/opt/docker /opt/docker"),
Cmd("ENV", "JAVA_OPTS=''"),
Cmd("EXPOSE", "8080"),
Cmd("USER", "1001:1001"),
Cmd("ENTRYPOINT", "/opt/docker/bin/exchange-api"),
Cmd("CMD", "[]")
)
)
2 changes: 1 addition & 1 deletion project/plugins.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
addSbtPlugin("io.spray" % "sbt-revolver" % "0.9.1")

// Builds docker image of our exchange svr
addSbtPlugin("com.typesafe.sbt" % "sbt-native-packager" % "1.5.1")
addSbtPlugin("com.typesafe.sbt" % "sbt-native-packager" % "1.7.0")

// To see the current versions being used, uncomment this line, then run: sbt dependencyTree
//addSbtPlugin("net.virtual-void" % "sbt-dependencpwdy-graph" % "0.8.0")
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.20.0
2.21.0