Skip to content

Commit

Permalink
Merge pull request #111 from LuCEresearchlab/deployment-fixes
Browse files Browse the repository at this point in the history
Deployment fixes
  • Loading branch information
malags authored May 7, 2021
2 parents 6e0645b + f51cc3b commit b47afa0
Show file tree
Hide file tree
Showing 27 changed files with 78 additions and 39 deletions.
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,21 @@ this will allow for a more scalable tagging experience.
- mongodb: Dockerfile for MongoDB server
- tagging service: Python Flask server


## Usage

The application is entirely dockerized and as such can be run as long as Docker is installed, to run it:

```
cd python-react-tagging-standalone
docker-compose up -d # development
docker-compose -f docker-compose-deploy.yml up -d # deployment
```

then connect to http://localhost:8080/

In the case of deploying the application it is required to set
`TAGGING_SERVICE_URL=<host-url>:5000` inside the file `frontend/.env.prod`.

To stop the containers

```
Expand Down
2 changes: 2 additions & 0 deletions frontend/.dockerignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
**/node_modules
build
logs
1 change: 0 additions & 1 deletion frontend/.env
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
NODE_PATH=./
TAGGING_SERVICE_URL=http://localhost:5000
1 change: 1 addition & 0 deletions frontend/.env.prod
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
TAGGING_SERVICE_URL=http://192.168.1.169:5000
19 changes: 17 additions & 2 deletions frontend/Dockerfile-deploy
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM node:15.14.0-alpine3.10
FROM node:15.14.0-alpine3.10 as build

EXPOSE 8080

Expand All @@ -10,4 +10,19 @@ RUN npm ci

RUN npm run build

CMD ["node", "server.js"]
FROM nginx:alpine

# copy the build folder from react to the root of nginx (www)
COPY --from=build /app/build /usr/share/nginx/html

# --------- only for those using react router ----------
# if you are using react router
# you need to overwrite the default nginx configurations
# remove default nginx configuration file
RUN rm /etc/nginx/conf.d/default.conf
# replace with custom one
COPY nginx/nginx.conf /etc/nginx/conf.d

EXPOSE 8080

CMD ["nginx", "-g", "daemon off;"]
3 changes: 0 additions & 3 deletions frontend/config.json

This file was deleted.

17 changes: 17 additions & 0 deletions frontend/nginx/nginx.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
server {

listen 8080;

location / {
root /usr/share/nginx/html;
index index.html index.htm;
try_files $uri $uri/ /index.html;
}


error_page 500 502 503 504 /50x.html;

location = /50x.html {
root /usr/share/nginx/html;
}
}
6 changes: 6 additions & 0 deletions frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
"babel-jest": "^26.6.3",
"babel-loader": "^8.2.2",
"clean-webpack-plugin": "^3.0.0",
"dotenv": "^9.0.0",
"eslint": "^7.20.0",
"eslint-config-prettier": "^7.2.0",
"eslint-plugin-jest": "^24.1.3",
Expand Down
16 changes: 0 additions & 16 deletions frontend/server.js

This file was deleted.

2 changes: 1 addition & 1 deletion frontend/src/components/diff_component/AnswersMerger.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import stringEquals from "../../util/StringEquals";
import {useFetch} from "../../hooks/useFetch";


const {TAGGING_SERVICE_URL} = require('../../../config.json')
const TAGGING_SERVICE_URL = process.env.TAGGING_SERVICE_URL

interface Input {
dataset_id: string,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import NoMisconception from "../../util/NoMisconception";
import {FormatColorReset} from "@material-ui/icons";
import {highlightRangeToColor, highlightStyle} from "../../helpers/Util";

const {TAGGING_SERVICE_URL} = require('../../../config.json')
const TAGGING_SERVICE_URL = process.env.TAGGING_SERVICE_URL

const useStyles = makeStyles((theme: Theme) =>
createStyles({
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/v2/TaggingUI.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import ClusterHandler from "./cluster_handler_component/ClusterHandler";
import withKeyboard from "../../hooks/withKeyboard";
import {useFetch} from "../../hooks/useFetch";

const {TAGGING_SERVICE_URL} = require('../../../config.json')
const TAGGING_SERVICE_URL = process.env.TAGGING_SERVICE_URL

interface Input {
taggingSession: TaggingSession,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import {setClusters} from "../../../model/TaggingClusterSessionDispatch";
import {Clear, Search} from "@material-ui/icons";
import DroppableCluster from "./DroppableCluster";

const {TAGGING_SERVICE_URL} = require('../../../../config.json')
const TAGGING_SERVICE_URL = process.env.TAGGING_SERVICE_URL

interface Input {
taggingSession: TaggingSession,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import withKeyboard from "../../../hooks/withKeyboard";
import stringEquals from "../../../util/StringEquals";
import {postClusters} from "../../../helpers/PostHelper";

const {TAGGING_SERVICE_URL} = require('../../../../config.json')
const TAGGING_SERVICE_URL = process.env.TAGGING_SERVICE_URL

interface Input {
taggingClusterSession: TaggingClusterSession,
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/helpers/DownloadHelper.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const {TAGGING_SERVICE_URL} = require('../../config.json')
const TAGGING_SERVICE_URL = process.env.TAGGING_SERVICE_URL
const download_url = TAGGING_SERVICE_URL + '/datasets/download/dataset/'

// https://www.codevoila.com/post/30/export-json-data-to-downloadable-file-using-javascript
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/helpers/PostHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {HighlightRange} from "../interfaces/HighlightRange";
import {Cluster} from "../interfaces/Dataset";


const {TAGGING_SERVICE_URL} = require('../../config.json')
const TAGGING_SERVICE_URL = process.env.TAGGING_SERVICE_URL

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

Expand Down
2 changes: 1 addition & 1 deletion frontend/src/pages/auth/Login.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {User, userContext} from "../../util/UserContext";
import {FiberManualRecord} from "@material-ui/icons";
import {useHistory} from "react-router-dom";

const {TAGGING_SERVICE_URL} = require('../../../config.json')
const TAGGING_SERVICE_URL = process.env.TAGGING_SERVICE_URL

interface Input {
setSession(session: User): void
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/pages/tagging/DatasetSelection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {DatasetDesc} from "../../interfaces/Dataset";
import {userContext} from "../../util/UserContext";


const {TAGGING_SERVICE_URL} = require('../../../config.json')
const TAGGING_SERVICE_URL = process.env.TAGGING_SERVICE_URL


const redirect = (id: string, url: string, user_id: string, router: any) => {
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/pages/tagging/DiffView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {MisconceptionElement} from "../../interfaces/MisconceptionElement";
import {useFetch} from "../../hooks/useFetch";


const {TAGGING_SERVICE_URL} = require('../../../config.json')
const TAGGING_SERVICE_URL = process.env.TAGGING_SERVICE_URL


const useStyles = makeStyles(() =>
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/pages/tagging/TaggingDetailPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {StyledTableCell, StyledTableRow, useStyles} from "../../components/style
// @ts-ignore
import Highlightable from "highlightable";

const {TAGGING_SERVICE_URL} = require('../../../config.json')
const TAGGING_SERVICE_URL = process.env.TAGGING_SERVICE_URL

function TaggingDetailPage() {

Expand Down
2 changes: 1 addition & 1 deletion frontend/src/pages/tagging/TaggingPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import useTaggingClusterSession from "../../model/TaggingClusterSession";
import {userContext} from "../../util/UserContext";
import {useFetch} from "../../hooks/useFetch";

const {TAGGING_SERVICE_URL} = require('../../../config.json')
const TAGGING_SERVICE_URL = process.env.TAGGING_SERVICE_URL

function TaggingPage() {

Expand Down
2 changes: 1 addition & 1 deletion frontend/src/pages/tagging/TaggingSummaryPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {Paper, Table, TableBody, TableContainer, TableHead, TableRow} from "@mat
import {StyledTableCell, StyledTableRow, useStyles} from "../../components/styled/StyledTable";


const {TAGGING_SERVICE_URL} = require('../../../config.json')
const TAGGING_SERVICE_URL = process.env.TAGGING_SERVICE_URL

interface Stats {
count: number,
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/pages/upload/FileUploader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {makeStyles, createStyles, Theme} from '@material-ui/core/styles';
import React, {useState} from 'react';


const TAGGING_SERVICE_URL = require('../../../config.json').TAGGING_SERVICE_URL
const TAGGING_SERVICE_URL = process.env.TAGGING_SERVICE_URL

const useStyles = makeStyles((theme: Theme) =>
createStyles({
Expand Down
5 changes: 5 additions & 0 deletions frontend/webpack.dev.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import HtmlWebpackPlugin from "html-webpack-plugin";
import ForkTsCheckerWebpackPlugin from 'fork-ts-checker-webpack-plugin';
import ESLintPlugin from "eslint-webpack-plugin";

require('dotenv').config();

const config: webpack.Configuration = {
mode: "development",
output: {
Expand Down Expand Up @@ -43,6 +45,9 @@ const config: webpack.Configuration = {
new ESLintPlugin({
extensions: ["js", "jsx", "ts", "tsx"],
}),
new webpack.DefinePlugin({
'process.env.TAGGING_SERVICE_URL': 'http://localhost:5000'
}),
],
devtool: "inline-source-map",
devServer: {
Expand Down
9 changes: 8 additions & 1 deletion frontend/webpack.prod.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ import webpack from "webpack";
import HtmlWebpackPlugin from "html-webpack-plugin";
import ForkTsCheckerWebpackPlugin from "fork-ts-checker-webpack-plugin";
import ESLintPlugin from "eslint-webpack-plugin";
import { CleanWebpackPlugin } from "clean-webpack-plugin";
import {CleanWebpackPlugin} from "clean-webpack-plugin";

require('dotenv').config({
path: path.join(__dirname, '.env.prod')
});

const config: webpack.Configuration = {
mode: "production",
Expand Down Expand Up @@ -45,6 +49,9 @@ const config: webpack.Configuration = {
extensions: ["js", "jsx", "ts", "tsx"],
}),
new CleanWebpackPlugin(),
new webpack.DefinePlugin({
'process.env.TAGGING_SERVICE_URL': JSON.stringify(process.env.TAGGING_SERVICE_URL)
}),
],
};

Expand Down
2 changes: 1 addition & 1 deletion tagging-service/flaskr/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def create_app(test_config=None):
api.init_app(app)
cache.init_app(app)
app.config.from_pyfile('./config/env_config.py')
CORS(app, resources={r'/*': {"origins": "http://localhost:8080"}})
CORS(app, resources={r'/*': {"origins": "*"}})

@app.errorhandler(Error)
def handle_invalid_usage(error):
Expand Down

0 comments on commit b47afa0

Please sign in to comment.