diff --git a/DEPENDENCIES_BACKEND b/DEPENDENCIES_BACKEND index d41e2849..d7ee2ac8 100644 --- a/DEPENDENCIES_BACKEND +++ b/DEPENDENCIES_BACKEND @@ -8,8 +8,11 @@ maven/mavencentral/com.fasterxml.jackson.datatype/jackson-datatype-jdk8/2.14.1, maven/mavencentral/com.fasterxml.jackson.datatype/jackson-datatype-jsr310/2.14.1, Apache-2.0, approved, #4699 maven/mavencentral/com.fasterxml.jackson.module/jackson-module-parameter-names/2.14.1, Apache-2.0, approved, #5938 maven/mavencentral/com.fasterxml/classmate/1.5.1, Apache-2.0, approved, clearlydefined +maven/mavencentral/com.jayway.jsonpath/json-path/2.7.0, Apache-2.0, approved, clearlydefined maven/mavencentral/com.squareup.okhttp/okhttp/2.7.5, Apache-2.0, approved, clearlydefined maven/mavencentral/com.squareup.okio/okio/1.6.0, Apache-2.0, approved, CQ11382 +maven/mavencentral/com.sun.istack/istack-commons-runtime/4.1.1, BSD-3-Clause, approved, #2590 +maven/mavencentral/com.vaadin.external.google/android-json/0.0.20131108.vaadin1, Apache-2.0, approved, CQ21310 maven/mavencentral/com.zaxxer/HikariCP/5.0.1, Apache-2.0, approved, clearlydefined maven/mavencentral/io.micrometer/micrometer-commons/1.10.3, Apache-2.0 AND (Apache-2.0 AND MIT), approved, #7333 maven/mavencentral/io.micrometer/micrometer-observation/1.10.3, Apache-2.0, approved, #7331 @@ -18,22 +21,50 @@ maven/mavencentral/io.swagger.core.v3/swagger-core-jakarta/2.2.9, Apache-2.0, ap maven/mavencentral/io.swagger.core.v3/swagger-models-jakarta/2.2.9, Apache-2.0, approved, #5919 maven/mavencentral/jakarta.activation/jakarta.activation-api/2.1.1, EPL-2.0 OR BSD-3-Clause OR GPL-2.0-only with Classpath-exception-2.0, approved, ee4j.jaf maven/mavencentral/jakarta.annotation/jakarta.annotation-api/2.1.1, EPL-2.0 OR GPL-2.0-only with Classpath-exception-2.0, approved, ee4j.ca +maven/mavencentral/jakarta.inject/jakarta.inject-api/2.0.0, Apache-2.0, approved, clearlydefined maven/mavencentral/jakarta.persistence/jakarta.persistence-api/3.1.0, EPL-2.0 OR BSD-3-Clause AND (EPL-2.0 OR BSD-3-Clause AND BSD-3-Clause), approved, #7696 maven/mavencentral/jakarta.transaction/jakarta.transaction-api/2.0.1, EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0, approved, #7697 maven/mavencentral/jakarta.validation/jakarta.validation-api/3.0.2, Apache-2.0, approved, clearlydefined maven/mavencentral/jakarta.xml.bind/jakarta.xml.bind-api/4.0.0, BSD-3-Clause, approved, ee4j.jaxb +maven/mavencentral/net.bytebuddy/byte-buddy-agent/1.12.22, Apache-2.0, approved, #1810 +maven/mavencentral/net.bytebuddy/byte-buddy/1.12.22, Apache-2.0 AND BSD-3-Clause, approved, #1811 +maven/mavencentral/net.minidev/accessors-smart/2.4.8, Apache-2.0, approved, #7515 +maven/mavencentral/net.minidev/json-smart/2.4.8, Apache-2.0, approved, #3288 +maven/mavencentral/org.antlr/antlr4-runtime/4.10.1, BSD-3-Clause AND LicenseRef-Public-domain AND MIT AND LicenseRef-Unicode-TOU, approved, #7065 maven/mavencentral/org.apache.commons/commons-lang3/3.12.0, Apache-2.0, approved, clearlydefined maven/mavencentral/org.apache.logging.log4j/log4j-api/2.19.0, Apache-2.0, approved, clearlydefined maven/mavencentral/org.apache.logging.log4j/log4j-to-slf4j/2.19.0, Apache-2.0, approved, #5941 maven/mavencentral/org.apache.tomcat.embed/tomcat-embed-core/10.1.5, Apache-2.0 AND (EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0) AND (CDDL-1.0 OR GPL-2.0-only WITH Classpath-exception-2.0) AND W3C AND CC0-1.0, approved, #5949 maven/mavencentral/org.apache.tomcat.embed/tomcat-embed-el/10.1.5, Apache-2.0, approved, #6997 maven/mavencentral/org.apache.tomcat.embed/tomcat-embed-websocket/10.1.5, Apache-2.0, approved, #7920 +maven/mavencentral/org.apiguardian/apiguardian-api/1.1.2, Apache-2.0, approved, clearlydefined maven/mavencentral/org.aspectj/aspectjweaver/1.9.19, EPL-1.0, approved, tools.aspectj +maven/mavencentral/org.assertj/assertj-core/3.23.1, Apache-2.0, approved, clearlydefined +maven/mavencentral/org.eclipse.angus/angus-activation/1.0.0, EPL-2.0 OR GPL-2.0-only with Classpath-exception-2.0, approved, ee4j.angus +maven/mavencentral/org.glassfish.jaxb/jaxb-core/4.0.1, BSD-3-Clause, approved, ee4j.jaxb +maven/mavencentral/org.glassfish.jaxb/jaxb-runtime/4.0.1, BSD-3-Clause, approved, ee4j.jaxb +maven/mavencentral/org.glassfish.jaxb/txw2/4.0.1, BSD-3-Clause, approved, ee4j.jaxb +maven/mavencentral/org.hamcrest/hamcrest/2.2, BSD-3-Clause, approved, clearlydefined +maven/mavencentral/org.hibernate.common/hibernate-commons-annotations/6.0.2.Final, LGPL-2.1-only, approved, #6962 maven/mavencentral/org.hibernate.orm/hibernate-core/6.1.6.Final, LGPL-2.1-or-later AND (Apache-2.0 AND LGPL-2.1-only) AND (CC-PDDC AND LGPL-2.1-only) AND (EPL-2.0 OR BSD-3-Clause), approved, #5939 maven/mavencentral/org.hibernate.validator/hibernate-validator/8.0.0.Final, Apache-2.0, approved, clearlydefined +maven/mavencentral/org.hsqldb/hsqldb/2.7.1, BSD-3-Clause, approved, clearlydefined maven/mavencentral/org.jboss.logging/jboss-logging/3.5.0.Final, Apache-2.0, approved, #9471 +maven/mavencentral/org.jboss/jandex/2.4.2.Final, Apache-2.0, approved, clearlydefined +maven/mavencentral/org.junit.jupiter/junit-jupiter-api/5.9.2, EPL-2.0, approved, #3133 +maven/mavencentral/org.junit.jupiter/junit-jupiter-engine/5.9.2, EPL-2.0, approved, #3125 +maven/mavencentral/org.junit.jupiter/junit-jupiter-params/5.9.2, EPL-2.0, approved, #3134 +maven/mavencentral/org.junit.jupiter/junit-jupiter/5.9.2, EPL-2.0, approved, #6972 +maven/mavencentral/org.junit.platform/junit-platform-commons/1.9.2, EPL-2.0, approved, #3130 +maven/mavencentral/org.junit.platform/junit-platform-engine/1.9.2, EPL-2.0, approved, #3128 +maven/mavencentral/org.mockito/mockito-core/4.8.1, MIT, approved, clearlydefined +maven/mavencentral/org.mockito/mockito-junit-jupiter/4.8.1, MIT, approved, clearlydefined maven/mavencentral/org.modelmapper/modelmapper/3.1.1, Apache-2.0, approved, clearlydefined +maven/mavencentral/org.objenesis/objenesis/3.2, Apache-2.0, approved, clearlydefined +maven/mavencentral/org.opentest4j/opentest4j/1.2.0, Apache-2.0, approved, clearlydefined +maven/mavencentral/org.ow2.asm/asm/9.1, BSD-3-Clause, approved, CQ23029 maven/mavencentral/org.projectlombok/lombok/1.18.24, MIT AND LicenseRef-Public-Domain, approved, CQ23907 +maven/mavencentral/org.skyscreamer/jsonassert/1.5.1, Apache-2.0, approved, clearlydefined maven/mavencentral/org.slf4j/jul-to-slf4j/2.0.6, MIT, approved, #7698 maven/mavencentral/org.slf4j/slf4j-api/2.0.6, MIT, approved, #5915 maven/mavencentral/org.springdoc/springdoc-openapi-starter-common/2.1.0, Apache-2.0, approved, clearlydefined @@ -41,21 +72,26 @@ maven/mavencentral/org.springdoc/springdoc-openapi-starter-webmvc-api/2.1.0, Apa maven/mavencentral/org.springdoc/springdoc-openapi-starter-webmvc-ui/2.1.0, Apache-2.0, approved, clearlydefined maven/mavencentral/org.springframework.boot/spring-boot-autoconfigure/3.0.2, Apache-2.0, approved, #6981 maven/mavencentral/org.springframework.boot/spring-boot-configuration-processor/3.0.2, Apache-2.0, approved, #6973 +maven/mavencentral/org.springframework.boot/spring-boot-devtools/3.0.2, Apache-2.0, approved, clearlydefined maven/mavencentral/org.springframework.boot/spring-boot-starter-aop/3.0.2, Apache-2.0, approved, #6965 maven/mavencentral/org.springframework.boot/spring-boot-starter-data-jpa/3.0.2, Apache-2.0, approved, #7351 maven/mavencentral/org.springframework.boot/spring-boot-starter-jdbc/3.0.2, Apache-2.0, approved, #6974 maven/mavencentral/org.springframework.boot/spring-boot-starter-json/3.0.2, Apache-2.0, approved, #7006 maven/mavencentral/org.springframework.boot/spring-boot-starter-logging/3.0.2, Apache-2.0, approved, #6982 maven/mavencentral/org.springframework.boot/spring-boot-starter-security/3.0.2, Apache-2.0, approved, #7329 +maven/mavencentral/org.springframework.boot/spring-boot-starter-test/3.0.2, Apache-2.0, approved, #7001 maven/mavencentral/org.springframework.boot/spring-boot-starter-tomcat/3.0.2, Apache-2.0, approved, #6987 maven/mavencentral/org.springframework.boot/spring-boot-starter-web/3.0.2, Apache-2.0, approved, #5945 maven/mavencentral/org.springframework.boot/spring-boot-starter/3.0.2, Apache-2.0, approved, #7330 +maven/mavencentral/org.springframework.boot/spring-boot-test-autoconfigure/3.0.2, Apache-2.0, approved, #6966 +maven/mavencentral/org.springframework.boot/spring-boot-test/3.0.2, Apache-2.0, approved, #6976 maven/mavencentral/org.springframework.boot/spring-boot/3.0.2, Apache-2.0, approved, #7327 maven/mavencentral/org.springframework.data/spring-data-commons/3.0.1, Apache-2.0, approved, #5943 maven/mavencentral/org.springframework.data/spring-data-jpa/3.0.1, Apache-2.0, approved, #5935 maven/mavencentral/org.springframework.security/spring-security-config/6.0.1, Apache-2.0, approved, #7338 maven/mavencentral/org.springframework.security/spring-security-core/6.0.1, Apache-2.0, approved, #7325 maven/mavencentral/org.springframework.security/spring-security-crypto/6.0.1, Apache-2.0 AND ISC, approved, #7326 +maven/mavencentral/org.springframework.security/spring-security-test/6.0.1, Apache-2.0, approved, #7402 maven/mavencentral/org.springframework.security/spring-security-web/6.0.1, Apache-2.0, approved, #7328 maven/mavencentral/org.springframework.session/spring-session-core/3.0.0, Apache-2.0, approved, #7858 maven/mavencentral/org.springframework/spring-aop/6.0.4, Apache-2.0, approved, #5940 @@ -67,8 +103,10 @@ maven/mavencentral/org.springframework/spring-expression/6.0.4, Apache-2.0, appr maven/mavencentral/org.springframework/spring-jcl/6.0.4, Apache-2.0, approved, #3283 maven/mavencentral/org.springframework/spring-jdbc/6.0.4, Apache-2.0, approved, #5924 maven/mavencentral/org.springframework/spring-orm/6.0.4, Apache-2.0, approved, #5925 +maven/mavencentral/org.springframework/spring-test/6.0.4, Apache-2.0, approved, #7003 maven/mavencentral/org.springframework/spring-tx/6.0.4, Apache-2.0, approved, #5926 maven/mavencentral/org.springframework/spring-web/6.0.4, Apache-2.0, approved, #5942 maven/mavencentral/org.springframework/spring-webmvc/6.0.4, Apache-2.0, approved, #5944 maven/mavencentral/org.webjars/swagger-ui/4.18.2, Apache-2.0, approved, #7850 +maven/mavencentral/org.xmlunit/xmlunit-core/2.9.1, Apache-2.0, approved, #6272 maven/mavencentral/org.yaml/snakeyaml/1.33, Apache-2.0, approved, clearlydefined diff --git a/backend/Dockerfile b/backend/Dockerfile index a3d4c8a8..82da5893 100644 --- a/backend/Dockerfile +++ b/backend/Dockerfile @@ -18,7 +18,6 @@ # # SPDX-License-Identifier: Apache-2.0 # - FROM maven:3.8.7-eclipse-temurin-17 as build RUN mkdir /app WORKDIR /app @@ -28,7 +27,12 @@ RUN mvn initialize -f pom.xml COPY src/ /app/src/ RUN mvn clean package -DskipTests -FROM eclipse-temurin:17 +FROM eclipse-temurin:17-jre-alpine RUN mkdir /opt/app -COPY --from=build /app/target/*.jar /opt/app/scm-be.jar -CMD ["java", "-jar", "/opt/app/scm-be.jar"] \ No newline at end of file +COPY --from=build /app/target/*.jar /opt/app/puris-backend.jar + +RUN adduser -u 8877 -D nonroot && chmod 755 /opt/app/puris-backend.jar + +USER nonroot + +ENTRYPOINT ["sh", "-c", " java ${JAVA_OPTS} -jar /opt/app/puris-backend.jar ${0} ${@}"] diff --git a/backend/INSTALL.md b/backend/INSTALL.md index d0ae14ea..15d345e2 100644 --- a/backend/INSTALL.md +++ b/backend/INSTALL.md @@ -1,19 +1,60 @@ ## Project Installation +The first steps are always the same: 1. Clone the project -2. Make sure the tractusx-edc is running with all its components (control plane, data plane, ...) +2. Make sure the PURIS backend and the tractusx-edc is running with all its components + +Depending on your needs of deployment, follow the following steps + +### Running using mvn (local develpment) 3. Change the `src/main/resources/application.properties` or the respective environment variables to configure the port, the URL of the EDC control plane, backend application etc. 4. Run the application: - - (Java) Use `mvn install` to build the project and run the generated `.jar` file - - (Docker) Run `docker build .` and `docker run -d -p 8081:8081 CONTAINERID` - - (Kubernetes) Run `helm install puris-backend` -4a. Run the application with role specific settings: - - Use `mvn spring-boot:run -Dspring-boot.run.arguments=--spring.profiles.active=customer` to start with customer setup - or - - Use `mvn spring-boot:run -Dspring-boot.run.arguments=--spring.profiles.active=supplier`to start with supplier setup +```shell +# build and run the generated .jar file +mvn install +# run for demo or development puroposes +# customer role +mvn spring-boot:run -Dspring-boot.run.arguments=--spring.profiles.active=customer +# supplier role +mvn spring-boot:run -Dspring-boot.run.arguments=--spring.profiles.active=supplier +``` 5. Done! The Swagger UI should be available at - (Java & Docker) `http://YOURIP:8081/catena/swagger-ui/index.html` - (Kubernetes) `http://CLUSTERIP:30001/catena/swagger-ui/index.html` 6. It is highly suggested to install and run the PURIS frontend afterward + +### Running using docker (deployment) +3. Optional (one can set properties via environment variables to docker): Change the `src/main/resources/application.properties` or the respective environment + variables to configure the port, the URL of the EDC control plane, backend application etc. +4. Run the application: +```shell +cd backend + +docker build -t puris-backend:dev . + +# A use docker +docker run -d --rm -p 8081:8081 --name backend -e server.port=8082 puris-backend:dev CONTAINERID + +# B use docker-compose +docker-compose up +``` +5. Done! The Swagger UI should be available at + - (Java & Docker) `http://YOURIP:8081/catena/swagger-ui/index.html` + - (Kubernetes) `http://CLUSTERIP:30001/catena/swagger-ui/index.html` +6. It is highly suggested to install and run the PURIS frontend afterward + +### Running using helm (deployment) +Change the `src/main/resources/application.properties` or the respective environment +variables to configure the port, the URL of the EDC control plane, backend application etc. +4. Run the application: +```shell +cd backend/charts + +helm install puris-backend +``` +5. Done! The Swagger UI should be available at + - (Java & Docker) `http://YOURIP:8081/catena/swagger-ui/index.html` + - (Kubernetes) `http://CLUSTERIP:30001/catena/swagger-ui/index.html` +6. It is highly suggested to install and run the PURIS frontend afterward diff --git a/backend/docker-compose.yaml b/backend/docker-compose.yaml new file mode 100644 index 00000000..d953510b --- /dev/null +++ b/backend/docker-compose.yaml @@ -0,0 +1,36 @@ +# +# Copyright (c) 2023 Volkswagen AG +# Copyright (c) 2023 Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V. (represented by Fraunhofer ISST) +# Copyright (c) 2023 Contributors to the Eclipse Foundation +# +# See the NOTICE file(s) distributed with this work for additional +# information regarding copyright ownership. +# +# This program and the accompanying materials are made available under the +# terms of the Apache License, Version 2.0 which is available at +# https://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. +# +# SPDX-License-Identifier: Apache-2.0 +# +version: '1' +services: + puris-backend: + image: puris-backend:dev + container_name: backend + ports: + - 8081:8081 + environment: + - server.port=8081 + - puris.demonstrator.role= #customer/supplier + - edc.controlplane.host=172.17.0.2 + - edc.controlplane.data.port=31605 + - edc.dataplane.public.port=31503 + - edc.idsUrl=http://plato-controlplane:8084/api/v1/ids + - own.bpnl= #BPNL4444444444XX + - own.bpns= #BPNS4444444444XX diff --git a/backend/src/main/resources/application.properties b/backend/src/main/resources/application.properties index 80649646..ea4ed486 100755 --- a/backend/src/main/resources/application.properties +++ b/backend/src/main/resources/application.properties @@ -2,8 +2,10 @@ server.port=${SERVER_PORT:8081} my.base.url=http://localhost request.serverendpoint=${my.base.url}:${server.port}/catena/product-stock/request +request.apiassetid=product-stock-request-api response.serverendpoint=${my.base.url}:${server.port}/catena/product-stock/response - +response.apiassetid=product-stock-response-api +edr.endpoint=${my.base.url}:${server.port}/catena/edrendpoint # DB Configuration spring.datasource.driver-class-name=${DATASOURCE_DRIVERCLASSNAME:org.hsqldb.jdbc.JDBCDriver} spring.datasource.url=${DATASOURCE_URL:jdbc:hsqldb:mem:testdb;DB_CLOSE_DELAY=-1} @@ -20,3 +22,24 @@ edc.controlplane.data.port=${EDC_CONTROLPLANE_DATA_PORT:31960} edc.controlplane.key=${EDC_CONTROLPLANE_KEY:password} edc.backend.url=${EDC_BACKEND_URL:http://172.17.0.2:31048} minikube.ip=${MINIKUBE_IP:host.minikube.internal} + +edc.applydataplaneworkaround=true +edc.dataplane.public.port=30784 + +# Jackson (JSON) +#spring.jackson.default-property-inclusion=non_empty +#logging.level.org.hibernate.SQL=DEBUG +#logging.level.org.hibernate.type.descriptor.sql.BasicBinder=TRACE +spring.jpa.properties.hibernate.enable_lazy_load_no_trans=true + +# Own EDC-IDS-URL +edc.idsUrl=${EDC_IDSURL:http://plato-controlplane:8084/api/v1/ids} +own.bpnl=${OWN_BPNL:BPNL1234567890ZZ} +own.bpns=${OWN_BPNS:BPNS1234567890ZZ} + +# The number of minutes before received authentication data +# in the context of a consumer pull is removed from memory +own.edr.deletiontimer=2 + +puris.apiversion=1.0.0 +puris.demonstrator.role=customer diff --git a/frontend/.env.dockerbuild b/frontend/.env.dockerbuild new file mode 100644 index 00000000..86fb9051 --- /dev/null +++ b/frontend/.env.dockerbuild @@ -0,0 +1,2 @@ +VITE_APP_NAME=\$APP_NAME +VITE_BACKEND_BASE_URL=\$BACKEND_BASE_URL diff --git a/frontend/Dockerfile b/frontend/Dockerfile index f9bf54af..d8058712 100644 --- a/frontend/Dockerfile +++ b/frontend/Dockerfile @@ -18,29 +18,46 @@ # # SPDX-License-Identifier: Apache-2.0 # +FROM node:lts-alpine as build -FROM node:lts-alpine +ARG NPM_BUILD_MODE=dockerbuild +ENV JQ_VERSION=1.6 -# build arg for setting mode (local, develop, integration or beta, defaults to develop) -ARG npm_build_mode=develop +# TODO curl results in problem with node during ```npm run ${NPM_BUILD_MODE}``` +#RUN apk --no-cache add curl +#RUN curl https://github.com/stedolan/jq/releases/download/jq-${JQ_VERSION}/jq-linux64 -o /tmp/jq-linux64 +RUN wget --no-check-certificate https://github.com/stedolan/jq/releases/download/jq-${JQ_VERSION}/jq-linux64 -O /tmp/jq-linux64 +RUN cp /tmp/jq-linux64 /usr/bin/jq +RUN chmod +x /usr/bin/jq -# install simple http server for serving static content -RUN npm install -g http-server - -# make the 'app' folder the current working directory WORKDIR /app +COPY . . -# copy both 'package.json' and 'package-lock.json' (if available) -COPY package*.json ./ +RUN jq 'to_entries | map_values({ (.key) : ("$" + .key) }) | reduce .[] as $item ({}; . + $item)' ./src/config.json > ./src/config.tmp.json && mv ./src/config.tmp.json ./src/config.json -# install project dependencies -RUN npm install +RUN npm install && npm run ${NPM_BUILD_MODE} -# copy project files and folders to the current working directory (i.e. 'app' folder) -COPY . . +RUN chmod -R 777 /app/dist + + +# uses 101 restricted user +FROM nginxinc/nginx-unprivileged:stable-alpine +#FROM nginx:stable-alpine + +# commly it would be .../html/js/.*js, but due to the project structure the JS files are in .../html/assets +ENV JSFOLDER=/usr/share/nginx/html/assets/*.js + +# use root user to install moreutils for sponge in start-nginx to substring env workaround +USER root + +COPY ./start-nginx.sh /usr/bin/start-nginx.sh +RUN apk --no-cache add moreutils -# build app for production with minification -RUN npm run $npm_build_mode +# use non-root user +USER 101 -EXPOSE 8080 -CMD [ "http-server", "dist" ] \ No newline at end of file +WORKDIR /usr/share/nginx/html +COPY --from=build /app/dist . +ENTRYPOINT [ "start-nginx.sh" ] +# nginx exposes at port 80 +# nginx-unpriviledged exposes at port 8080 diff --git a/frontend/INSTALL.md b/frontend/INSTALL.md index 00f464e7..de7c88ed 100644 --- a/frontend/INSTALL.md +++ b/frontend/INSTALL.md @@ -1,9 +1,38 @@ ## Project Installation - +The first steps are always the same: 1. Clone the project 2. Make sure the PURIS backend and the tractusx-edc is running with all its components -3. The `VITE_BASE_URL` in the `.env` file must be configured to the PURIS backend instance + +Depending on your needs of deployment, follow the following steps + +### Running using npm (local develpment) +Use npm as follows: +3. The `VITE_BASE_URL` in the `.env` file must be configured to the PURIS backend instance. 4. Run the application: - - (npm) Use `npm install` and `npm run dev` (for development) or `npm run build` (for production) - - (Docker) Run `docker build .` and `docker run -d -p 3000:3000 CONTAINERID` +```shell +npm install + +# A development +npm run dev + +# B production +npm run build +``` +5. Done! The frontend should be available at `http://YOURIP:3000/` + +### Running using docker (deployment) +As JS-frameworks hard-wire their environments, this project uses a workaround to make the .env variables replaceable by (docker) environment variables. +3. Build and run the docker frontend as follows: +```shell +cd frontend + +docker build -t puris-frontend:dev . + +# A use docker +docker run -d --rm -p 3000:8080 --name frontend -e BACKEND_BASE_URL=http://YOURBACKENDIP:8081/catena puris-frontend:dev CONTAINERID + +# B use docker-compose +docker-compose up +``` +Note: please find the available parameters in src/config.json 5. Done! The frontend should be available at `http://YOURIP:3000/` diff --git a/frontend/docker-compose.yaml b/frontend/docker-compose.yaml new file mode 100644 index 00000000..64cada57 --- /dev/null +++ b/frontend/docker-compose.yaml @@ -0,0 +1,30 @@ +# +# Copyright (c) 2023 Volkswagen AG +# Copyright (c) 2023 Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V. (represented by Fraunhofer ISST) +# Copyright (c) 2023 Contributors to the Eclipse Foundation +# +# See the NOTICE file(s) distributed with this work for additional +# information regarding copyright ownership. +# +# This program and the accompanying materials are made available under the +# terms of the Apache License, Version 2.0 which is available at +# https://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. +# +# SPDX-License-Identifier: Apache-2.0 +# +version: '1' +services: + puris-frontend: + image: puris-frontend:dev + container_name: frontend + ports: + - 3000:8080 + environment: + - APP_NAME=PURIS + - BACKEND_BASE_URL=http://localhost:8081/catena/ diff --git a/frontend/package.json b/frontend/package.json index 36084445..d0429267 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -3,6 +3,7 @@ "version": "0.0.1", "scripts": { "dev": "vite --host", + "dockerbuild": "vite build --mode dockerbuild", "build": "vite build", "local": "vite build --mode minikube", "develop": "vite build --mode dev", diff --git a/frontend/src/config.json b/frontend/src/config.json new file mode 100644 index 00000000..8a11fabe --- /dev/null +++ b/frontend/src/config.json @@ -0,0 +1,4 @@ +{ + "APP_NAME": "$APP_NAME", + "BACKEND_BASE_URL": "$BACKEND_BASE_URL" +} diff --git a/frontend/src/main.js b/frontend/src/main.js index 0b349b16..b54baa7d 100644 --- a/frontend/src/main.js +++ b/frontend/src/main.js @@ -19,11 +19,12 @@ * SPDX-License-Identifier: Apache-2.0 */ -import { createApp } from "vue"; +import {createApp} from "vue"; import App from "./App.vue"; import router from "./router"; import "./index.css"; import JsonViewer from "vue-json-viewer"; +import Config from "./config.json" const app = createApp(App); const publicEnvVar = import.meta.env.VITE_BASE_URL; @@ -31,5 +32,8 @@ const publicEnvVar = import.meta.env.VITE_BASE_URL; app.use(router); app.use(JsonViewer); +console.log("config.json BACKEND_BASE_URL=" + Config.BACKEND_BASE_URL); +console.log(".env.x VITE_BASE_URL=" + import.meta.env.VITE_BASE_URL); + app.mount("#app"); app.provide("baseUrl", publicEnvVar); diff --git a/frontend/src/views/StockView.vue b/frontend/src/views/StockView.vue index a79cbe49..78844ad8 100644 --- a/frontend/src/views/StockView.vue +++ b/frontend/src/views/StockView.vue @@ -134,7 +134,6 @@ import StockTableSFC from "@/views/stock/StockTableSFC.vue"; export default { name: "StockView", components: {StockTableSFC}, - data() { return { backendURL: import.meta.env.VITE_BACKEND_BASE_URL, @@ -163,6 +162,7 @@ export default { }; }, mounted() { + console.log("backendURL in StockView: " + this.backendURL); fetch(this.backendURL + this.endpointMaterials) .then(res => res.json()) .then(data => this.bdMaterials = data) diff --git a/frontend/start-nginx.sh b/frontend/start-nginx.sh new file mode 100755 index 00000000..780ece71 --- /dev/null +++ b/frontend/start-nginx.sh @@ -0,0 +1,21 @@ +#!/usr/bin/env sh +echo "Starting NGINX" +export EXISTING_VARS=$(printenv | awk -F= '{print $1}' | sed 's/^/\$/g' | paste -sd,); + +echo "===============" +echo "ENVIRONMENT VARIABLES:" +printenv +echo "===============" + +for file in $JSFOLDER; +do + echo -e "\r\n" + echo $file + + # other command cuts off length of files. sponge has no file-size limitation. + #cat $file | envsubst $EXISTING_VARS | tee $file + #envsubst $EXISTING_VARS < $file | tee $file + envsubst $EXISTING_VARS < $file | sponge $file + echo -e "\r\n" +done +nginx -g 'daemon off;'