From 4bcf77a57637a176507899ceb3beb91e43e4df69 Mon Sep 17 00:00:00 2001 From: Afonso Pinto Date: Thu, 22 Feb 2024 15:26:28 +0000 Subject: [PATCH 1/3] CDE-40 fix: Fix build (#21) * CDE-40 fix: Fix build * CDE-40 fix: Fix library import * CDE-40 chore: Fix linting * CDE-40 chore: Remove package no longer used * CDE-40 chore: Update deployment configurations * CDE-40 feat: Update example fetch --- Dockerfile | 2 ++ demo/integration.js | 11 +++++++++-- k8s/codefresh.yaml | 1 + lib/components/common/HoveredOptionContent.tsx | 2 +- lib/components/steps/mapping/MappingTab.tsx | 6 +++--- package.json | 1 - vite.config.ts | 4 ---- 7 files changed, 16 insertions(+), 11 deletions(-) diff --git a/Dockerfile b/Dockerfile index 5528318..2d3a676 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,8 +1,10 @@ ARG PARENT=ubuntu/nginx ARG NODE_PARENT=node:18.12.1 +ARG VITE_API_KEY FROM ${NODE_PARENT} as build ENV APP_DIR=/app +ENV VITE_API_KEY=$VITE_API_KEY WORKDIR ${APP_DIR} diff --git a/demo/integration.js b/demo/integration.js index a40871c..3715426 100644 --- a/demo/integration.js +++ b/demo/integration.js @@ -1,5 +1,5 @@ -import {init, mapElasticSearchHitsToOptions} from '../lib/main.tsx'; +import {init, mapElasticSearchHitsToOptions} from './cde-mapper.js'; import {getQueryObject} from "./query.js"; export function mapAndInit(datasetMappingFile, additionalDatasetMappingsFiles, datasetFile) { @@ -111,7 +111,14 @@ function getCollections() { async function fetchElasticSearchData(queryString) { const query = getQueryObject(queryString) - const response = await fetch('/api', { + const apiKey = import.meta.env.VITE_API_KEY; + const baseUrl = '/api/1/elastic/Interlex_pr/_search'; + + const queryParameters = new URLSearchParams({ + key: apiKey, + }).toString(); + + const response = await fetch(`${baseUrl}?${queryParameters}`, { method: 'POST', headers: { 'Content-Type': 'application/json', diff --git a/k8s/codefresh.yaml b/k8s/codefresh.yaml index 3933c24..7ed4299 100644 --- a/k8s/codefresh.yaml +++ b/k8s/codefresh.yaml @@ -31,3 +31,4 @@ steps: environment: - KUBECONTEXT=${{CLUSTER}} - KUBERNETES_NAMESPACE=${{NAMESPACE}} + - VITE_API_KEY=${{VITE_API_KEY}} \ No newline at end of file diff --git a/lib/components/common/HoveredOptionContent.tsx b/lib/components/common/HoveredOptionContent.tsx index 9fc0989..3fe2ee0 100644 --- a/lib/components/common/HoveredOptionContent.tsx +++ b/lib/components/common/HoveredOptionContent.tsx @@ -1,6 +1,6 @@ import {Stack, Typography, Box} from '@mui/material'; import {vars} from '../../theme/variables'; -import {Option} from "./CustomMappingDropdown.tsx"; +import {Option} from "../../models.ts"; const { gray400, diff --git a/lib/components/steps/mapping/MappingTab.tsx b/lib/components/steps/mapping/MappingTab.tsx index bb596ce..b2d10bb 100644 --- a/lib/components/steps/mapping/MappingTab.tsx +++ b/lib/components/steps/mapping/MappingTab.tsx @@ -165,7 +165,7 @@ const MappingTab = ({defaultCollection}: MappingProps) => { const handleFiltering = () => { // TODO: to implement - console.log("To be implemented " + visibleRows) + void visibleRows setVisibleRows([]) } @@ -205,13 +205,13 @@ const MappingTab = ({defaultCollection}: MappingProps) => { ); }; - // eslint-disable-next-line @typescript-eslint/no-unused-vars const getPairingSuggestions = (key: string) => { + void key return [] }; - // eslint-disable-next-line @typescript-eslint/no-unused-vars const hasPairingSuggestions = (key: string) => { + void key return false }; diff --git a/package.json b/package.json index 2b2d03f..9bf0f5d 100644 --- a/package.json +++ b/package.json @@ -32,7 +32,6 @@ "@typescript-eslint/eslint-plugin": "^6.14.0", "@typescript-eslint/parser": "^6.14.0", "@vitejs/plugin-react": "^4.2.1", - "dotenv": "^16.4.5", "eslint": "^8.55.0", "eslint-plugin-react-hooks": "^4.6.0", "eslint-plugin-react-refresh": "^0.4.5", diff --git a/vite.config.ts b/vite.config.ts index 5374aa3..c7f5531 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -3,9 +3,6 @@ import {resolve} from 'path' import react from '@vitejs/plugin-react' import dts from 'vite-plugin-dts' -import dotenv from 'dotenv'; - -dotenv.config(); // https://vitejs.dev/config/ export default defineConfig(({ mode }) => ({ @@ -31,7 +28,6 @@ export default defineConfig(({ mode }) => ({ '/api': { target: 'https://scicrunch.org', changeOrigin: true, - rewrite: (path) => path.replace(/^\/api/, `/api/1/elastic/Interlex_pr/_search?key=${process.env.VITE_API_KEY}`), }, }, }, From be2d48be018fc8b5152ce35f331d59561df68557 Mon Sep 17 00:00:00 2001 From: Afonso Pinto Date: Fri, 23 Feb 2024 12:10:20 +0000 Subject: [PATCH 2/3] Feature/cde 40 deployment (#24) * CDE-40 chore: Add build demo step * CDE-40 chore: Update codefresh pipeline * CDE-40 chore: Update codefresh pipeline * CDE-40 feat: Replace node script with shell script --- Dockerfile | 9 +++++++-- k8s/codefresh.yaml | 2 ++ replace_env_vars.sh | 6 ++++++ 3 files changed, 15 insertions(+), 2 deletions(-) create mode 100755 replace_env_vars.sh diff --git a/Dockerfile b/Dockerfile index 2d3a676..b2425c0 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,10 +1,12 @@ ARG PARENT=ubuntu/nginx ARG NODE_PARENT=node:18.12.1 -ARG VITE_API_KEY + + FROM ${NODE_PARENT} as build -ENV APP_DIR=/app +ARG VITE_API_KEY ENV VITE_API_KEY=$VITE_API_KEY +ENV APP_DIR=/app WORKDIR ${APP_DIR} @@ -15,6 +17,9 @@ RUN npm install # user node ADD --chown=node:node . ${APP_DIR} +COPY replace_env_vars.sh /usr/local/bin/replace_env_vars.sh +RUN chmod +x /usr/local/bin/replace_env_vars.sh +RUN /usr/local/bin/replace_env_vars.sh RUN npm run build FROM ${PARENT} diff --git a/k8s/codefresh.yaml b/k8s/codefresh.yaml index 7ed4299..9e6fcdd 100644 --- a/k8s/codefresh.yaml +++ b/k8s/codefresh.yaml @@ -20,6 +20,8 @@ steps: tag: "${{CF_SHORT_REVISION}}" dockerfile: Dockerfile registry: ${{REGISTRY}} + build_arguments: + - VITE_API_KEY=${{VITE_API_KEY}} deploy-to-kubernetes: image: codefresh/cf-deploy-kubernetes tag: latest diff --git a/replace_env_vars.sh b/replace_env_vars.sh new file mode 100755 index 0000000..1ba059b --- /dev/null +++ b/replace_env_vars.sh @@ -0,0 +1,6 @@ +#!/bin/sh +# replace_env_vars.sh + +for var in $(printenv | grep VITE_ | awk -F= '{print $1}'); do + sed -i 's|import.meta.env.'$var'|"'$(printenv $var)'"|g' ./demo/*.js +done From 305de059f32a1857d29b667b5817cfe876e82523 Mon Sep 17 00:00:00 2001 From: Afonso Pinto Date: Fri, 23 Feb 2024 15:00:27 +0000 Subject: [PATCH 3/3] CDE-40 chore: - Add nginx reverse proxy (#25) * CDE-40 chore: WIP - Add nginx reverse proxy * CDE-40 chore: Add nginx reverse proxy * chore(): added docker-compose and updated readme --------- Co-authored-by: Zoran Sinnema --- Dockerfile | 5 +++-- README.md | 12 ++++++++++++ default.conf | 15 +++++++++++++++ docker-compose.yaml | 6 ++++++ 4 files changed, 36 insertions(+), 2 deletions(-) create mode 100644 default.conf create mode 100644 docker-compose.yaml diff --git a/Dockerfile b/Dockerfile index b2425c0..3bc4745 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,8 +1,6 @@ ARG PARENT=ubuntu/nginx ARG NODE_PARENT=node:18.12.1 - - FROM ${NODE_PARENT} as build ARG VITE_API_KEY ENV VITE_API_KEY=$VITE_API_KEY @@ -25,5 +23,8 @@ RUN npm run build FROM ${PARENT} ENV PORT=80 +# Copy the custom NGINX configuration file +COPY default.conf /etc/nginx/sites-available/default + COPY --from=build /app/demo/* /var/www/html EXPOSE ${PORT} diff --git a/README.md b/README.md index e6c39e5..3463984 100644 --- a/README.md +++ b/README.md @@ -23,5 +23,17 @@ run docker run --name cde-mapper -e TZ=UTC -p 8000:80 cde-mapper ``` +## docker-compose + +run +```bash +docker-compose up --build +``` + +stop: +```bash +docker-compose down +``` + open the url http://localhost:8000/ diff --git a/default.conf b/default.conf new file mode 100644 index 0000000..539cb69 --- /dev/null +++ b/default.conf @@ -0,0 +1,15 @@ +server { + listen 80; + + location / { + root /var/www/html; + index index.html index.htm; + try_files $uri $uri/ =404; + } + + location /api/ { + proxy_pass https://scicrunch.org; + proxy_set_header Host scicrunch.org; + proxy_pass_request_headers on; + } +} diff --git a/docker-compose.yaml b/docker-compose.yaml new file mode 100644 index 0000000..f5a8fda --- /dev/null +++ b/docker-compose.yaml @@ -0,0 +1,6 @@ +version: "2.4" +services: + cde-demo: + build: . + ports: + - "8080:80" \ No newline at end of file