diff --git a/Dockerfile b/Dockerfile index fe8e093c..a1b63678 100644 --- a/Dockerfile +++ b/Dockerfile @@ -10,6 +10,12 @@ WORKDIR ${BUILDDIR} COPY package.json ${BUILDDIR} COPY yarn.lock ${BUILDDIR} COPY nginx/default.conf ${BUILDDIR} +ARG VITE_SCICRUNCH_API_KEY +ENV VITE_SCICRUNCH_API_KEY=$VITE_SCICRUNCH_API_KEY +ARG VITE_SCICRUNCH_API_URL +ENV VITE_API_URL=$VITE_API_URL +RUN echo "VITE_SCICRUNCH_API_KEY=$VITE_SCICRUNCH_API_KEY" > .env +RUN echo "VITE_SCICRUNCH_API_URL=$VITE_API_URL" >> .env RUN yarn install COPY . ${BUILDDIR} @@ -23,4 +29,4 @@ COPY --from=frontend /app/default.conf /etc/nginx/conf.d/default.conf COPY --from=frontend /app/dist /usr/share/nginx/html/ -EXPOSE 80 \ No newline at end of file +EXPOSE 80 diff --git a/deploy/codefresh/codefresh.yml b/deploy/codefresh/codefresh.yml index 43cdacb6..6b0208fa 100644 --- a/deploy/codefresh/codefresh.yml +++ b/deploy/codefresh/codefresh.yml @@ -6,30 +6,32 @@ stages: steps: clone: stage: "clone" - title: "Cloning Interlex" + title: "Cloning interlex" type: "git-clone" repo: "metacell/interlex" revision: "${{CF_BRANCH}}" build: stage: "build" - title: "Building Interlex" + title: "Building interlex" type: "build" image_name: "interlex" - tag: "${{CF_BUILD_ID}}" + tag: "${{CF_SHORT_REVISION}}" dockerfile: Dockerfile working_directory: ./interlex - buildkit: true + buildkit: true registry: "${{CODEFRESH_REGISTRY}}" + build_arguments: + - VITE_API_URL=${{VITE_API_URL}} + - VITE_SCICRUNCH_API_KEY=${{VITE_SCICRUNCH_API_KEY}} deploy: stage: "deploy" - title: "Deploying Interlex" - image: codefresh/kubectl + title: "Deploying interlex" + image: codefresh/cf-deploy-kubernetes + tag: latest working_directory: ./interlex/deploy/k8s commands: - - export CLUSTER_NAME="${{CLUSTER_NAME}}" - - export NAMESPACE="${{NAMESPACE}}" - - export CF_BUILD_ID - - export REGISTRY="${{REGISTRY}}/" - - export DOMAIN="${{DOMAIN}}" - - chmod +x ./deploy.sh - - ./deploy.sh \ No newline at end of file + - /cf-deploy-kubernetes interlex.yaml + - /cf-deploy-kubernetes ingress.yaml + environment: + - KUBECONTEXT=${{CLUSTER_NAME}} + - KUBERNETES_NAMESPACE=${{NAMESPACE}} diff --git a/deploy/k8s/codefresh.yaml b/deploy/k8s/codefresh.yaml deleted file mode 100644 index 0344a8b7..00000000 --- a/deploy/k8s/codefresh.yaml +++ /dev/null @@ -1,34 +0,0 @@ -version: "1.0" -stages: - - "clone" - - "build" - - "deploy" -steps: - clone: - stage: "clone" - title: "Cloning interlex" - type: "git-clone" - repo: "metacell/interlex" - revision: "${{CF_BRANCH}}" - build: - stage: "build" - title: "Building interlex" - type: "build" - image_name: "interlex" - tag: "${{CF_SHORT_REVISION}}" - dockerfile: Dockerfile - working_directory: ./interlex - buildkit: true - registry: "${{CODEFRESH_REGISTRY}}" - deploy: - stage: "deploy" - title: "Deploying interlex" - image: codefresh/cf-deploy-kubernetes - tag: latest - working_directory: ./interlex/deploy/k8s - commands: - - /cf-deploy-kubernetes interlex.yaml - - /cf-deploy-kubernetes ingress.yaml - environment: - - KUBECONTEXT=${{CLUSTER_NAME}} - - KUBERNETES_NAMESPACE=${{NAMESPACE}} diff --git a/nginx/default.conf b/nginx/default.conf index e2cbeb4a..fa7f0ed2 100644 --- a/nginx/default.conf +++ b/nginx/default.conf @@ -1,28 +1,13 @@ -upstream interlex { - server interlex:8000; -} - server { listen 80; - location / { - root /usr/share/nginx/html/; - try_files $uri /index.html; - } + error_log /var/log/nginx/error.log debug; # todo testing remove me not for production use - location /interlex/ { + location / { root /usr/share/nginx/html/; try_files $uri /index.html; } - location ~* ^/(admin|api|logged-out|login|interlex|complete|disconnect|__debug__)/.*$ { - proxy_set_header Host $host; - proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; - proxy_set_header X-Forwarded-Proto https; - proxy_redirect off; - proxy_pass http://interlex; - } - # Proxy for Elasticsearch API requests location /api/elasticsearch { proxy_pass https://scicrunch.org/api/1/elastic/Interlex_pr/_search; diff --git a/src/api/endpoints/index.ts b/src/api/endpoints/index.ts index cf250c3c..1155e7f3 100644 --- a/src/api/endpoints/index.ts +++ b/src/api/endpoints/index.ts @@ -4,10 +4,8 @@ import * as api from "./../../api/endpoints/interLexURIStructureAPI"; import { TERM, ONTOLOGY, ORGANIZATION } from '../../model/frontend/types' import curieParser from '../../parsers/curieParser'; import termParser, { elasticSearhParser, getTerm } from '../../parsers/termParser'; -import { Curies } from '../../model/frontend/curies'; import axios from 'axios'; import { API_CONFIG } from '../../config'; -import { config } from 'dotenv'; const useMockApi = () => mockApi; const useApi = () => api; @@ -134,7 +132,7 @@ export const getMatchTerms = async (term, filters = {}) => { }); }; -const fetchData = async (url, method = "GET", data = null) => { +const fetchData = async (url, method = "GET", data: object | null = null) => { try { const response = await axios({ url, @@ -153,7 +151,7 @@ const fetchData = async (url, method = "GET", data = null) => { }; export const elasticSearch = async (query) => { - const url = API_CONFIG.BASE_SCICRUNCH_URL + import.meta.env.VITE_SCICRUNCH_API_KEY + const url = API_CONFIG.BASE_SCICRUNCH_URL + API_CONFIG.SCICRUNCH_KEY; try { const result = await fetchData(url, "POST", { query: { @@ -173,7 +171,7 @@ export const searchAll = async (term, filters = {}) => { /** Call Endpoint */ return searchAll("base", term, filters).then((data) => { - let terms = termParser(data.terms, term, filters); + let terms = termParser((data as any).terms, term, filters); terms?.results?.forEach( result => { result.type = TERM; }) @@ -411,4 +409,4 @@ export const handleRecoverUser = async (email: string) => { console.error("Recover user failed:", error); throw error; } -}; \ No newline at end of file +}; diff --git a/src/components/Header/Search.jsx b/src/components/Header/Search.jsx index a56373b3..0645aaa0 100644 --- a/src/components/Header/Search.jsx +++ b/src/components/Header/Search.jsx @@ -136,9 +136,9 @@ const Search = () => { // eslint-disable-next-line react-hooks/exhaustive-deps const fetchTerms = useCallback(debounce(async (searchTerm) => { const data = await elasticSearch(searchTerm); - const dataTerms = data?.results.filter(result => result.type === SEARCH_TYPES.TERM); - const dataOrganizations = data?.results.filter(result => result.type === SEARCH_TYPES.ORGANIZATION); - const dataOntologies = data?.results.filter(result => result.type === SEARCH_TYPES.ONTOLOGY); + const dataTerms = data?.results?.filter(result => result.type === SEARCH_TYPES.TERM); + const dataOrganizations = data?.results?.filter(result => result.type === SEARCH_TYPES.ORGANIZATION); + const dataOntologies = data?.results?.filter(result => result.type === SEARCH_TYPES.ONTOLOGY); setTerms(dataTerms); setOrganizations(dataOrganizations); setOntologies(dataOntologies); @@ -360,8 +360,6 @@ const Search = () => { ); }; - - Search.propTypes = { open: PropTypes.bool, handleClose: PropTypes.func, diff --git a/src/config.js b/src/config.js index 1997d73d..963c8c10 100644 --- a/src/config.js +++ b/src/config.js @@ -26,4 +26,5 @@ export const API_CONFIG = { }, OLYMPIAN_GODS : "https://uri.olympiangods.org", BASE_SCICRUNCH_URL: "/api/elasticsearch?key=", -}; \ No newline at end of file + SCICRUNCH_KEY: import.meta.env.VITE_SCICRUNCH_API_KEY, +};