diff --git a/build.sbt b/build.sbt index 640c1218f..dfdb27093 100644 --- a/build.sbt +++ b/build.sbt @@ -88,7 +88,10 @@ lazy val apiSettings = Seq( name := "api", libraryDependencies ++= apiDependencies ++ apiTestDependencies.map(_ % "test, it"), mainClass := Some("vinyldns.api.Boot"), - javaOptions in reStart += "-Dlogback.configurationFile=test/logback.xml", + javaOptions in reStart ++= Seq( + "-Dlogback.configurationFile=test/logback.xml", + s"""-Dvinyldns.base-version=${(version in ThisBuild).value}""" + ), coverageExcludedPackages := ".*Boot.*" ) @@ -123,6 +126,9 @@ lazy val apiDockerSettings = Seq( // adds config file to mount bashScriptExtraDefines += """addJava "-Dconfig.file=${app_home}/../conf/application.conf"""", bashScriptExtraDefines += """addJava "-Dlogback.configurationFile=${app_home}/../conf/logback.xml"""", // adds logback + + // this is the default version, can be overridden + bashScriptExtraDefines += s"""addJava "-Dvinyldns.base-version=${(version in ThisBuild).value}"""", bashScriptExtraDefines += "(cd ${app_home} && ./wait-for-dependencies.sh && cd -)", credentials in Docker := Seq(Credentials(Path.userHome / ".ivy2" / ".dockerCredentials")), dockerCommands ++= Seq( @@ -148,6 +154,9 @@ lazy val portalDockerSettings = Seq( // adds config file to mount bashScriptExtraDefines += """addJava "-Dconfig.file=/opt/docker/conf/application.conf"""", bashScriptExtraDefines += """addJava "-Dlogback.configurationFile=/opt/docker/conf/logback.xml"""", + + // this is the default version, can be overridden + bashScriptExtraDefines += s"""addJava "-Dvinyldns.base-version=${(version in ThisBuild).value}"""", credentials in Docker := Seq(Credentials(Path.userHome / ".ivy2" / ".dockerCredentials")) ) @@ -332,6 +341,9 @@ lazy val portal = (project in file("modules/portal")).enablePlugins(PlayScala, A routesGenerator := InjectedRoutesGenerator, coverageExcludedPackages := ";views.html.*;router.*", javaOptions in Test += "-Dconfig.file=conf/application-test.conf", + + // ads the version when working locally with sbt run + PlayKeys.devSettings += "vinyldns.base-version" -> (version in ThisBuild).value, // adds an extra classpath to the portal loading so we can externalize jars, make sure to create the lib_extra // directory and lay down any dependencies that are required when deploying diff --git a/modules/api/src/main/resources/reference.conf b/modules/api/src/main/resources/reference.conf index 9de3f3fc6..f370d0b6c 100644 --- a/modules/api/src/main/resources/reference.conf +++ b/modules/api/src/main/resources/reference.conf @@ -40,7 +40,8 @@ vinyldns { color = "green" # version of vinyldns - version = "unknown" + base-version = "unset" + version = ${vinyldns.base-version} # time users have to wait to resync a zone sync-delay = 600000 diff --git a/modules/api/src/test/scala/vinyldns/api/route/StatusRoutingSpec.scala b/modules/api/src/test/scala/vinyldns/api/route/StatusRoutingSpec.scala index 2c7bd59e1..42a0db605 100644 --- a/modules/api/src/test/scala/vinyldns/api/route/StatusRoutingSpec.scala +++ b/modules/api/src/test/scala/vinyldns/api/route/StatusRoutingSpec.scala @@ -50,7 +50,7 @@ class StatusRoutingSpec resultStatus.processingDisabled shouldBe false resultStatus.color shouldBe "blue" resultStatus.keyName shouldBe "vinyldns." - resultStatus.version shouldBe "unknown" + resultStatus.version shouldBe "unset" } } } diff --git a/modules/api/src/universal/conf/application.conf b/modules/api/src/universal/conf/application.conf index bf6c5cdb0..061064f26 100644 --- a/modules/api/src/universal/conf/application.conf +++ b/modules/api/src/universal/conf/application.conf @@ -3,6 +3,11 @@ # own settings vinyldns { + # Should be provided in the start up script via an environment + base-version = "unset" + version = ${vinyldns.base-version} # default to the base version if not overridden + version = ${?VINYLDNS_VERSION} # override the base version via env var + queue.settings.service-endpoint = "http://vinyldns-elasticmq:9324/" # host and port the server binds to. This should not be changed diff --git a/modules/portal/app/controllers/FrontendController.scala b/modules/portal/app/controllers/FrontendController.scala index 57cf6e20b..91452c8f0 100644 --- a/modules/portal/app/controllers/FrontendController.scala +++ b/modules/portal/app/controllers/FrontendController.scala @@ -18,7 +18,7 @@ package controllers import actions.FrontendAction import javax.inject.{Inject, Singleton} -import models.CustomLinks +import models.{CustomLinks, Meta} import org.slf4j.LoggerFactory import play.api.Logger import play.api.mvc._ @@ -40,6 +40,7 @@ class FrontendController @Inject()( private val userAction = Action.andThen(new FrontendAction(userAccountAccessor.get)) implicit lazy val customLinks: CustomLinks = CustomLinks(configuration) + implicit lazy val meta: Meta = Meta(configuration) private val logger = LoggerFactory.getLogger(classOf[FrontendController]) def loginPage(): Action[AnyContent] = Action { implicit request => diff --git a/modules/portal/app/models/Meta.scala b/modules/portal/app/models/Meta.scala new file mode 100644 index 000000000..9c4c35320 --- /dev/null +++ b/modules/portal/app/models/Meta.scala @@ -0,0 +1,24 @@ +/* + * Copyright 2018 Comcast Cable Communications Management, LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package models +import play.api.Configuration + +case class Meta(version: String) +object Meta { + def apply(config: Configuration): Meta = + Meta(config.getOptional[String]("vinyldns.version").getOrElse("unknown")) +} diff --git a/modules/portal/app/views/login.scala.html b/modules/portal/app/views/login.scala.html index dc8a493a5..5e697e199 100644 --- a/modules/portal/app/views/login.scala.html +++ b/modules/portal/app/views/login.scala.html @@ -1,5 +1,5 @@ @import helper.CSRF -@(alertMessage: Option[String] = None)(implicit requestHeader: RequestHeader, customLinks: models.CustomLinks) +@(alertMessage: Option[String] = None)(implicit requestHeader: RequestHeader, customLinks: models.CustomLinks, meta: models.Meta) @@ -42,7 +42,7 @@