diff --git a/Dockerfile b/Dockerfile index 5528318..3bc4745 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,6 +2,8 @@ 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 ENV APP_DIR=/app WORKDIR ${APP_DIR} @@ -13,10 +15,16 @@ 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} 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/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/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 diff --git a/k8s/codefresh.yaml b/k8s/codefresh.yaml index 3933c24..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 @@ -31,3 +33,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 c729115..27616fa 100644 --- a/lib/components/steps/mapping/MappingTab.tsx +++ b/lib/components/steps/mapping/MappingTab.tsx @@ -174,7 +174,7 @@ const MappingTab = ({defaultCollection}: MappingProps) => { const handleFiltering = () => { // TODO: to implement - console.log("To be implemented " + visibleRows) + void visibleRows setVisibleRows([]) } @@ -214,13 +214,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 0aa42ea..a9a515f 100644 --- a/package.json +++ b/package.json @@ -33,7 +33,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/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 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}`), }, }, },