Skip to content

Commit c5451ca

Browse files
committed
CH-109 update frontend libraries
1 parent d4c03cf commit c5451ca

17 files changed

Lines changed: 7556 additions & 8909 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
connexion[swagger-ui]==2.14.2
2+
swagger-ui-bundle >= 0.0.2
3+
python_dateutil >= 2.6.0
4+
setuptools >= 21.0.0
5+
Flask<3.0.0
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# coding: utf-8
2+
3+
import sys
4+
from setuptools import setup, find_packages
5+
6+
NAME = "__APP_NAME__"
7+
VERSION = "1.0.0"
8+
9+
# To install the library, run the following
10+
#
11+
# python setup.py install
12+
#
13+
# prerequisite: setuptools
14+
# http://pypi.python.org/pypi/setuptools
15+
16+
REQUIRES = [
17+
"connexion>=2.0.2",
18+
"swagger-ui-bundle>=0.0.2",
19+
"python_dateutil>=2.6.0",
20+
"pyjwt>=2.6.0",
21+
"cloudharness"
22+
]
23+
24+
setup(
25+
name=NAME,
26+
version=VERSION,
27+
description="__APP_NAME__",
28+
author_email="cloudharness@metacell.us",
29+
url="",
30+
keywords=["OpenAPI", "__APP_NAME__"],
31+
install_requires=REQUIRES,
32+
packages=find_packages(),
33+
package_data={'': ['openapi/openapi.yaml']},
34+
include_package_data=True,
35+
entry_points={
36+
'console_scripts': ['__APP_NAME__=__APP_NAME__.__main__:main']},
37+
long_description="""\
38+
__APP_NAME__
39+
"""
40+
)
41+

application-templates/webapp/Dockerfile

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,28 +7,28 @@ ENV APP_DIR=/app
77

88
WORKDIR ${APP_DIR}
99
COPY frontend/package.json ${APP_DIR}
10-
COPY frontend/package-lock.json ${APP_DIR}
11-
RUN npm ci
10+
COPY frontend/yarn.lock ${APP_DIR}
11+
RUN yarn install --frozen-lockfile --timeout 60000
1212

1313
COPY frontend ${APP_DIR}
14-
RUN npm run build
14+
RUN yarn build
1515

1616
#####
17-
1817
FROM $CLOUDHARNESS_FLASK
19-
20-
ENV MODULE_NAME=__APP_NAME__
18+
ENV MODULE_NAME=samples
2119

2220
ENV WORKERS=2
2321
ENV PORT=8080
2422

2523
COPY backend/requirements.txt /usr/src/app/
2624

27-
RUN pip3 install --no-cache-dir -r requirements.txt
25+
RUN --mount=type=cache,target=/root/.cache python -m pip install --upgrade pip &&\
26+
pip3 install -r requirements.txt --prefer-binary
2827

2928
COPY backend/ /usr/src/app
30-
RUN pip3 install -e .
3129

3230
COPY --from=frontend app/dist/ /usr/src/app/www
3331

34-
ENTRYPOINT gunicorn --workers=$WORKERS --bind=0.0.0.0:$PORT $MODULE_NAME.__main__:app
32+
RUN pip3 install -e .
33+
34+
CMD gunicorn --workers=$WORKERS --bind=0.0.0.0:$PORT $MODULE_NAME.__main__:app --timeout 180

