From 7515cfd84e6c7d3f355f11b744ee7979f6bb663a Mon Sep 17 00:00:00 2001 From: Tim Schlagenhaufer Date: Thu, 9 Dec 2021 19:08:34 +0100 Subject: [PATCH 1/9] Add runtime variables for frontend via container Signed-off-by: Tim Schlagenhaufer --- Dockerfile | 8 +++++++- frontend/.eslintignore | 1 + frontend/.eslintrc.js | 1 + frontend/.prettierignore | 1 + frontend/public/env.js | 12 ++++++++++++ frontend/public/index.html | 1 + frontend/setup-runtime.sh | 19 +++++++++++++++++++ 7 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 frontend/public/env.js create mode 100644 frontend/setup-runtime.sh diff --git a/Dockerfile b/Dockerfile index 81343f31c..1f0623f0a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -28,5 +28,11 @@ RUN mvn clean package -DskipTests=true -Dspotbugs.skip=true -Dpmd.skip=true FROM amazoncorretto:17-alpine COPY --from=MAVEN /home/maven/business-partner-agent/target/business-partner-agent*SNAPSHOT.jar business-partner-agent.jar +# Overwrite frontend runtime variables +RUN mkdir public +COPY --from=VUE /frontend/dist/env.js /public/env.js +COPY --from=VUE /frontend/setup-runtime.sh setup-runtime.sh +RUN ["chmod", "a+x", "./setup-runtime.sh"] + EXPOSE 8080 -CMD java -XX:+UnlockExperimentalVMOptions -Dcom.sun.management.jmxremote ${JAVA_OPTS} -jar business-partner-agent.jar +ENTRYPOINT ./setup-runtime.sh public/env.js business-partner-agent.jar && java -XX:+UnlockExperimentalVMOptions -Dcom.sun.management.jmxremote ${JAVA_OPTS} -jar business-partner-agent.jar diff --git a/frontend/.eslintignore b/frontend/.eslintignore index d9fbc8df0..bae29bcd1 100644 --- a/frontend/.eslintignore +++ b/frontend/.eslintignore @@ -7,5 +7,6 @@ **/*.scss **/*.sass **/*.html +**/*.sh node_modules dist diff --git a/frontend/.eslintrc.js b/frontend/.eslintrc.js index 0f35c6269..03474eef5 100644 --- a/frontend/.eslintrc.js +++ b/frontend/.eslintrc.js @@ -31,6 +31,7 @@ module.exports = { "vue/comment-directive": "warn", "unicorn/prefer-module": "off", "unicorn/filename-case": "off", + "unicorn/prevent-abbreviations": "off", "@typescript-eslint/ban-ts-comment": "warn", }, }; diff --git a/frontend/.prettierignore b/frontend/.prettierignore index e2a6e94da..e377552aa 100644 --- a/frontend/.prettierignore +++ b/frontend/.prettierignore @@ -5,3 +5,4 @@ # SPDX-License-Identifier: Apache-2.0 dist node_modules +setup-runtime.sh diff --git a/frontend/public/env.js b/frontend/public/env.js new file mode 100644 index 000000000..909fff907 --- /dev/null +++ b/frontend/public/env.js @@ -0,0 +1,12 @@ +/* + * Copyright (c) 2020-2021 - for information on the respective copyright owner + * see the NOTICE file and/or the repository at + * https://github.com/hyperledger-labs/business-partner-agent + * + * SPDX-License-Identifier: Apache-2.0 + */ +// Runtime variables - values must have '__' prefix and suffix - no secret values +window.env = { + SIDEBAR_CLOSE_ON_STARTUP: "__SIDEBAR_CLOSE_ON_STARTUP__", + SIDEBAR_HIDE_BURGER_BUTTON: "__SIDEBAR_HIDE_BURGER_BUTTON__", +}; diff --git a/frontend/public/index.html b/frontend/public/index.html index de35f8c8a..fed5f9d4f 100644 --- a/frontend/public/index.html +++ b/frontend/public/index.html @@ -12,6 +12,7 @@ + Loading... diff --git a/frontend/setup-runtime.sh b/frontend/setup-runtime.sh new file mode 100644 index 000000000..3ee7fb199 --- /dev/null +++ b/frontend/setup-runtime.sh @@ -0,0 +1,19 @@ +#!/bin/sh +# Copyright (c) 2020-2021 - for information on the respective copyright owner +# see the NOTICE file and/or the repository at +# https://github.com/hyperledger-labs/business-partner-agent +# +# SPDX-License-Identifier: Apache-2.0 + +# First argument: Path to env.js which needs to be modified +# Second argument: Path to BPA jar file to replace env.js +echo "Start setting runtime variables" + +# Overwrite frontend runtime variables with environment variables from container +sed -i 's#__SIDEBAR_CLOSE_ON_STARTUP__#'"$SIDEBAR_CLOSE_ON_STARTUP"'#g' "$1" +sed -i 's#__SIDEBAR_HIDE_BURGER_BUTTON__#'"$SIDEBAR_HIDE_BURGER_BUTTON"'#g' "$1" + +# Overwrite env.js in given jar file (path) +jar uf "$2" "$1" + +echo "Finish setting runtime variables" From 99895b64216878ccf66957f094233830a81b74d3 Mon Sep 17 00:00:00 2001 From: Tim Schlagenhaufer Date: Fri, 10 Dec 2021 15:19:32 +0100 Subject: [PATCH 2/9] Update build Dockerfile to support runtime variables Signed-off-by: Tim Schlagenhaufer --- Dockerfile | 17 +++++++++++------ Dockerfile.run | 19 ++++++++++++++++--- 2 files changed, 27 insertions(+), 9 deletions(-) diff --git a/Dockerfile b/Dockerfile index 1f0623f0a..bd786e9ec 100644 --- a/Dockerfile +++ b/Dockerfile @@ -26,13 +26,18 @@ RUN mvn clean package -DskipTests=true -Dspotbugs.skip=true -Dpmd.skip=true # Runtime Container FROM amazoncorretto:17-alpine -COPY --from=MAVEN /home/maven/business-partner-agent/target/business-partner-agent*SNAPSHOT.jar business-partner-agent.jar -# Overwrite frontend runtime variables -RUN mkdir public -COPY --from=VUE /frontend/dist/env.js /public/env.js +# Setup rights for overwriting frontend runtime variables COPY --from=VUE /frontend/setup-runtime.sh setup-runtime.sh -RUN ["chmod", "a+x", "./setup-runtime.sh"] + +RUN \ + mkdir public && \ + chmod a+x ./setup-runtime.sh && \ + chmod -R a+rw ./public + +COPY --from=VUE /frontend/dist/env.js ./public/env.js +COPY --from=MAVEN /home/maven/business-partner-agent/target/business-partner-agent*SNAPSHOT.jar business-partner-agent.jar + EXPOSE 8080 -ENTRYPOINT ./setup-runtime.sh public/env.js business-partner-agent.jar && java -XX:+UnlockExperimentalVMOptions -Dcom.sun.management.jmxremote ${JAVA_OPTS} -jar business-partner-agent.jar +CMD ./setup-runtime.sh public/env.js business-partner-agent.jar && java -XX:+UnlockExperimentalVMOptions -Dcom.sun.management.jmxremote ${JAVA_OPTS} -jar business-partner-agent.jar diff --git a/Dockerfile.run b/Dockerfile.run index 695cf9761..e5265306c 100644 --- a/Dockerfile.run +++ b/Dockerfile.run @@ -3,10 +3,23 @@ FROM adoptopenjdk/openjdk15:alpine RUN adduser --disabled-password app + +WORKDIR /home/app + +# Setup rights for overwriting frontend runtime variables +COPY ./frontend/setup-runtime.sh setup-runtime.sh + +RUN \ + mkdir public && \ + chmod a+x ./setup-runtime.sh && \ + chmod -R a+rw ./public + +# Non-root USER app WORKDIR /home/app -EXPOSE 8080 -CMD java -XX:+UnlockExperimentalVMOptions -Dcom.sun.management.jmxremote ${JAVA_OPTS} -jar business-partner-agent.jar +COPY ./frontend/dist/env.js ./public/env.js +COPY ./backend/business-partner-agent/target/business-partner-agent*.jar business-partner-agent.jar -COPY ./backend/business-partner-agent/target/business-partner-agent*.jar business-partner-agent.jar \ No newline at end of file +EXPOSE 8080 +CMD ./setup-runtime.sh public/env.js business-partner-agent.jar && java -XX:+UnlockExperimentalVMOptions -Dcom.sun.management.jmxremote ${JAVA_OPTS} -jar business-partner-agent.jar From c65c6a06b548b69491609438a744d49441a70d74 Mon Sep 17 00:00:00 2001 From: Tim Schlagenhaufer Date: Mon, 13 Dec 2021 12:33:07 +0100 Subject: [PATCH 3/9] Disable reopening of sidebar on screen size change when variable is set + typings Signed-off-by: Tim Schlagenhaufer --- frontend/license-header/config.json | 2 +- frontend/license-header/license-header | 2 +- frontend/package-lock.json | 83 -------------------------- frontend/src/App.vue | 17 +++++- frontend/src/utils/textUtils.ts | 12 ++++ frontend/src/window-env.d.ts | 19 ++++++ 6 files changed, 47 insertions(+), 88 deletions(-) create mode 100644 frontend/src/window-env.d.ts diff --git a/frontend/license-header/config.json b/frontend/license-header/config.json index 9ee911227..ddb7bc809 100644 --- a/frontend/license-header/config.json +++ b/frontend/license-header/config.json @@ -1,7 +1,7 @@ { "ignore": ["**/*.md", "**/*.svg", "license-header/license-header"], "license": "license-header/license-header", - "regexIdentifier": "##", + "regexIdentifier": "_!##", "defaultFormat": { "eachLine": { "prepend": "# " diff --git a/frontend/license-header/license-header b/frontend/license-header/license-header index ac88bcbb8..e9f766809 100644 --- a/frontend/license-header/license-header +++ b/frontend/license-header/license-header @@ -1,4 +1,4 @@ -Copyright (c) 2020-##[0-9]{4}## - for information on the respective copyright owner +Copyright (c) 2020-_!##[0-9]{4}_!## - for information on the respective copyright owner see the NOTICE file and/or the repository at https://github.com/hyperledger-labs/business-partner-agent diff --git a/frontend/package-lock.json b/frontend/package-lock.json index eb9920293..1cf247891 100644 --- a/frontend/package-lock.json +++ b/frontend/package-lock.json @@ -11257,58 +11257,6 @@ "yargs": "^13.3.0" }, "dependencies": { - "@nodelib/fs.stat": { - "version": "2.0.5", - "resolved": "https://registry.npmjs.org/@nodelib/fs.stat/-/fs.stat-2.0.5.tgz", - "integrity": "sha512-RkhPPp2zrqDAQA/2jNhnztcPAlv64XdhIp7a7454A5ovI7Bukxgt7MX7udwAu3zg1DcpPU0rz3VV1SeaqvY4+A==", - "dev": true - }, - "array-union": { - "version": "2.1.0", - "resolved": "https://registry.npmjs.org/array-union/-/array-union-2.1.0.tgz", - "integrity": "sha512-HGyxoOTYUyCM6stUe6EJgnd4EoewAI7zMdfqO+kGjnlZmBDz/cR5pf8r/cR4Wq60sL/p0IkcjUEEPwS3GFrIyw==", - "dev": true - }, - "braces": { - "version": "3.0.2", - "resolved": "https://registry.npmjs.org/braces/-/braces-3.0.2.tgz", - "integrity": "sha512-b8um+L1RzM3WDSzvhm6gIz1yfTbBt6YTlcEKAvsmqCZZFw46z626lVj9j1yEPW33H5H+lBQpZMP1k8l+78Ha0A==", - "dev": true, - "requires": { - "fill-range": "^7.0.1" - } - }, - "dir-glob": { - "version": "3.0.1", - "resolved": "https://registry.npmjs.org/dir-glob/-/dir-glob-3.0.1.tgz", - "integrity": "sha512-WkrWp9GR4KXfKGYzOLmTuGVi1UWFfws377n9cc55/tb6DuqyF6pcQ5AbiHEshaDpY9v6oaSr2XCDidGmMwdzIA==", - "dev": true, - "requires": { - "path-type": "^4.0.0" - } - }, - "fast-glob": { - "version": "3.2.7", - "resolved": "https://registry.npmjs.org/fast-glob/-/fast-glob-3.2.7.tgz", - "integrity": "sha512-rYGMRwip6lUMvYD3BTScMwT1HtAs2d71SMv66Vrxs0IekGZEjhM0pcMfjQPnknBt2zeCwQMEupiN02ZP4DiT1Q==", - "dev": true, - "requires": { - "@nodelib/fs.stat": "^2.0.2", - "@nodelib/fs.walk": "^1.2.3", - "glob-parent": "^5.1.2", - "merge2": "^1.3.0", - "micromatch": "^4.0.4" - } - }, - "fill-range": { - "version": "7.0.1", - "resolved": "https://registry.npmjs.org/fill-range/-/fill-range-7.0.1.tgz", - "integrity": "sha512-qOo9F+dMUmC2Lcb4BbVvnKJxTPjCm+RRpe4gDuGrzkL7mEVl/djYSu2OdQ2Pa302N4oqkSg9ir6jaLWJ2USVpQ==", - "dev": true, - "requires": { - "to-regex-range": "^5.0.1" - } - }, "fs-extra": { "version": "8.1.0", "resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-8.1.0.tgz", @@ -11342,42 +11290,11 @@ "integrity": "sha512-2zeMQpbKz5dhZ9IwL0gbxSW5w0NK/MSAMtNuhgIHEPmaU3vPdKPL0UdvUCXs5SS4JAwsBxysK5sFMW8ocFiVjQ==", "dev": true }, - "is-number": { - "version": "7.0.0", - "resolved": "https://registry.npmjs.org/is-number/-/is-number-7.0.0.tgz", - "integrity": "sha512-41Cifkg6e8TylSpdtTpeLVMqvSBEVzTttHvERD741+pnZ8ANv0004MRL43QKPDlK9cGvNp6NZWZUBlbGXYxxng==", - "dev": true - }, - "micromatch": { - "version": "4.0.4", - "resolved": "https://registry.npmjs.org/micromatch/-/micromatch-4.0.4.tgz", - "integrity": "sha512-pRmzw/XUcwXGpD9aI9q/0XOwLNygjETJ8y0ao0wdqprrzDa4YnxLcz7fQRZr8voh8V10kGhABbNcHVk5wHgWwg==", - "dev": true, - "requires": { - "braces": "^3.0.1", - "picomatch": "^2.2.3" - } - }, - "path-type": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/path-type/-/path-type-4.0.0.tgz", - "integrity": "sha512-gDKb8aZMDeD/tZWs9P6+q0J9Mwkdl6xMV8TjnGP3qJVJ06bdMgkbBlLU8IdfOsIsFz2BW1rNVT3XuNEl8zPAvw==", - "dev": true - }, "slash": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/slash/-/slash-3.0.0.tgz", "integrity": "sha512-g9Q1haeby36OSStwb4ntCGGGaKsaVSjQ68fBxoQcutl5fS1vuY18H3wSt3jFyFtrkx+Kz0V1G85A4MyAdDMi2Q==", "dev": true - }, - "to-regex-range": { - "version": "5.0.1", - "resolved": "https://registry.npmjs.org/to-regex-range/-/to-regex-range-5.0.1.tgz", - "integrity": "sha512-65P7iz6X5yEr1cwcgvQxbbIw7Uk3gOy5dIdtZ4rDveLqhrdJP+Li/Hx6tyK0NEb+2GCyneCMJiGqrADCSNk8sQ==", - "dev": true, - "requires": { - "is-number": "^7.0.0" - } } } }, diff --git a/frontend/src/App.vue b/frontend/src/App.vue index 1e7edd16a..692e7cf78 100644 --- a/frontend/src/App.vue +++ b/frontend/src/App.vue @@ -7,7 +7,11 @@ -->