-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
25,426 additions
and
9,212 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
node_modules | ||
build | ||
.gradle |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
FROM openjdk:11 | ||
RUN apt-get update; \ | ||
apt-get install -y iptables curl npm | ||
COPY . /app |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,72 +1,109 @@ | ||
# Vaadin Gradle Skeleton Starter Spring Boot | ||
# Demonstrator for Vaadin Flow Issue [#13624](https://github.com/vaadin/flow/issues/13624) | ||
|
||
This project demos the possibility of having Vaadin project in npm+webpack mode using Gradle. | ||
Please see the [Starting a Vaadin project using Gradle](https://vaadin.com/docs/latest/guide/start/gradle) for the documentation. | ||
If a http proxy is required to build a Vaadin app, the build will fail. | ||
|
||
This demonstrator tries to build the app in a Docker container, which prevents outbound network traffic on port 80 and 443, but uses a squid proxy as an http proxy. | ||
|
||
Prerequisites: | ||
* Java 8 or higher | ||
* node.js and npm. Vaadin Gradle plugin will install those for you | ||
automatically (handy for CI), or you can install it to your OS: | ||
* Windows: [node.js Download site](https://nodejs.org/en/download/) - use the .msi 64-bit installer | ||
* Linux: `sudo apt install npm` | ||
* Git | ||
* (Optionally): Intellij Community | ||
The proxy is configured in [gradle.properties](gradle.properties) and [.npmrc](.npmrc). | ||
|
||
## Vaadin Versions | ||
To start the build, just run `docker compose up --build` (due to very slow bind mounts on macOS, I'm not using them 😟). | ||
|
||
* The [v14](https://github.com/vaadin/base-starter-spring-gradle) branch (the default one) | ||
contains the example app for Vaadin 14 | ||
* The [master](https://github.com/vaadin/base-starter-spring-gradle/tree/master) branch | ||
contains the example app for Vaadin 19 | ||
It will fail due to an error thrown by `esbuild`: | ||
|
||
## Running With Spring Boot via Gradle In Development Mode | ||
|
||
Run the following command in this repo: | ||
|
||
```bash | ||
./gradlew clean bootRun | ||
``` | ||
|
||
Now you can open the [http://localhost:8080](http://localhost:8080) with your browser. | ||
|
||
## Running With Spring Boot from your IDE In Development Mode | ||
|
||
Run the following command in this repo, to create necessary Vaadin config files: | ||
|
||
```bash | ||
./gradlew clean vaadinPrepareFrontend | ||
``` | ||
|
||
The `build/vaadin-generated/` folder will now contain proper configuration files. | ||
|
||
Open the `DemoApplication` class, and Run/Debug its main method from your IDE. | ||
|
||
Now you can open the [http://localhost:8080](http://localhost:8080) with your browser. | ||
|
||
## Building In Production Mode | ||
|
||
Run the following command in this repo: | ||
|
||
```bash | ||
./gradlew clean build -Pvaadin.productionMode | ||
``` | ||
|
||
That will build this app in production mode as a runnable jar archive; please find the jar file in `build/libs/base-starter-spring-gradle*.jar`. | ||
You can run the JAR file with: | ||
|
||
```bash | ||
cd build/libs/ | ||
java -jar base-starter-spring-gradle*.jar | ||
vaadin-issue13624-openjdk-1 | > Task :vaadinBuildFrontend FAILED | ||
vaadin-issue13624-openjdk-1 | | ||
vaadin-issue13624-openjdk-1 | FAILURE: Build failed with an exception. | ||
vaadin-issue13624-openjdk-1 | | ||
vaadin-issue13624-openjdk-1 | * What went wrong: | ||
vaadin-issue13624-openjdk-1 | Execution failed for task ':vaadinBuildFrontend'. | ||
vaadin-issue13624-openjdk-1 | > Webpack process exited with non-zero exit code. | ||
vaadin-issue13624-openjdk-1 | Stderr: '/app/node_modules/esbuild/bin/esbuild:2 | ||
vaadin-issue13624-openjdk-1 | throw new Error(`esbuild: Failed to install correctly | ||
vaadin-issue13624-openjdk-1 | ^ | ||
vaadin-issue13624-openjdk-1 | | ||
vaadin-issue13624-openjdk-1 | Error: esbuild: Failed to install correctly | ||
vaadin-issue13624-openjdk-1 | | ||
vaadin-issue13624-openjdk-1 | Make sure you don't have "ignore-scripts" set to true. You can check this with | ||
vaadin-issue13624-openjdk-1 | "npm config get ignore-scripts". If that returns true you can reset it back to | ||
vaadin-issue13624-openjdk-1 | false using "npm config set ignore-scripts false" and then reinstall esbuild. | ||
vaadin-issue13624-openjdk-1 | | ||
vaadin-issue13624-openjdk-1 | If you're using npm v7, make sure your package-lock.json file contains either | ||
vaadin-issue13624-openjdk-1 | "lockfileVersion": 1 or the code "hasInstallScript": true. If it doesn't have | ||
vaadin-issue13624-openjdk-1 | either of those, then it is likely the case that a known bug in npm v7 has | ||
vaadin-issue13624-openjdk-1 | corrupted your package-lock.json file. Regenerating your package-lock.json file | ||
vaadin-issue13624-openjdk-1 | should fix this issue. | ||
vaadin-issue13624-openjdk-1 | | ||
vaadin-issue13624-openjdk-1 | at Object.<anonymous> (/app/node_modules/esbuild/bin/esbuild:2:7) | ||
vaadin-issue13624-openjdk-1 | at Module._compile (node:internal/modules/cjs/loader:1103:14) | ||
vaadin-issue13624-openjdk-1 | at Object.Module._extensions..js (node:internal/modules/cjs/loader:1157:10) | ||
vaadin-issue13624-openjdk-1 | at Module.load (node:internal/modules/cjs/loader:981:32) | ||
vaadin-issue13624-openjdk-1 | at Function.Module._load (node:internal/modules/cjs/loader:822:12) | ||
vaadin-issue13624-openjdk-1 | at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:77:12) | ||
vaadin-issue13624-openjdk-1 | at node:internal/main/run_main_module:17:47 | ||
vaadin-issue13624-openjdk-1 | Hash: 29fa358a62132e0349d8 | ||
vaadin-issue13624-openjdk-1 | Version: webpack 4.46.0 | ||
vaadin-issue13624-openjdk-1 | Time: 12602ms | ||
vaadin-issue13624-openjdk-1 | Built at: 04/26/2022 7:18:18 PM | ||
vaadin-issue13624-openjdk-1 | Asset Size Chunks Chunk Names | ||
vaadin-issue13624-openjdk-1 | VAADIN/build/vaadin-bundle-446c1fbd4a644a93c8e8.cache.js 1.38 KiB 0 [immutable] bundle | ||
vaadin-issue13624-openjdk-1 | sw.js 1.38 KiB | ||
vaadin-issue13624-openjdk-1 | Entrypoint bundle = VAADIN/build/vaadin-bundle-446c1fbd4a644a93c8e8.cache.js | ||
vaadin-issue13624-openjdk-1 | [0] ./generated/vaadin.ts 482 bytes {0} [built] [failed] [1 error] | ||
vaadin-issue13624-openjdk-1 | | ||
vaadin-issue13624-openjdk-1 | ERROR in ./generated/vaadin.ts | ||
vaadin-issue13624-openjdk-1 | Module build failed (from ../node_modules/esbuild-loader/dist/index.js): | ||
vaadin-issue13624-openjdk-1 | Error: The service was stopped | ||
vaadin-issue13624-openjdk-1 | at /app/node_modules/esbuild/lib/main.js:1258:29 | ||
vaadin-issue13624-openjdk-1 | at /app/node_modules/esbuild/lib/main.js:611:9 | ||
vaadin-issue13624-openjdk-1 | at Socket.afterClose (/app/node_modules/esbuild/lib/main.js:589:7) | ||
vaadin-issue13624-openjdk-1 | at Socket.emit (node:events:538:35) | ||
vaadin-issue13624-openjdk-1 | at endReadableNT (node:internal/streams/readable:1345:12) | ||
vaadin-issue13624-openjdk-1 | at processTicksAndRejections (node:internal/process/task_queues:83:21) | ||
vaadin-issue13624-openjdk-1 | | ||
vaadin-issue13624-openjdk-1 | ERROR in ../build/sw.ts | ||
vaadin-issue13624-openjdk-1 | Module build failed (from ../node_modules/esbuild-loader/dist/index.js): | ||
vaadin-issue13624-openjdk-1 | Error: The service was stopped | ||
vaadin-issue13624-openjdk-1 | at /app/node_modules/esbuild/lib/main.js:1258:29 | ||
vaadin-issue13624-openjdk-1 | at /app/node_modules/esbuild/lib/main.js:611:9 | ||
vaadin-issue13624-openjdk-1 | at Socket.afterClose (/app/node_modules/esbuild/lib/main.js:589:7) | ||
vaadin-issue13624-openjdk-1 | at Socket.emit (node:events:538:35) | ||
vaadin-issue13624-openjdk-1 | at endReadableNT (node:internal/streams/readable:1345:12) | ||
vaadin-issue13624-openjdk-1 | at processTicksAndRejections (node:internal/process/task_queues:83:21) | ||
vaadin-issue13624-openjdk-1 | Child HtmlWebpackCompiler: | ||
vaadin-issue13624-openjdk-1 | Asset Size Chunks Chunk Names | ||
vaadin-issue13624-openjdk-1 | __child-HtmlWebpackPlugin_0 4.31 KiB 0 HtmlWebpackPlugin_0 | ||
vaadin-issue13624-openjdk-1 | Entrypoint HtmlWebpackPlugin_0 = __child-HtmlWebpackPlugin_0 | ||
vaadin-issue13624-openjdk-1 | [0] ../node_modules/html-webpack-plugin/lib/loader.js!./index.html 740 bytes {0} [built] | ||
vaadin-issue13624-openjdk-1 | Child InjectManifest: | ||
vaadin-issue13624-openjdk-1 | Asset Size Chunks Chunk Names | ||
vaadin-issue13624-openjdk-1 | sw.js 1.38 KiB 0 InjectManifest | ||
vaadin-issue13624-openjdk-1 | Entrypoint InjectManifest = sw.js | ||
vaadin-issue13624-openjdk-1 | [0] ../build/sw.ts 482 bytes {0} [built] [failed] [1 error] | ||
vaadin-issue13624-openjdk-1 | | ||
vaadin-issue13624-openjdk-1 | ERROR in ../build/sw.ts | ||
vaadin-issue13624-openjdk-1 | Module build failed (from ../node_modules/esbuild-loader/dist/index.js): | ||
vaadin-issue13624-openjdk-1 | Error: The service was stopped | ||
vaadin-issue13624-openjdk-1 | at /app/node_modules/esbuild/lib/main.js:1258:29 | ||
vaadin-issue13624-openjdk-1 | at /app/node_modules/esbuild/lib/main.js:611:9 | ||
vaadin-issue13624-openjdk-1 | at Socket.afterClose (/app/node_modules/esbuild/lib/main.js:589:7) | ||
vaadin-issue13624-openjdk-1 | at Socket.emit (node:events:538:35) | ||
vaadin-issue13624-openjdk-1 | at endReadableNT (node:internal/streams/readable:1345:12) | ||
vaadin-issue13624-openjdk-1 | at processTicksAndRejections (node:internal/process/task_queues:83:21) | ||
vaadin-issue13624-openjdk-1 | <i> [build-status] 2 errors and 0 warnings were reported. | ||
vaadin-issue13624-openjdk-1 | <i> [build-status] : Failed to compile. | ||
vaadin-issue13624-openjdk-1 | ' | ||
vaadin-issue13624-openjdk-1 | | ||
vaadin-issue13624-openjdk-1 | * Try: | ||
vaadin-issue13624-openjdk-1 | > Run with --stacktrace option to get the stack trace. | ||
vaadin-issue13624-openjdk-1 | > Run with --info or --debug option to get more log output. | ||
vaadin-issue13624-openjdk-1 | 4 actionable tasks: 3 executed, 1 up-to-date | ||
vaadin-issue13624-openjdk-1 | > Run with --scan to get full insights. | ||
vaadin-issue13624-openjdk-1 | | ||
vaadin-issue13624-openjdk-1 | * Get more help at https://help.gradle.org | ||
vaadin-issue13624-openjdk-1 | | ||
vaadin-issue13624-openjdk-1 | BUILD FAILED in 1m 27s | ||
vaadin-issue13624-openjdk-1 exited with code 1 | ||
``` | ||
|
||
Now you can open the [http://localhost:8080](http://localhost:8080) with your browser. | ||
|
||
### Building In Production On CI | ||
|
||
Usually the CI images will not have node.js+npm available. However, Vaadin Gradle Plugin will download it for you automatically, there is no need for you to do anything. | ||
To build your app for production in CI, just run: | ||
|
||
```bash | ||
./gradlew clean build -Pvaadin.productionMode | ||
``` | ||
The issue is, that the when the postinstall script from `node_modules/esbuild/package.json` is called by Vaadin's Gradle plugin, neither the http-proxy environment variables nor an npm config located in `node_modules/esbuild/.npmrc`, `~/.npmrc` or `/etc/npmrc` are respected. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#!/usr/bin/env bash | ||
set -x | ||
|
||
export | ||
|
||
iptables -A OUTPUT -p tcp --dport 443 -j DROP | ||
iptables -A OUTPUT -p tcp --dport 80 -j DROP | ||
|
||
# Uncomment, if an interactive session into the docker container is needed: | ||
#tail -f /dev/null | ||
|
||
# None of them works for the Gradle build: | ||
#mkdir -p node_modules/esbuild && cp .npmrc /node_modules/esbuild/.npmrc | ||
#cp .npmrc ~/.npmrc | ||
#cp .npmrc /etc/npmrc | ||
|
||
./gradlew -Pvaadin.productionMode=true --info build | ||
|
||
# This works (as npm seems to respect the http(s)_proxy env variables), | ||
# so the issue has to be related to Vaadin's Gradle plugin. | ||
# It fails with an timeout if neither the http(s)_proxy env variables nor an npm config | ||
# is available. | ||
#npm --ignore-scripts install | ||
#ls -l node_modules/ | ||
#cd node_modules/esbuild | ||
#npm run postinstall | ||
#./bin/esbuild | ||
|
||
#tail -f /dev/null |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
--- | ||
version: "3" | ||
|
||
services: | ||
openjdk: | ||
build: . | ||
environment: | ||
- https_proxy=http://squid:3128 | ||
- http_proxy=http://squid:3128 | ||
working_dir: /app | ||
command: ./build.sh | ||
cap_add: | ||
- NET_ADMIN | ||
|
||
squid: | ||
image: ubuntu/squid:5.2-22.04_beta | ||
ports: | ||
- 3128:3128 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,5 @@ | ||
vaadinVersion=23.0.7 | ||
systemProp.http.proxyHost=squid | ||
systemProp.http.proxyPort=3128 | ||
systemProp.https.proxyHost=squid | ||
systemProp.https.proxyPort=3128 |
Oops, something went wrong.