diff --git a/client/.dockerignore b/.dockerignore similarity index 100% rename from client/.dockerignore rename to .dockerignore diff --git a/.env.sample b/.env.sample new file mode 100644 index 0000000..2158884 --- /dev/null +++ b/.env.sample @@ -0,0 +1,3 @@ +PORT=4040 +MONGO_URI="mongodb://mongo:secretPassword@mongo" +API_KEY="something-secret" \ No newline at end of file diff --git a/.gitignore b/.gitignore index 4be95fe..23cbbb7 100644 --- a/.gitignore +++ b/.gitignore @@ -1,31 +1,16 @@ # dependencies -**/*/node_modules +/node_modules /.pnp .pnp.js # misc .DS_Store -.env.local -.env.development.local -.env.test.local -.env.production.local +.env npm-debug.log* yarn-debug.log* yarn-error.log* -# Client -client/src/config/*.json -!client/src/config/default.json -!client/src/config/docker.json - -# testing -client/coverage - -# production -client/build - -# Server -server/src/config/*.json -!server/src/config/default.json -!server/src/config/docker.json +# compiled +public/*.js +public/*.txt diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..a8a40f4 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,38 @@ +# FROM node:16-alpine as build +# WORKDIR /app + +# COPY package*.json ./ +# COPY public/ ./public/ + +# RUN npm ci --silent +# RUN npm install react-scripts@4.0.3 -g --silent + +# COPY src/ ./src/ + +# RUN npm run build + +# FROM nginx:stable-alpine +# RUN apk add --no-cache jq + +# COPY --from=build /app/build /usr/share/nginx/html +# EXPOSE 80 + +# COPY docker-entrypoint.sh / +# ENTRYPOINT ["/docker-entrypoint.sh"] +# CMD ["nginx", "-g", "daemon off;"] + +# FROM node:16-alpine +# WORKDIR /server + +# ENV NODE_ENV=docker + +# RUN chown node:node /server +# USER node + +# COPY --chown=node:node src/package*.json ./ + +# RUN npm install + +# COPY --chown=node:node src/ ./ + +# CMD ["node", "server.js"] diff --git a/babel.config.json b/babel.config.json new file mode 100644 index 0000000..fbd6da0 --- /dev/null +++ b/babel.config.json @@ -0,0 +1,6 @@ +{ + "presets": [ + "@babel/preset-env", + "@babel/preset-react" + ] +} \ No newline at end of file diff --git a/client/.env b/client/.env deleted file mode 100644 index cbf212e..0000000 --- a/client/.env +++ /dev/null @@ -1 +0,0 @@ -REACT_APP_DASH_API_URL=http://localhost:9090 \ No newline at end of file diff --git a/client/Dockerfile b/client/Dockerfile deleted file mode 100644 index 61377fc..0000000 --- a/client/Dockerfile +++ /dev/null @@ -1,22 +0,0 @@ -FROM node:16-alpine as build -WORKDIR /app - -COPY package*.json ./ -COPY public/ ./public/ - -RUN npm ci --silent -RUN npm install react-scripts@4.0.3 -g --silent - -COPY src/ ./src/ - -RUN npm run build - -FROM nginx:stable-alpine -RUN apk add --no-cache jq - -COPY --from=build /app/build /usr/share/nginx/html -EXPOSE 80 - -COPY docker-entrypoint.sh / -ENTRYPOINT ["/docker-entrypoint.sh"] -CMD ["nginx", "-g", "daemon off;"] diff --git a/client/README.md b/client/README.md deleted file mode 100644 index 3446eaf..0000000 --- a/client/README.md +++ /dev/null @@ -1,74 +0,0 @@ -# App Dash Client (React) -This is the main UI for the "App-Dash" project. - -It's built with [React](https://reactjs.org/) and [MaterialUI](https://mui.com/) - -## Run -The client can be run as a Docker container, or locally for development. - -### Docker container -The container uses an entrypoint script that will read the environment variables that start with `REACT_APP_` and add them to the `window.ENV` object. - -> Thanks to [axelhzf](https://github.com/axelhzf)'s repo: [create-react-app-docker-environment-variables](https://github.com/axelhzf/create-react-app-docker-environment-variables) - -This is how the api url is accessed at runtime allowing you to deploy this client code using different backends as desired. - -- First, build the image - -```shell -docker build -t app-dash-client . -``` - -- Then, run the container and map the port - - Be sure to set the environment variable for the `REACT_APP_DASH_API_URL` - -```shell -docker run -p 3001:80 -e REACT_APP_DASH_API_URL='http://localhost:9090' app-dash-client -``` - -- Access the site at [http://localhost:3001](http://localhost:3001) - -### Locally -- First, be sure the node_modules are installed -```shell -npm i --silent -``` - -- Invoke the `start` command from `react-scripts` - - The URL for the server is set in the `.env` file as a default to the localhost server - - See the React docs [Adding Custom Environment Variables](https://create-react-app.dev/docs/adding-custom-environment-variables/) for ways to override this. - -```shell -npm start -``` - -- Access the site at [http://localhost:3000](http://localhost:3000) - - -## Create React App (Generated) - -This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app). - -### Available Scripts - -In the project directory, you can run: - -- `npm start` - - Runs the app in the development mode. - - Open [http://localhost:3000](http://localhost:3000) to view it in the browser. - - - The page will reload if you make edits. - - You will also see any lint errors in the console. - -- `npm test` - - Launches the test runner in the interactive watch mode. - - See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information. - -- `npm run build` - - Builds the app for production to the `build` folder. - - It correctly bundles React in production mode and optimizes the build for the best performance. - - - The build is minified and the filenames include the hashes. - - Your app is ready to be deployed! - - - See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information. diff --git a/client/docker-entrypoint.sh b/client/docker-entrypoint.sh deleted file mode 100755 index 4513403..0000000 --- a/client/docker-entrypoint.sh +++ /dev/null @@ -1,14 +0,0 @@ -#!/bin/sh -set -euo pipefail - -# Capture all environment variables starting with APP_DASH_ and make JSON string from them -ENV_JSON="$(jq --compact-output --null-input 'env | with_entries(select(.key | startswith("REACT_APP_")))')" - -# Escape sed replacement's special characters: \, &, /. -# No need to escape newlines, because --compact-output already removed them. -# Inside of JSON strings newlines are already escaped. -ENV_JSON_ESCAPED="$(printf "%s" "${ENV_JSON}" | sed -e 's/[\&/]/\\&/g')" - -sed -i "s/