summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFabian Mastenbroek <mail.fabianm@gmail.com>2022-03-18 13:34:09 +0100
committerFabian Mastenbroek <mail.fabianm@gmail.com>2022-04-05 13:46:33 +0200
commit6cf097b60366ecb2116f742be4374fcec841a950 (patch)
tree60d28a12e9b900079e095a0bd6c5f7bb2965df10
parentde5b2f7f9178b87ccb941201a5ddba9921cb2fa2 (diff)
build(web/ui): Support building WebJar for OpenDC web UI
This change updates the build process to build a static WebJar out of the OpenDC web UI module. This allows us to embed the UI inside the development distribution of OpenDC for other users to readily deploy it.
-rw-r--r--buildSrc/src/main/kotlin/java-library-conventions.gradle.kts35
-rw-r--r--buildSrc/src/main/kotlin/kotlin-conventions.gradle.kts11
-rw-r--r--opendc-web/opendc-web-ui/build.gradle.kts66
-rw-r--r--opendc-web/opendc-web-ui/next.config.js6
4 files changed, 87 insertions, 31 deletions
diff --git a/buildSrc/src/main/kotlin/java-library-conventions.gradle.kts b/buildSrc/src/main/kotlin/java-library-conventions.gradle.kts
new file mode 100644
index 00000000..d4cc667a
--- /dev/null
+++ b/buildSrc/src/main/kotlin/java-library-conventions.gradle.kts
@@ -0,0 +1,35 @@
+/*
+ * Copyright (c) 2022 AtLarge Research
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+plugins {
+ `java-library`
+}
+
+/* Project configuration */
+repositories {
+ mavenCentral()
+}
+
+java {
+ sourceCompatibility = Libs.jvmTarget
+ targetCompatibility = Libs.jvmTarget
+}
diff --git a/buildSrc/src/main/kotlin/kotlin-conventions.gradle.kts b/buildSrc/src/main/kotlin/kotlin-conventions.gradle.kts
index 20c379a2..5d9ae56e 100644
--- a/buildSrc/src/main/kotlin/kotlin-conventions.gradle.kts
+++ b/buildSrc/src/main/kotlin/kotlin-conventions.gradle.kts
@@ -23,21 +23,12 @@
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
plugins {
- `java-library`
+ id("java-library-conventions")
kotlin("jvm")
id("org.jlleitschuh.gradle.ktlint")
}
/* Project configuration */
-repositories {
- mavenCentral()
-}
-
-java {
- sourceCompatibility = Libs.jvmTarget
- targetCompatibility = Libs.jvmTarget
-}
-
tasks.withType<KotlinCompile>().configureEach {
kotlinOptions.jvmTarget = Libs.jvmTarget.toString()
kotlinOptions.freeCompilerArgs += "-opt-in=kotlin.RequiresOptIn"
diff --git a/opendc-web/opendc-web-ui/build.gradle.kts b/opendc-web/opendc-web-ui/build.gradle.kts
index 9063d0e3..62d71897 100644
--- a/opendc-web/opendc-web-ui/build.gradle.kts
+++ b/opendc-web/opendc-web-ui/build.gradle.kts
@@ -25,10 +25,19 @@ import com.github.gradle.node.yarn.task.YarnTask
description = "Web interface for OpenDC"
plugins {
- java
+ `java-library-conventions`
id("com.github.node-gradle.node")
}
+sourceSets {
+ main {
+ java.srcDir("src")
+ }
+ test {
+ java.srcDir("test")
+ }
+}
+
val lintTask = tasks.register<YarnTask>("lintNext") {
args.set(listOf("lint"))
dependsOn(tasks.yarn)
@@ -37,22 +46,35 @@ val lintTask = tasks.register<YarnTask>("lintNext") {
outputs.upToDateWhen { true }
}
-val buildTask = tasks.register<YarnTask>("buildNext") {
- args.set(listOf("build"))
+tasks.register<YarnTask>("dev") {
+ args.set(listOf("dev"))
dependsOn(tasks.yarn)
inputs.dir(project.fileTree("src"))
inputs.dir("node_modules")
inputs.files("package.json", "next.config.js")
- outputs.dir("${project.buildDir}/build")
+ outputs.upToDateWhen { true }
}
-tasks.register<YarnTask>("dev") {
- args.set(listOf("dev"))
+val buildTask = tasks.register<YarnTask>("buildNext") {
+ args.set(listOf("build"))
+
+ val env = listOf(
+ "NEXT_BASE_PATH",
+ "NEXT_PUBLIC_API_BASE_URL",
+ "NEXT_PUBLIC_SENTRY_DSN",
+ "NEXT_PUBLIC_AUTH0_DOMAIN",
+ "NEXT_PUBLIC_AUTH0_CLIENT_ID",
+ "NEXT_PUBLIC_AUTH0_AUDIENCE",
+ )
+ for (envvar in env) {
+ environment.put(envvar, "%%${envvar}%%")
+ }
+
dependsOn(tasks.yarn)
inputs.dir(project.fileTree("src"))
inputs.dir("node_modules")
inputs.files("package.json", "next.config.js")
- outputs.upToDateWhen { true }
+ outputs.dir(layout.buildDirectory.dir("next"))
}
tasks.register<YarnTask>("start") {
@@ -64,19 +86,25 @@ tasks.register<YarnTask>("start") {
outputs.upToDateWhen { true }
}
-sourceSets {
- java {
- main {
- java.srcDir("src")
- resources.srcDir("public")
- }
+tasks.processResources {
+ dependsOn(buildTask)
+ inputs.dir(project.fileTree("public"))
- test {
- java.srcDir("test")
- }
+ from(layout.buildDirectory.dir("next")) {
+ include("routes-manifest.json")
+ into("META-INF/resources/${project.name}")
+ }
+
+ from(layout.buildDirectory.dir("next/static")) {
+ into("META-INF/resources/${project.name}/static/_next/static")
}
-}
-tasks.test {
- dependsOn(lintTask)
+ from(layout.buildDirectory.dir("next/server/pages")) {
+ include("**/*.html")
+ into("META-INF/resources/${project.name}/pages")
+ }
+
+ from(project.fileTree("public")) {
+ into("META-INF/resources/${project.name}/static")
+ }
}
diff --git a/opendc-web/opendc-web-ui/next.config.js b/opendc-web/opendc-web-ui/next.config.js
index 59341b1f..d8029108 100644
--- a/opendc-web/opendc-web-ui/next.config.js
+++ b/opendc-web/opendc-web-ui/next.config.js
@@ -23,14 +23,16 @@
// PatternFly 4 uses global CSS imports in its distribution files. Therefore,
// we need to transpile the modules before we can use them.
const { withGlobalCss } = require('next-global-css')
+const { PHASE_DEVELOPMENT_SERVER } = require("next/constants");
const withConfig = withGlobalCss()
-module.exports = withConfig({
+module.exports = (phase) => withConfig({
+ basePath: process.env.NEXT_BASE_PATH && '/' + process.env.NEXT_BASE_PATH,
reactStrictMode: true,
experimental: {
eslint: true
},
- distDir: 'build/next',
+ distDir: phase === PHASE_DEVELOPMENT_SERVER ? 'build/next-dev' : 'build/next',
async redirects() {
return [
{