363 lines
11 KiB
YAML
363 lines
11 KiB
YAML
apiVersion: v1
|
|
kind: ConfigMap
|
|
metadata:
|
|
name: imes-basic-dashboard-nginx-conf
|
|
namespace: prd
|
|
data:
|
|
patch_dynamic_sql.py: |
|
|
from pathlib import Path
|
|
import re
|
|
|
|
patterns = [
|
|
(re.compile(r'headers:\{data:([A-Za-z_$][\w$]*),"Content-Type":"application/json"\},data:\1'),
|
|
r'headers:{"Content-Type":"application/json"},data:{crypto:\1,param:""}'),
|
|
(re.compile(r'headers:\{"Content-Type":"application/json",data:([A-Za-z_$][\w$]*)\},data:\1'),
|
|
r'headers:{"Content-Type":"application/json"},data:{crypto:\1,param:""}'),
|
|
]
|
|
|
|
paths = []
|
|
paths.extend(Path('/app/www/js').glob('*.js'))
|
|
paths.extend(Path('/app/www/lib').glob('*.js'))
|
|
paths.extend(Path('/app/www').glob('*.js'))
|
|
|
|
for path in paths:
|
|
text = path.read_text(errors='ignore')
|
|
updated = text
|
|
for pattern, replacement in patterns:
|
|
updated = pattern.sub(replacement, updated)
|
|
if updated != text:
|
|
path.write_text(updated)
|
|
|
|
db_compat.py: |
|
|
import json
|
|
import urllib.error
|
|
import urllib.request
|
|
from http.server import BaseHTTPRequestHandler, ThreadingHTTPServer
|
|
|
|
TARGET = 'http://imes-basic-mom-report-dashboard:6071/dashboard/db/dynamic-query'
|
|
|
|
class Handler(BaseHTTPRequestHandler):
|
|
def do_OPTIONS(self):
|
|
self.send_response(204)
|
|
self._cors()
|
|
self.end_headers()
|
|
|
|
def do_POST(self):
|
|
length = int(self.headers.get('Content-Length') or '0')
|
|
raw = self.rfile.read(length).decode('utf-8', errors='ignore').strip()
|
|
if raw.startswith('{'):
|
|
body = raw
|
|
else:
|
|
try:
|
|
crypto = json.loads(raw)
|
|
except Exception:
|
|
crypto = raw
|
|
body = json.dumps({'crypto': crypto, 'param': ''}, ensure_ascii=False)
|
|
|
|
req = urllib.request.Request(
|
|
TARGET,
|
|
data=body.encode('utf-8'),
|
|
headers={'Content-Type': 'application/json'},
|
|
method='POST',
|
|
)
|
|
try:
|
|
with urllib.request.urlopen(req, timeout=60) as resp:
|
|
data = resp.read()
|
|
self.send_response(resp.status)
|
|
self._cors()
|
|
self.send_header('Content-Type', resp.headers.get('Content-Type', 'application/json'))
|
|
self.end_headers()
|
|
self.wfile.write(data)
|
|
except urllib.error.HTTPError as err:
|
|
data = err.read()
|
|
self.send_response(err.code)
|
|
self._cors()
|
|
self.send_header('Content-Type', err.headers.get('Content-Type', 'application/json'))
|
|
self.end_headers()
|
|
self.wfile.write(data)
|
|
except Exception as exc:
|
|
data = json.dumps({'code': 1, 'msg': str(exc), 'data': None}).encode('utf-8')
|
|
self.send_response(502)
|
|
self._cors()
|
|
self.send_header('Content-Type', 'application/json')
|
|
self.end_headers()
|
|
self.wfile.write(data)
|
|
|
|
def log_message(self, fmt, *args):
|
|
return
|
|
|
|
def _cors(self):
|
|
self.send_header('Access-Control-Allow-Origin', '*')
|
|
self.send_header('Access-Control-Allow-Credentials', 'true')
|
|
self.send_header('Access-Control-Allow-Headers', '*')
|
|
self.send_header('Access-Control-Allow-Methods', 'PUT,POST,GET,DELETE,OPTIONS')
|
|
|
|
ThreadingHTTPServer(('0.0.0.0', 18080), Handler).serve_forever()
|
|
|
|
web.conf: |
|
|
server {
|
|
listen 80;
|
|
|
|
gzip on;
|
|
gzip_static on;
|
|
gzip_min_length 1k;
|
|
gzip_comp_level 4;
|
|
gzip_proxied any;
|
|
gzip_types text/plain text/xml text/css application/json application/javascript;
|
|
gzip_vary on;
|
|
gzip_disable "MSIE [1-6]\.(?!.*SV1)";
|
|
client_max_body_size "100M";
|
|
|
|
root /app/www;
|
|
|
|
location / {
|
|
root /app/www;
|
|
index index.html;
|
|
try_files $uri $uri/ /index.html;
|
|
}
|
|
|
|
location ~* \.(js|css)$ {
|
|
root /app/www;
|
|
add_header Cache-Control "no-cache, no-store, must-revalidate";
|
|
try_files $uri =404;
|
|
}
|
|
|
|
location = /api/visual-global/list {
|
|
proxy_redirect off;
|
|
proxy_set_header Host $host;
|
|
proxy_set_header X-real-ip $remote_addr;
|
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
|
proxy_pass http://imes-basic-mom-report-dashboard:6071/dashboard/visual/list;
|
|
}
|
|
|
|
location = /api/visual/list {
|
|
proxy_redirect off;
|
|
proxy_set_header Host $host;
|
|
proxy_set_header X-real-ip $remote_addr;
|
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
|
proxy_pass http://imes-basic-mom-report-dashboard:6071/dashboard/visual/list;
|
|
}
|
|
|
|
location = /api/visual/detail {
|
|
proxy_redirect off;
|
|
proxy_set_header Host $host;
|
|
proxy_set_header X-real-ip $remote_addr;
|
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
|
proxy_pass http://imes-basic-mom-report-dashboard:6071/dashboard/visual/detail;
|
|
}
|
|
|
|
location /api/db/ {
|
|
proxy_redirect off;
|
|
proxy_set_header Host $host;
|
|
proxy_set_header X-real-ip $remote_addr;
|
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
|
proxy_pass http://imes-basic-mom-report-dashboard:6071/dashboard/db/;
|
|
}
|
|
|
|
location = /api/db/dynamic-query {
|
|
proxy_redirect off;
|
|
proxy_set_header Host $host;
|
|
proxy_set_header X-real-ip $remote_addr;
|
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
|
proxy_pass http://imes-basic-dashboard-db-compat:18080/api/db/dynamic-query;
|
|
}
|
|
|
|
location /api/category/ {
|
|
proxy_redirect off;
|
|
proxy_set_header Host $host;
|
|
proxy_set_header X-real-ip $remote_addr;
|
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
|
proxy_pass http://imes-basic-mom-report-dashboard:6071/dashboard/category/;
|
|
}
|
|
|
|
location /api/ {
|
|
proxy_redirect off;
|
|
proxy_set_header Host $host;
|
|
proxy_set_header X-real-ip $remote_addr;
|
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
|
proxy_pass http://192.168.100.7:10002/;
|
|
}
|
|
|
|
location /oss/ {
|
|
proxy_redirect off;
|
|
proxy_set_header Host $host;
|
|
proxy_set_header X-real-ip $remote_addr;
|
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
|
proxy_pass http://192.168.100.7:10002/oss/;
|
|
}
|
|
}
|
|
---
|
|
apiVersion: apps/v1
|
|
kind: Deployment
|
|
metadata:
|
|
labels:
|
|
app: imes-basic-dashboard
|
|
name: imes-basic-dashboard
|
|
namespace: prd
|
|
spec:
|
|
progressDeadlineSeconds: 600
|
|
replicas: 1
|
|
revisionHistoryLimit: 10
|
|
selector:
|
|
matchLabels:
|
|
app: imes-basic-dashboard
|
|
strategy:
|
|
rollingUpdate:
|
|
maxSurge: 25%
|
|
maxUnavailable: 25%
|
|
type: RollingUpdate
|
|
template:
|
|
metadata:
|
|
labels:
|
|
app: imes-basic-dashboard
|
|
spec:
|
|
affinity:
|
|
nodeAffinity:
|
|
requiredDuringSchedulingIgnoredDuringExecution:
|
|
nodeSelectorTerms:
|
|
- matchExpressions:
|
|
- key: kubernetes.io/arch
|
|
operator: In
|
|
values:
|
|
- amd64
|
|
containers:
|
|
- args:
|
|
- start
|
|
- web
|
|
env:
|
|
- name: PORT
|
|
value: '80'
|
|
- name: HOST_IP
|
|
valueFrom:
|
|
fieldRef:
|
|
apiVersion: v1
|
|
fieldPath: status.hostIP
|
|
- name: POD_IP
|
|
valueFrom:
|
|
fieldRef:
|
|
apiVersion: v1
|
|
fieldPath: status.podIP
|
|
- name: POD_NAME
|
|
valueFrom:
|
|
fieldRef:
|
|
apiVersion: v1
|
|
fieldPath: metadata.name
|
|
- name: MEMORY_SIZE
|
|
value: large
|
|
image: 192.168.100.49:30002/prd/imes-basic-dashboard:20260129124349
|
|
imagePullPolicy: IfNotPresent
|
|
name: dashboard
|
|
ports:
|
|
- containerPort: 80
|
|
protocol: TCP
|
|
lifecycle:
|
|
postStart:
|
|
exec:
|
|
command:
|
|
- /bin/sh
|
|
- -c
|
|
- |
|
|
for i in $(seq 1 30); do
|
|
if [ -d /app/nginx/conf.d ]; then
|
|
cp /dashboard-nginx-conf/web.conf /app/nginx/conf.d/web.conf
|
|
python3 /dashboard-nginx-conf/patch_dynamic_sql.py || true
|
|
/app/nginx/sbin/nginx -s reload -c /app/nginx/conf/nginx.conf || true
|
|
exit 0
|
|
fi
|
|
sleep 1
|
|
done
|
|
exit 1
|
|
resources:
|
|
limits:
|
|
memory: 1Gi
|
|
requests:
|
|
memory: 256Mi
|
|
terminationMessagePath: /dev/termination-log
|
|
terminationMessagePolicy: File
|
|
volumeMounts:
|
|
- mountPath: /dashboard-nginx-conf
|
|
name: dashboard-nginx-conf
|
|
readOnly: true
|
|
dnsPolicy: ClusterFirst
|
|
restartPolicy: Always
|
|
schedulerName: default-scheduler
|
|
securityContext: {}
|
|
terminationGracePeriodSeconds: 10
|
|
volumes:
|
|
- configMap:
|
|
defaultMode: 420
|
|
items:
|
|
- key: web.conf
|
|
path: web.conf
|
|
- key: patch_dynamic_sql.py
|
|
path: patch_dynamic_sql.py
|
|
- key: db_compat.py
|
|
path: db_compat.py
|
|
name: imes-basic-dashboard-nginx-conf
|
|
name: dashboard-nginx-conf
|
|
---
|
|
apiVersion: apps/v1
|
|
kind: Deployment
|
|
metadata:
|
|
labels:
|
|
app: imes-basic-dashboard-db-compat
|
|
name: imes-basic-dashboard-db-compat
|
|
namespace: prd
|
|
spec:
|
|
replicas: 1
|
|
revisionHistoryLimit: 3
|
|
selector:
|
|
matchLabels:
|
|
app: imes-basic-dashboard-db-compat
|
|
template:
|
|
metadata:
|
|
labels:
|
|
app: imes-basic-dashboard-db-compat
|
|
spec:
|
|
containers:
|
|
- command:
|
|
- python3
|
|
- /dashboard-nginx-conf/db_compat.py
|
|
image: 192.168.100.49:30002/prd/imes-basic-dashboard:20260129124349
|
|
imagePullPolicy: IfNotPresent
|
|
name: db-compat
|
|
ports:
|
|
- containerPort: 18080
|
|
protocol: TCP
|
|
resources:
|
|
limits:
|
|
memory: 256Mi
|
|
requests:
|
|
memory: 64Mi
|
|
volumeMounts:
|
|
- mountPath: /dashboard-nginx-conf
|
|
name: dashboard-nginx-conf
|
|
readOnly: true
|
|
restartPolicy: Always
|
|
terminationGracePeriodSeconds: 10
|
|
volumes:
|
|
- configMap:
|
|
defaultMode: 420
|
|
items:
|
|
- key: db_compat.py
|
|
path: db_compat.py
|
|
name: imes-basic-dashboard-nginx-conf
|
|
name: dashboard-nginx-conf
|
|
---
|
|
apiVersion: v1
|
|
kind: Service
|
|
metadata:
|
|
labels:
|
|
app: imes-basic-dashboard-db-compat
|
|
name: imes-basic-dashboard-db-compat
|
|
namespace: prd
|
|
spec:
|
|
ports:
|
|
- name: http
|
|
port: 18080
|
|
protocol: TCP
|
|
targetPort: 18080
|
|
selector:
|
|
app: imes-basic-dashboard-db-compat
|
|
type: ClusterIP
|