Skip to content

Commit df050b2

Browse files
authored
Prod config (#2)
* Windows deploy config * Switch to openjdk11 and scala 2.12.7
1 parent ffbf86e commit df050b2

20 files changed

+416
-55
lines changed

.travis.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
language: scala
22
scala:
3-
- 2.12.6
3+
- 2.12.7
44
jdk:
5-
- oraclejdk8
5+
- oraclejdk11
66
script: ./.travis.sh
77
skip_cleanup: true

app/AppModule.scala

+8-5
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,23 @@
11
import java.util.concurrent.Executors
22

33
import com.avast.metrics.scalaapi.Monitor
4-
import com.typesafe.config._
54
import com.typesafe.scalalogging.StrictLogging
65
import lib._
76
import monix.execution.Scheduler
87
import monix.execution.schedulers.SchedulerService
98
import net.codingwell.scalaguice.ScalaModule
9+
import play.api.{Configuration, Environment}
1010
import scalikejdbc._
1111
import scalikejdbc.config.DBs
12-
import utils.AllowedApiOrigins
12+
import utils.AllowedWsApiOrigins
1313

1414
import scala.collection.JavaConverters._
1515

16-
class AppModule extends ScalaModule with PropertiesConfiguration with StrictLogging {
17-
private lazy val config = ConfigFactory.load()
16+
class AppModule(environment: Environment, configuration: Configuration)
17+
extends ScalaModule
18+
with PropertiesConfiguration
19+
with StrictLogging {
20+
private val config = configuration.underlying
1821

1922
DBs.setupAll()
2023

@@ -30,7 +33,7 @@ class AppModule extends ScalaModule with PropertiesConfiguration with StrictLogg
3033

3134
val rootMonitor = Monitor.noOp()
3235

33-
bind[AllowedApiOrigins].toInstance(AllowedApiOrigins(config.getStringList("allowedWsApiOrigins").asScala))
36+
bind[AllowedWsApiOrigins].toInstance(AllowedWsApiOrigins(config.getStringList("allowedWsApiOrigins").asScala))
3437

3538
val cloudConnector = CloudConnector.fromConfig(config.getConfig("cloudConnector"))
3639
val dao = new Dao(executorService)

app/controllers/FrontController.scala

+4-7
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,14 @@
11
package controllers
22

3-
import java.io.File
4-
53
import com.google.inject.Inject
6-
import com.typesafe.config.{Config, ConfigFactory}
74
import lib.WebpackBuildFile
85
import play.Environment
96
import play.api.mvc._
7+
import utils.ConfigProperty
108

11-
class FrontController @Inject() (cc: ControllerComponents, env: Environment) extends AbstractController(cc){
12-
val config: Config = ConfigFactory.parseFile(new File("conf/frontend.conf")).resolve()
13-
9+
class FrontController @Inject()(cc: ControllerComponents, env: Environment, @ConfigProperty("webpack.port") port: Int)
10+
extends AbstractController(cc) {
1411
def index = Action {
15-
Ok(views.html.index.render(env, config.getInt("webpack.port"), WebpackBuildFile.jsBundle, WebpackBuildFile.cssBundle))
12+
Ok(views.html.index.render(env, port, WebpackBuildFile.jsBundleName, WebpackBuildFile.cssBundleName))
1613
}
1714
}

app/controllers/SameOriginCheck.scala

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@ package controllers
22

33
import com.typesafe.scalalogging.StrictLogging
44
import play.api.mvc.RequestHeader
5-
import utils.AllowedApiOrigins
5+
import utils.AllowedWsApiOrigins
66

77
// imported from https://github.com/playframework/play-scala-websocket-example
88
trait SameOriginCheck extends StrictLogging {
99

10-
protected def allowedOrigins: AllowedApiOrigins
10+
protected def allowedOrigins: AllowedWsApiOrigins
1111

1212
/**
1313
* Checks that the WebSocket comes from the same origin. This is necessary to protect

app/controllers/WsApiController.scala

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@ import monix.eval.Task
1818
import play.api.libs.circe.Circe
1919
import play.api.libs.streams.ActorFlow
2020
import play.api.mvc._
21-
import utils.AllowedApiOrigins
21+
import utils.AllowedWsApiOrigins
2222

2323
import scala.concurrent.Future
2424
import scala.util.Try
2525

2626
@Singleton
27-
class WsApiController @Inject()(cc: ControllerComponents, protected override val allowedOrigins: AllowedApiOrigins)(
27+
class WsApiController @Inject()(cc: ControllerComponents, protected override val allowedOrigins: AllowedWsApiOrigins)(
2828
implicit system: ActorSystem,
2929
mat: Materializer)
3030
extends AbstractController(cc)

app/lib/WebpackBuildFile.scala

+50-9
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,56 @@
11
package lib
22

3-
import java.io.File
3+
import java.net.URI
4+
import java.nio.file.{FileSystems, Files, Paths}
5+
import java.util
46

5-
object WebpackBuildFile {
6-
private val d = new File("public/bundle")
7-
val jsBundle: String = if (d.exists && d.isDirectory) {
8-
d.listFiles.filter(_.isFile).toList.find(f => f.getName.contains("js.bundle.")).get.getName.replace(".gz", "")
9-
} else ""
7+
import com.typesafe.scalalogging.StrictLogging
108

11-
val cssBundle: String = if (d.exists && d.isDirectory) {
12-
d.listFiles.filter(_.isFile).toList.find(f => f.getName.contains("style.bundle.")).get.getName.replace(".gz", "")
13-
} else ""
9+
import scala.collection.JavaConverters._
10+
11+
object WebpackBuildFile extends StrictLogging {
12+
13+
private val bundleDir = if (Files.exists(Paths.get("public", "bundle"))) {
14+
Paths.get("public", "bundle")
15+
} else {
16+
val uri: URI = getClass.getClassLoader.getResource("public/bundle").toURI
17+
logger.debug(s"Found bundle resources @ $uri")
18+
19+
val uriParts: Array[String] = uri.toString.split("!")
20+
val fs = FileSystems.newFileSystem(URI.create(uriParts.head), new util.HashMap[String, Object]())
21+
fs.getPath(uriParts(1))
22+
}
23+
24+
logger.info(s"Locating built bundle at ${bundleDir.toUri}")
25+
26+
val jsBundleName: String = {
27+
val packedFile = Files
28+
.list(bundleDir)
29+
.iterator()
30+
.asScala
31+
.filter(Files.isRegularFile(_))
32+
.toList
33+
.collectFirst {
34+
case f if f.toString.contains("js.bundle.") && !f.toString.contains("gz") => f
35+
}
36+
.getOrElse(sys.error("Could not locate JS bundle"))
37+
38+
packedFile.getFileName.toString
39+
}
40+
41+
val cssBundleName: String = {
42+
val packedFile = Files
43+
.list(bundleDir)
44+
.iterator()
45+
.asScala
46+
.filter(Files.isRegularFile(_))
47+
.toList
48+
.collectFirst {
49+
case f if f.toString.contains("style.bundle.") && !f.toString.contains("gz") => f
50+
}
51+
.getOrElse(sys.error("Could not locate styles bundle"))
52+
53+
packedFile.getFileName.toString
54+
}
1455

1556
}

app/utils/AllowedApiOrigins.scala

-4
This file was deleted.

app/utils/AllowedWsApiOrigins.scala

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
package utils
2+
3+
case class AllowedWsApiOrigins(values: Seq[String])

build.sbt

+20-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
1+
import java.io.{File, FileOutputStream}
2+
13
import com.typesafe.sbt.packager.MappingsHelper._
4+
import sbtassembly.MergeStrategy
25

36
import scala.sys.process.Process
47

58
lazy val Versions = new {
69
val monix = "3.0.0-RC1"
7-
val http4s = "0.18.15"
10+
val http4s = "0.18.18"
811
val scalikeJdbc = "3.3.1"
912
val metricsVersion = "2.4.4"
1013
}
@@ -15,7 +18,7 @@ name := "rbackup-client"
1518

1619
version := "0.1"
1720

18-
scalaVersion := "2.12.6"
21+
scalaVersion := "2.12.7"
1922

2023
lazy val `rbackup-client` = (project in file(".")).enablePlugins(PlayScala)
2124

@@ -41,6 +44,15 @@ libraryDependencies ++= Seq(
4144
"org.scalatest" %% "scalatest" % "3.0.5" % "test"
4245
)
4346

47+
libraryDependencies ~= {
48+
//noinspection UnnecessaryPartialFunction
49+
_ map {
50+
case m =>
51+
m.exclude("commons-logging", "commons-logging")
52+
.exclude("com.typesafe.play", "sbt-link")
53+
}
54+
}
55+
4456
// Play framework hooks for development
4557
PlayKeys.playRunHooks += WebpackServer(file("./front"))
4658

@@ -70,4 +82,10 @@ frontEndBuild := {
7082

7183
frontEndBuild := (frontEndBuild dependsOn cleanFrontEndBuild).value
7284

85+
sources in (Compile,doc) := Seq.empty
86+
publishArtifact in (Compile, packageDoc) := false
87+
7388
dist := (dist dependsOn frontEndBuild).value
89+
90+
PlayKeys.playDefaultPort := 3370
91+
PlayKeys.devSettings := Seq("play.server.http.port" -> "3370")

conf/application.conf

-9
This file was deleted.

conf/reference.conf

+15-9
Original file line numberDiff line numberDiff line change
@@ -15,26 +15,32 @@ fileHandler {
1515
retries = 2
1616
}
1717

18-
allowedWsApiOrigins = ["http://localhost:9000", "https://www.websocket.org"]
18+
allowedWsApiOrigins = ["http://localhost:3370"]
1919

20-
play.filters.hosts {
21-
# Allow requests to localhost:9000.
22-
allowed=["localhost:9000","127.0.0.1:9000"]
20+
play.filters {
21+
headers.contentSecurityPolicy = "font-src 'https://fonts.googleapis.com'; img-src 'self'; style-src 'self' https://use.fontawesome.com"
22+
23+
hosts {
24+
allowed = ["localhost:3370", "127.0.0.1:3370", "localhost:3370", "127.0.0.1:3370"]
25+
}
2326
}
2427

25-
play.http.secret.key="%APPLICATION_SECRET%"
28+
play.http.secret.key = "%APPLICATION_SECRET%"
2629

27-
play.i18n.langs=["cs"]
30+
play.i18n.langs = ["cs"]
2831

29-
play.filters.enabled=[play.filters.hosts.AllowedHostsFilter]
32+
play.filters.enabled = [play.filters.hosts.AllowedHostsFilter]
3033

3134
play.modules.enabled += "AppModule"
3235

36+
webpack.port = 8080
37+
38+
dbFilePath = "./filecache"
3339

3440
# JDBC settings
3541
db.default.driver = "org.h2.Driver"
36-
db.default.url = "jdbc:h2:file:./filecache"
37-
db.default.user = "rbackup"
42+
db.default.url = "jdbc:h2:file:"${dbFilePath}
43+
db.default.username = "rbackup"
3844
db.default.password = "secretPass"
3945

4046
# Connection Pool settings

front/sass/style.scss

-1
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,4 @@ html, body {
33
}
44

55
@import "variables.scss";
6-
@import "~bootstrap/scss/bootstrap.scss";
76
@import "~vue-snotify/styles/material";

front/src/components/App.vue

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
</div>
1717
</div>
1818

19-
<vue-snotify></vue-snotify>
19+
<vue-snotify/>
2020
</v-app>
2121

2222
</template>
@@ -34,7 +34,7 @@
3434
},
3535
data() {
3636
return {
37-
hostUrl: "localhost:9000",
37+
hostUrl: "localhost:3370",
3838
clientStatus: null,
3939
}
4040
},

front/src/main.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import Vue from 'vue';
22
import App from './components/App.vue';
33
import Vuetify from 'vuetify'
44
import '../sass/style.scss';
5-
import Snotify, { SnotifyPosition } from 'vue-snotify'
5+
import Snotify, { SnotifyPosition } from 'vue-snotify/vue-snotify.min.js'
66

77
const options = {
88
toast: {

front/webpack.production.config.js

+70
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
'use strict';
2+
3+
const path = require('path');
4+
const webpack = require('webpack');
5+
const ExtractTextPlugin = require("extract-text-webpack-plugin");
6+
const OptimizeCssAssetsPlugin = require('optimize-css-assets-webpack-plugin');
7+
const CompressionPlugin = require('compression-webpack-plugin');
8+
9+
module.exports = {
10+
entry: path.resolve('./src/main.js'),
11+
output: {
12+
path: path.resolve('../public/bundle'),
13+
filename: 'js.bundle.[hash].js'
14+
},
15+
module: {
16+
rules: [
17+
{
18+
test: /\.js$/,
19+
loader: 'babel-loader',
20+
exclude: /node_modules/
21+
},
22+
{
23+
test: /\.vue$/,
24+
loader: 'vue-loader',
25+
options: {
26+
}
27+
},
28+
{
29+
test: /\.s[a|c]ss$/,
30+
use: ExtractTextPlugin.extract({
31+
fallback: 'style-loader',
32+
use: ['css-loader', 'sass-loader']
33+
})
34+
},
35+
{
36+
test: /\.css$/,
37+
use: [
38+
'style-loader',
39+
'css-loader'
40+
]
41+
},
42+
{
43+
test: /\.(png|jpg|gif|svg)$/,
44+
loader: 'file-loader',
45+
options: {
46+
name: '[name].[ext]?[hash]'
47+
}
48+
}
49+
]
50+
},
51+
plugins:[
52+
new webpack.DefinePlugin({
53+
'process.env.NODE_ENV': JSON.stringify('production')
54+
}),
55+
new webpack.optimize.UglifyJsPlugin({
56+
sourceMap: true
57+
}),
58+
new ExtractTextPlugin("style.bundle.[contentHash].css"),
59+
new OptimizeCssAssetsPlugin({
60+
cssProcessor: require('cssnano'),
61+
cssProcessorOptions: { discardComments: {removeAll: true } }
62+
}),
63+
new CompressionPlugin({
64+
asset: "[path].gz[query]",
65+
test: /\.(js|css)$/,
66+
minRatio: 0.8,
67+
deleteOriginalAssets: false
68+
})
69+
]
70+
};

project/plugins.sbt

+1
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ logLevel := Level.Warn
33
resolvers += "Typesafe repository" at "http://repo.typesafe.com/typesafe/releases/"
44

55
addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.6.17")
6+
addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.14.8")

windeploy/RBACKUP_CLIENT_CONFIG

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
-Xmx1024m

0 commit comments

Comments
 (0)