diff --git a/.gitignore b/.gitignore index f322f4d3e..b8f9b9531 100644 --- a/.gitignore +++ b/.gitignore @@ -29,3 +29,5 @@ package-lock.json **/__snapshots__/** src/components/dashboard/container/ListContainer.jsx .env +/public/env-config.js +env-config.js diff --git a/Dockerfile b/Dockerfile index 9b3c88df1..71c78e7d0 100644 --- a/Dockerfile +++ b/Dockerfile @@ -39,5 +39,16 @@ COPY --from=build-deps /usr/src/app/docker/default.conf /etc/nginx/conf.d/ # Make port 80 available to the world outside the container EXPOSE 80 -# Run the nginx server -CMD ["nginx", "-g", "daemon off;"] +# Copy .env file and shell script to container +WORKDIR /usr/share/nginx/html +COPY ./init.sh . +COPY .env . + +# Add bash +RUN apk add --no-cache bash + +# Make our shell script executable +RUN chmod +x init.sh + +# Start Nginx server +CMD ["/bin/bash", "-c", "/usr/share/nginx/html/init.sh && nginx -g \"daemon off;\""] diff --git a/README.md b/README.md index 3752f2eee..d97636491 100644 --- a/README.md +++ b/README.md @@ -19,8 +19,8 @@ # git clone [the url of the repository] For example; # git clone https://github.com/yourusername/openmrs-ocl-client.git # Create a .env file in the root directory with the variables API URL and Traditional OCL URL as shown below to access app in dev mode; - REACT_APP_OCL_API_HOST=https://api.qa.openconceptlab.org/ - REACT_APP_TRADITIONAL_OCL_HOST=https://qa.openconceptlab.org + OCL_API_HOST=https://api.qa.openconceptlab.org/ + TRADITIONAL_OCL_HOST=https://qa.openconceptlab.org - In the root directory of the project install all the dependencies using the command below $ npm install diff --git a/init.sh b/init.sh new file mode 100755 index 000000000..da6708d8e --- /dev/null +++ b/init.sh @@ -0,0 +1,29 @@ +#!/bin/bash + +# Recreate config file +rm -rf ./env-config.js +touch ./env-config.js + +# Add assignment +echo "window.env = {" >> ./env-config.js + +# Read each line in .env file +# Each line represents key=value pairs +while read -r line || [[ -n "$line" ]]; +do + # Split env variables by character `=` + if printf '%s\n' "$line" | grep -q -e '='; then + varname=$(printf '%s\n' "$line" | sed -e 's/=.*//') + varvalue=$(printf '%s\n' "$line" | sed -e 's/^[^=]*=//') + fi + + # Read value of current variable if exists as Environment variable + value=$(printf '%s\n' "${!varname}") + # Otherwise use value from .env file + [[ -z $value ]] && value=${varvalue} + + # Append configuration property to JS file + echo " $varname: '$value'," >> ./env-config.js +done < .env + +echo "};" >> ./env-config.js diff --git a/package.json b/package.json index 693f31bff..8bbf5347f 100644 --- a/package.json +++ b/package.json @@ -29,7 +29,7 @@ "uuid": "^3.3.2" }, "scripts": { - "start": "npm run build:css && react-scripts start", + "start": "chmod +x ./init.sh && ./init.sh && cp env-config.js ./public/ && npm run build:css && react-scripts start", "build": "npm run build:css && react-scripts build", "test": "react-scripts test --env=jsdom", "eject": "react-scripts eject", diff --git a/public/index.html b/public/index.html index 0e22c1ac3..5a8c66f3e 100644 --- a/public/index.html +++ b/public/index.html @@ -12,6 +12,7 @@ + OpenMRS OCL client diff --git a/src/components/dictionaryConcepts/components/ConceptNameRows.jsx b/src/components/dictionaryConcepts/components/ConceptNameRows.jsx index 35a26f367..222bd25a0 100644 --- a/src/components/dictionaryConcepts/components/ConceptNameRows.jsx +++ b/src/components/dictionaryConcepts/components/ConceptNameRows.jsx @@ -13,7 +13,8 @@ class ConceptNameRows extends Component { removeRow: PropTypes.func.isRequired, removeDataFromRow: PropTypes.func.isRequired, pathName: PropTypes.object.isRequired, - existingConcept: PropTypes.object.isRequired, + // eslint-disable-next-line react/require-default-props + existingConcept: PropTypes.object, rowId: PropTypes.string, }; diff --git a/src/config/index.js b/src/config/index.js index 985cd3375..6e400ada9 100644 --- a/src/config/index.js +++ b/src/config/index.js @@ -1,4 +1,4 @@ export default { - OCL_API_HOST: process.env.REACT_APP_OCL_HOST || 'https://api.qa.openconceptlab.org/', - TRADITIONAL_OCL: process.env.REACT_APP_TRADITIONAL_OCL_HOST || 'https://qa.openconceptlab.org', + OCL_API_HOST: (window.env && window.env.OCL_API_HOST) || 'https://api.qa.openconceptlab.org/', + TRADITIONAL_OCL: (window.env && window.env.TRADITIONAL_OCL_HOST) || 'https://qa.openconceptlab.org', }; diff --git a/src/tests/dictionaryConcepts/components/ConceptNameRows.test.jsx b/src/tests/dictionaryConcepts/components/ConceptNameRows.test.jsx index 7668c9b3a..ab96cf922 100644 --- a/src/tests/dictionaryConcepts/components/ConceptNameRows.test.jsx +++ b/src/tests/dictionaryConcepts/components/ConceptNameRows.test.jsx @@ -9,7 +9,6 @@ const props = { addDataFromRow: jest.fn(), removeRow: jest.fn(), removeDataFromRow: jest.fn(), - existingConcept: {}, newRow: { uuid: '123', },