application-templates/webapp/frontend/package.json

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@
1111
"prestart": "eslint . --color --fix",
1212
"start": "webpack serve --progress --env DOMAIN=http://localhost:5000 --config webpack.config.dev.js",
1313
"start:dev": "webpack serve --progress --env.DOMAIN=https://__APP_NAME__.cloudharness.metacell.us --config webpack.config.dev.js",
14-
"start:minikube": "webpack serve --progress --env DOMAIN=http://__APP_NAME__.cloudharness.local --config webpack.config.dev.js"
14+
"start:local": "webpack serve --progress --env DOMAIN=http://__APP_NAME__.ch.local --config webpack.config.dev.js"
1515
},
1616
"author": "",
17-
"license": "ISC",
17+
"license": "MIT",
1818
"dependencies": {
1919
"axios": "^0.21.1",
2020
"react": "^16.12.0",
@@ -28,31 +28,33 @@
2828
"@babel/plugin-proposal-class-properties": "^7.8.3",
2929
"@babel/preset-env": "^7.8.3",
3030
"@babel/preset-react": "^7.8.3",
31-
"awesome-typescript-loader": "^5.2.1",
3231
"babel-eslint": "^10.1.0",
3332
"babel-loader": "^8.0.6",
3433
"babel-plugin-module-resolver": "^4.0.0",
3534
"babel-preset-minify": "^0.5.1",
3635
"clean-webpack-plugin": "^3.0.0",
3736
"compression-webpack-plugin": "^7.1.2",
3837
"copy-webpack-plugin": "^6.2.1",
39-
"css-loader": "^3.4.2",
38+
"css-loader": "^5.2.4",
39+
"dotenv": "^16.0.2",
4040
"eslint": "5.16.0",
4141
"eslint-plugin-jest": "^23.8.2",
4242
"eslint-plugin-react": "^7.19.0",
4343
"eslint-plugin-react-hooks": "^3.0.0",
4444
"file-loader": "^5.0.2",
4545
"html-loader": "^0.5.5",
46-
"html-webpack-plugin": "^4.5.1",
46+
"html-webpack-plugin": "^5.5.0",
47+
"image-webpack-loader": "^8.1.0",
4748
"less": "^3.10.3",
48-
"less-loader": "^5.0.0",
49+
"less-loader": "^6.1.2",
4950
"less-vars-to-js": "^1.3.0",
5051
"raw-loader": "^4.0.2",
5152
"style-loader": "^1.1.3",
52-
"typescript": "^3.9.3",
53-
"webpack": "^5.0.0",
54-
"webpack-cli": "^4.3.1",
55-
"webpack-dev-server": "^3.11.1",
56-
"webpack-merge": "^5.0.0"
53+
"ts-loader": "^9.0.0",
54+
"typescript": "^4.8.3",
55+
"webpack": "^5.61.0",
56+
"webpack-cli": "^4.6.0",
57+
"webpack-dev-server": "^4.5.0",
58+
"webpack-merge": "^5.7.0"
5759
}
5860
}
141 KB
Loading

application-templates/webapp/frontend/src/components/RestTest.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ const test = new TestApi();
77
const RestTest = () => {
88
const [result, setResult] = useState(null);
99
useEffect(() => {
10-
test.ping().then(r => setResult(r));
10+
test.ping().then(r => setResult(r), () => setResult({ data: "API error"}));
1111
}, []);
1212

1313

14-
return result && <p>Backend answered: { result.data } </p>
14+
return result ? <p>Backend answered: { result.data } </p> : <p>Backend did not answer</p>
1515
}
1616

1717
export default RestTest;

