Skip to content

Commit b47afa0

Browse files
authored
Merge pull request #111 from LuCEresearchlab/deployment-fixes
Deployment fixes
2 parents 6e0645b + f51cc3b commit b47afa0

27 files changed

+78
-39
lines changed

README.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,21 @@ this will allow for a more scalable tagging experience.
1414
- mongodb: Dockerfile for MongoDB server
1515
- tagging service: Python Flask server
1616

17-
1817
## Usage
18+
1919
The application is entirely dockerized and as such can be run as long as Docker is installed, to run it:
20+
2021
```
2122
cd python-react-tagging-standalone
2223
docker-compose up -d # development
2324
docker-compose -f docker-compose-deploy.yml up -d # deployment
2425
```
26+
2527
then connect to http://localhost:8080/
2628

29+
In the case of deploying the application it is required to set
30+
`TAGGING_SERVICE_URL=<host-url>:5000` inside the file `frontend/.env.prod`.
31+
2732
To stop the containers
2833

2934
```

frontend/.dockerignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
11
**/node_modules
2+
build
3+
logs

frontend/.env

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
11
NODE_PATH=./
2-
TAGGING_SERVICE_URL=http://localhost:5000

frontend/.env.prod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
TAGGING_SERVICE_URL=http://192.168.1.169:5000

frontend/Dockerfile-deploy

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM node:15.14.0-alpine3.10
1+
FROM node:15.14.0-alpine3.10 as build
22

33
EXPOSE 8080
44

@@ -10,4 +10,19 @@ RUN npm ci
1010

1111
RUN npm run build
1212

13-
CMD ["node", "server.js"]
13+
FROM nginx:alpine
14+
15+
# copy the build folder from react to the root of nginx (www)
16+
COPY --from=build /app/build /usr/share/nginx/html
17+
18+
# --------- only for those using react router ----------
19+
# if you are using react router
20+
# you need to overwrite the default nginx configurations
21+
# remove default nginx configuration file
22+
RUN rm /etc/nginx/conf.d/default.conf
23+
# replace with custom one
24+
COPY nginx/nginx.conf /etc/nginx/conf.d
25+
26+
EXPOSE 8080
27+
28+
CMD ["nginx", "-g", "daemon off;"]

frontend/config.json

Lines changed: 0 additions & 3 deletions
This file was deleted.

frontend/nginx/nginx.conf

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
server {
2+
3+
listen 8080;
4+
5+
location / {
6+
root /usr/share/nginx/html;
7+
index index.html index.htm;
8+
try_files $uri $uri/ /index.html;
9+
}
10+
11+
12+
error_page 500 502 503 504 /50x.html;
13+
14+
location = /50x.html {
15+
root /usr/share/nginx/html;
16+
}
17+
}

frontend/package-lock.json

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

frontend/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
"babel-jest": "^26.6.3",
4545
"babel-loader": "^8.2.2",
4646
"clean-webpack-plugin": "^3.0.0",
47+
"dotenv": "^9.0.0",
4748
"eslint": "^7.20.0",
4849
"eslint-config-prettier": "^7.2.0",
4950
"eslint-plugin-jest": "^24.1.3",

frontend/server.js

Lines changed: 0 additions & 16 deletions
This file was deleted.

frontend/src/components/diff_component/AnswersMerger.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import stringEquals from "../../util/StringEquals";
77
import {useFetch} from "../../hooks/useFetch";
88

99

10-
const {TAGGING_SERVICE_URL} = require('../../../config.json')
10+
const TAGGING_SERVICE_URL = process.env.TAGGING_SERVICE_URL
1111

1212
interface Input {
1313
dataset_id: string,

frontend/src/components/tagger_component/MisconceptionTagElement.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import NoMisconception from "../../util/NoMisconception";
2222
import {FormatColorReset} from "@material-ui/icons";
2323
import {highlightRangeToColor, highlightStyle} from "../../helpers/Util";
2424

25-
const {TAGGING_SERVICE_URL} = require('../../../config.json')
25+
const TAGGING_SERVICE_URL = process.env.TAGGING_SERVICE_URL
2626

2727
const useStyles = makeStyles((theme: Theme) =>
2828
createStyles({

frontend/src/components/v2/TaggingUI.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import ClusterHandler from "./cluster_handler_component/ClusterHandler";
2424
import withKeyboard from "../../hooks/withKeyboard";
2525
import {useFetch} from "../../hooks/useFetch";
2626

27-
const {TAGGING_SERVICE_URL} = require('../../../config.json')
27+
const TAGGING_SERVICE_URL = process.env.TAGGING_SERVICE_URL
2828

2929
interface Input {
3030
taggingSession: TaggingSession,

frontend/src/components/v2/cluster_handler_component/ClusterHandler.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import {setClusters} from "../../../model/TaggingClusterSessionDispatch";
2121
import {Clear, Search} from "@material-ui/icons";
2222
import DroppableCluster from "./DroppableCluster";
2323

24-
const {TAGGING_SERVICE_URL} = require('../../../../config.json')
24+
const TAGGING_SERVICE_URL = process.env.TAGGING_SERVICE_URL
2525

2626
interface Input {
2727
taggingSession: TaggingSession,

frontend/src/components/v2/tagger_component/ClusterView.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import withKeyboard from "../../../hooks/withKeyboard";
3030
import stringEquals from "../../../util/StringEquals";
3131
import {postClusters} from "../../../helpers/PostHelper";
3232

33-
const {TAGGING_SERVICE_URL} = require('../../../../config.json')
33+
const TAGGING_SERVICE_URL = process.env.TAGGING_SERVICE_URL
3434

3535
interface Input {
3636
taggingClusterSession: TaggingClusterSession,

frontend/src/helpers/DownloadHelper.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const {TAGGING_SERVICE_URL} = require('../../config.json')
1+
const TAGGING_SERVICE_URL = process.env.TAGGING_SERVICE_URL
22
const download_url = TAGGING_SERVICE_URL + '/datasets/download/dataset/'
33

44
// https://www.codevoila.com/post/30/export-json-data-to-downloadable-file-using-javascript

frontend/src/helpers/PostHelper.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import {HighlightRange} from "../interfaces/HighlightRange";
22
import {Cluster} from "../interfaces/Dataset";
33

44

5-
const {TAGGING_SERVICE_URL} = require('../../config.json')
5+
const TAGGING_SERVICE_URL = process.env.TAGGING_SERVICE_URL
66

77
const post_answer_url = TAGGING_SERVICE_URL + '/datasets/tagged-answer'
88

frontend/src/pages/auth/Login.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {User, userContext} from "../../util/UserContext";
55
import {FiberManualRecord} from "@material-ui/icons";
66
import {useHistory} from "react-router-dom";
77

8-
const {TAGGING_SERVICE_URL} = require('../../../config.json')
8+
const TAGGING_SERVICE_URL = process.env.TAGGING_SERVICE_URL
99

1010
interface Input {
1111
setSession(session: User): void

frontend/src/pages/tagging/DatasetSelection.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {DatasetDesc} from "../../interfaces/Dataset";
99
import {userContext} from "../../util/UserContext";
1010

1111

12-
const {TAGGING_SERVICE_URL} = require('../../../config.json')
12+
const TAGGING_SERVICE_URL = process.env.TAGGING_SERVICE_URL
1313

1414

1515
const redirect = (id: string, url: string, user_id: string, router: any) => {

frontend/src/pages/tagging/DiffView.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {MisconceptionElement} from "../../interfaces/MisconceptionElement";
99
import {useFetch} from "../../hooks/useFetch";
1010

1111

12-
const {TAGGING_SERVICE_URL} = require('../../../config.json')
12+
const TAGGING_SERVICE_URL = process.env.TAGGING_SERVICE_URL
1313

1414

1515
const useStyles = makeStyles(() =>

frontend/src/pages/tagging/TaggingDetailPage.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {StyledTableCell, StyledTableRow, useStyles} from "../../components/style
88
// @ts-ignore
99
import Highlightable from "highlightable";
1010

11-
const {TAGGING_SERVICE_URL} = require('../../../config.json')
11+
const TAGGING_SERVICE_URL = process.env.TAGGING_SERVICE_URL
1212

1313
function TaggingDetailPage() {
1414

frontend/src/pages/tagging/TaggingPage.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import useTaggingClusterSession from "../../model/TaggingClusterSession";
88
import {userContext} from "../../util/UserContext";
99
import {useFetch} from "../../hooks/useFetch";
1010

11-
const {TAGGING_SERVICE_URL} = require('../../../config.json')
11+
const TAGGING_SERVICE_URL = process.env.TAGGING_SERVICE_URL
1212

1313
function TaggingPage() {
1414

frontend/src/pages/tagging/TaggingSummaryPage.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {Paper, Table, TableBody, TableContainer, TableHead, TableRow} from "@mat
66
import {StyledTableCell, StyledTableRow, useStyles} from "../../components/styled/StyledTable";
77

88

9-
const {TAGGING_SERVICE_URL} = require('../../../config.json')
9+
const TAGGING_SERVICE_URL = process.env.TAGGING_SERVICE_URL
1010

1111
interface Stats {
1212
count: number,

frontend/src/pages/upload/FileUploader.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import {makeStyles, createStyles, Theme} from '@material-ui/core/styles';
33
import React, {useState} from 'react';
44

55

6-
const TAGGING_SERVICE_URL = require('../../../config.json').TAGGING_SERVICE_URL
6+
const TAGGING_SERVICE_URL = process.env.TAGGING_SERVICE_URL
77

88
const useStyles = makeStyles((theme: Theme) =>
99
createStyles({

frontend/webpack.dev.config.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import HtmlWebpackPlugin from "html-webpack-plugin";
44
import ForkTsCheckerWebpackPlugin from 'fork-ts-checker-webpack-plugin';
55
import ESLintPlugin from "eslint-webpack-plugin";
66

7+
require('dotenv').config();
8+
79
const config: webpack.Configuration = {
810
mode: "development",
911
output: {
@@ -43,6 +45,9 @@ const config: webpack.Configuration = {
4345
new ESLintPlugin({
4446
extensions: ["js", "jsx", "ts", "tsx"],
4547
}),
48+
new webpack.DefinePlugin({
49+
'process.env.TAGGING_SERVICE_URL': 'http://localhost:5000'
50+
}),
4651
],
4752
devtool: "inline-source-map",
4853
devServer: {

frontend/webpack.prod.config.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@ import webpack from "webpack";
33
import HtmlWebpackPlugin from "html-webpack-plugin";
44
import ForkTsCheckerWebpackPlugin from "fork-ts-checker-webpack-plugin";
55
import ESLintPlugin from "eslint-webpack-plugin";
6-
import { CleanWebpackPlugin } from "clean-webpack-plugin";
6+
import {CleanWebpackPlugin} from "clean-webpack-plugin";
7+
8+
require('dotenv').config({
9+
path: path.join(__dirname, '.env.prod')
10+
});
711

812
const config: webpack.Configuration = {
913
mode: "production",
@@ -45,6 +49,9 @@ const config: webpack.Configuration = {
4549
extensions: ["js", "jsx", "ts", "tsx"],
4650
}),
4751
new CleanWebpackPlugin(),
52+
new webpack.DefinePlugin({
53+
'process.env.TAGGING_SERVICE_URL': JSON.stringify(process.env.TAGGING_SERVICE_URL)
54+
}),
4855
],
4956
};
5057

tagging-service/flaskr/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ def create_app(test_config=None):
1414
api.init_app(app)
1515
cache.init_app(app)
1616
app.config.from_pyfile('./config/env_config.py')
17-
CORS(app, resources={r'/*': {"origins": "http://localhost:8080"}})
17+
CORS(app, resources={r'/*': {"origins": "*"}})
1818

1919
@app.errorhandler(Error)
2020
def handle_invalid_usage(error):

0 commit comments

Comments
 (0)