From 809ca5e5f71bb01bf0088d9dffb85e94b51c0eff Mon Sep 17 00:00:00 2001 From: --show-origin Date: Mon, 7 Aug 2023 23:23:22 -0700 Subject: [PATCH 01/24] chore: frontend to use environment var in docker --- frontend/.env.dockerbuild | 2 ++ frontend/Dockerfile | 56 ++++++++++++-------------------- frontend/Dockerfile-old | 43 ++++++++++++++++++++++++ frontend/src/config.json | 4 +++ frontend/src/main.js | 5 +-- frontend/src/views/StockView.vue | 6 +++- frontend/start-nginx.sh | 7 ++++ 7 files changed, 84 insertions(+), 39 deletions(-) create mode 100644 frontend/.env.dockerbuild create mode 100644 frontend/Dockerfile-old create mode 100644 frontend/src/config.json create mode 100755 frontend/start-nginx.sh diff --git a/frontend/.env.dockerbuild b/frontend/.env.dockerbuild new file mode 100644 index 00000000..88c85f63 --- /dev/null +++ b/frontend/.env.dockerbuild @@ -0,0 +1,2 @@ +VITE_APP_NAME=$VITE_APP_NAME +VITE_BACKEND_BASE_URL=$VITE_BACKEND_BASE_URL diff --git a/frontend/Dockerfile b/frontend/Dockerfile index f9bf54af..d4ddb5f1 100644 --- a/frontend/Dockerfile +++ b/frontend/Dockerfile @@ -1,46 +1,30 @@ -# -# Copyright (c) 2022,2023 Volkswagen AG -# Copyright (c) 2022,2023 Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V. (represented by Fraunhofer ISST) -# Copyright (c) 2022,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 -# - FROM node:lts-alpine -# build arg for setting mode (local, develop, integration or beta, defaults to develop) -ARG npm_build_mode=develop +ARG npm_build_mode=dockerbuild +ENV JQ_VERSION=1.6 -# install simple http server for serving static content -RUN npm install -g http-server +#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 -# 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 build npm_build_mode -# copy project files and folders to the current working directory (i.e. 'app' folder) -COPY . . -# build app for production with minification -RUN npm run $npm_build_mode +FROM nginxinc/nginx-unprivileged:stable-alpine + +ENV SFOLDER=/usr/share/nginx/html/js/*.js + +COPY ./start-nginx.sh /usr/bin/start-nginx.sh +#RUN sudo chmod +x /usr/bin/start-nginx.sh -EXPOSE 8080 -CMD [ "http-server", "dist" ] \ No newline at end of file +WORKDIR /usr/share/nginx/html +# VueJS +COPY --from=0 /app/dist . +ENTRYPOINT [ "start-nginx.sh" ] diff --git a/frontend/Dockerfile-old b/frontend/Dockerfile-old new file mode 100644 index 00000000..41237009 --- /dev/null +++ b/frontend/Dockerfile-old @@ -0,0 +1,43 @@ +# +# Copyright (c) 2022,2023 Volkswagen AG +# Copyright (c) 2022,2023 Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V. (represented by Fraunhofer ISST) +# Copyright (c) 2022,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 +# + +FROM node:lts-alpine +# build arg for setting mode (local, develop, integration or beta, defaults to develop) +ARG npm_build_mode=dockerbuild +# 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 both 'package.json' and 'package-lock.json' (if available) +COPY package*.json ./ + +# install project dependencies +RUN npm install + +# copy project files and folders to the current working directory (i.e. 'app' folder) +COPY . . + +# build app for production with minification +RUN npm run $npm_build_mode + +EXPOSE 8080 +CMD [ "http-server", "dist" ] diff --git a/frontend/src/config.json b/frontend/src/config.json new file mode 100644 index 00000000..0af5f4aa --- /dev/null +++ b/frontend/src/config.json @@ -0,0 +1,4 @@ +{ + "APP_NAME": "$APP_NAME", + "BACKEND_BASE_URL": "$BASE_URL" +} diff --git a/frontend/src/main.js b/frontend/src/main.js index 0b349b16..89029961 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; @@ -32,4 +33,4 @@ app.use(router); app.use(JsonViewer); app.mount("#app"); -app.provide("baseUrl", publicEnvVar); +app.provide("baseUrl", Config.BACKEND_BASE_URL); diff --git a/frontend/src/views/StockView.vue b/frontend/src/views/StockView.vue index 360c8c6e..a6b90529 100644 --- a/frontend/src/views/StockView.vue +++ b/frontend/src/views/StockView.vue @@ -130,13 +130,17 @@