application-templates/webapp/frontend/webpack.config.dev.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,13 @@ module.exports = env => {
2020

2121

2222
const devServer = {
23-
contentBase: path.join(__dirname, 'dist'),
23+
static: [{
24+
directory: path.resolve(__dirname, 'dist'),
25+
publicPath: '/',
26+
}],
2427
compress: true,
28+
https: env.DOMAIN.includes("https"),
2529
port: Number(env.devPort),
26-
disableHostCheck: true,
2730
historyApiFallback: true,
2831
proxy: {
2932
'/api/': {
Lines changed: 47 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
const path = require('path');
2-
const HtmlWebpackPlugin = require('html-webpack-plugin');
3-
const CompressionPlugin = require('compression-webpack-plugin');
4-
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
5-
const CopyWebpackPlugin = require('copy-webpack-plugin');
1+
const path = require("path");
2+
const HtmlWebpackPlugin = require("html-webpack-plugin");
3+
const CompressionPlugin = require("compression-webpack-plugin");
4+
const { CleanWebpackPlugin } = require("clean-webpack-plugin");
5+
const CopyWebpackPlugin = require("copy-webpack-plugin");
66

77
const copyPaths = [
8-
{ from: path.resolve(__dirname, "src/assets"), to: 'assets' },
8+
{ from: path.resolve(__dirname, "src/assets"), to: "assets" },
99
];
1010

1111
module.exports = function webpacking(envVariables) {
@@ -14,36 +14,43 @@ module.exports = function webpacking(envVariables) {
1414
env = {};
1515
}
1616
if (!env.mode) {
17-
env.mode = 'production';
17+
env.mode = "production";
1818
}
1919

20-
21-
console.log('####################');
22-
console.log('####################');
23-
console.log('BUILD bundle with parameters:');
24-
console.log( env);
25-
console.log('####################');
26-
console.log('####################');
20+
console.log("####################");
21+
console.log("####################");
22+
console.log("BUILD bundle with parameters:");
23+
console.log(env);
24+
console.log("####################");
25+
console.log("####################");
2726

2827
const { mode } = env;
29-
const devtool = env.mode === 'source-map';
30-
28+
const devtool = "source-map";
3129

3230
const output = {
33-
path: path.resolve(__dirname, 'dist'),
34-
filename: '[name].[contenthash].js'
31+
path: path.resolve(__dirname, "dist"),
32+
filename: "[name].[contenthash].js",
33+
publicPath: "/"
3534
};
3635

3736
const module = {
3837
rules: [
3938
{
4039
test: /\.(js|jsx)$/,
4140
exclude: /node_modules/,
42-
loader: 'babel-loader'
41+
loader: "babel-loader",
4342
},
4443
{
45-
test: /\.ts|tsx?$/,
46-
loader: "awesome-typescript-loader"
44+
test: /\.ts(x?)$/,
45+
include: path.resolve(__dirname, 'src'),
46+
use: [
47+
{
48+
loader: "ts-loader",
49+
options: {
50+
transpileOnly: true,
51+
},
52+
}
53+
]
4754
},
4855
{
4956
test: /\.(css)$/,
@@ -53,7 +60,8 @@ module.exports = function webpacking(envVariables) {
5360
},
5461
{
5562
loader: "css-loader",
56-
}],
63+
},
64+
],
5765
},
5866
{
5967
test: /\.less$/,
@@ -76,27 +84,33 @@ module.exports = function webpacking(envVariables) {
7684
},
7785
{
7886
test: /\.(png|jpg|gif|eot|woff|woff2|svg|ttf)$/,
79-
loader: 'file-loader'
87+
use: [
88+
"file-loader",
89+
{
90+
loader: "image-webpack-loader",
91+
options: {
92+
bypassOnDebug: true, // webpack@1.x
93+
disable: true, // webpack@2.x and newer
94+
},
95+
},
96+
],
8097
},
81-
82-
]
98+
],
8399
};
84100

85101
const resolve = {
86-
extensions: ['*', '.js', '.json', '.ts', '.tsx', '.jsx'],
87-
symlinks: false
102+
extensions: ["*", ".js", ".json", ".ts", ".tsx", ".jsx"],
103+
symlinks: false,
88104
};
89105

90-
91-
92106
const plugins = [
93107
new CleanWebpackPlugin(),
94108
new CopyWebpackPlugin({ patterns: copyPaths }),
95109
new CompressionPlugin(),
96110
new HtmlWebpackPlugin({
97-
template: 'src/index.ejs',
98-
favicon: path.join(__dirname, 'src/assets/icon.png')
99-
})
111+
template: "src/index.ejs",
112+
favicon: path.join(__dirname, "src/assets/icon.png"),
113+
}),
100114
];
101115

102116
return {
@@ -105,6 +119,6 @@ module.exports = function webpacking(envVariables) {
105119
output,
106120
module,
107121
resolve,
108-
plugins
122+
plugins,
109123
};
110124
};

applications/samples/Dockerfile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ ENV APP_DIR=/app
77

88
WORKDIR ${APP_DIR}
99
COPY frontend/package.json ${APP_DIR}
10-
COPY frontend/package-lock.json ${APP_DIR}
11-
RUN npm ci
10+
COPY frontend/yarn.lock ${APP_DIR}
11+
RUN yarn install --frozen-lockfile --timeout 60000
1212

1313
COPY frontend ${APP_DIR}
14-
RUN npm run build
14+
RUN yarn build
1515

1616
#####
1717
FROM $CLOUDHARNESS_FLASK

0 commit comments

Comments
 (0)