Add research/
This commit is contained in:
parent
2cfb12cc71
commit
8923b8d4a5
15
research/Dockerfile
Normal file
15
research/Dockerfile
Normal file
@ -0,0 +1,15 @@
|
||||
FROM alpine:3.18
|
||||
|
||||
RUN apk add --no-cache \
|
||||
bash \
|
||||
curl \
|
||||
git \
|
||||
vim \
|
||||
python3 \
|
||||
py3-flask
|
||||
|
||||
ADD server.py /themblem/research/server.py
|
||||
|
||||
EXPOSE 26966
|
||||
|
||||
CMD ["python3", "/themblem/research/server.py"]
|
||||
10
research/deploy.sh
Executable file
10
research/deploy.sh
Executable file
@ -0,0 +1,10 @@
|
||||
#!/bin/bash
|
||||
set -e
|
||||
|
||||
DOCKER_IMAGE=registry.gitlab.com/euphon/themblem:research-$(git rev-parse --short HEAD)
|
||||
docker build --network=host -t $DOCKER_IMAGE .
|
||||
|
||||
docker push $DOCKER_IMAGE
|
||||
|
||||
kubectl -n emblem set image deployment/research research=$DOCKER_IMAGE
|
||||
kubectl -n emblem rollout status deployment/research
|
||||
91
research/k8s.yaml
Normal file
91
research/k8s.yaml
Normal file
@ -0,0 +1,91 @@
|
||||
apiVersion: v1
|
||||
items:
|
||||
- apiVersion: v1
|
||||
kind: Service
|
||||
metadata:
|
||||
name: research
|
||||
namespace: emblem
|
||||
spec:
|
||||
ports:
|
||||
- nodePort: 32039
|
||||
port: 26966
|
||||
protocol: TCP
|
||||
targetPort: 26966
|
||||
selector:
|
||||
app: research
|
||||
type: NodePort
|
||||
- apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: research
|
||||
namespace: emblem
|
||||
spec:
|
||||
replicas: 1
|
||||
selector:
|
||||
matchLabels:
|
||||
app: research
|
||||
strategy:
|
||||
rollingUpdate:
|
||||
maxSurge: 25%
|
||||
maxUnavailable: 25%
|
||||
type: RollingUpdate
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
app: research
|
||||
spec:
|
||||
containers:
|
||||
- env:
|
||||
- name: DATA_DIR
|
||||
value: /themblem/research/data
|
||||
image: registry.gitlab.com/euphon/themblem:research-90f2f8b
|
||||
imagePullPolicy: Always
|
||||
name: research
|
||||
ports:
|
||||
- containerPort: 26966
|
||||
name: http
|
||||
protocol: TCP
|
||||
resources: {}
|
||||
terminationMessagePath: /dev/termination-log
|
||||
terminationMessagePolicy: File
|
||||
volumeMounts:
|
||||
- mountPath: /themblem/research/data
|
||||
name: data
|
||||
dnsPolicy: ClusterFirst
|
||||
imagePullSecrets:
|
||||
- name: regcred
|
||||
restartPolicy: Always
|
||||
schedulerName: default-scheduler
|
||||
securityContext: {}
|
||||
terminationGracePeriodSeconds: 30
|
||||
volumes:
|
||||
- hostPath:
|
||||
path: /data/emblem-research
|
||||
type: Directory
|
||||
name: data
|
||||
- apiVersion: networking.k8s.io/v1
|
||||
kind: Ingress
|
||||
metadata:
|
||||
annotations:
|
||||
traefik.ingress.kubernetes.io/router.tls.certresolver: le
|
||||
name: research
|
||||
namespace: emblem
|
||||
spec:
|
||||
ingressClassName: traefik
|
||||
rules:
|
||||
- host: research.themblem.com
|
||||
http:
|
||||
paths:
|
||||
- backend:
|
||||
service:
|
||||
name: research
|
||||
port:
|
||||
number: 26966
|
||||
path: /
|
||||
pathType: Prefix
|
||||
tls:
|
||||
- hosts:
|
||||
- research.themblem.com
|
||||
kind: List
|
||||
metadata:
|
||||
resourceVersion: ""
|
||||
31
research/server.py
Executable file
31
research/server.py
Executable file
@ -0,0 +1,31 @@
|
||||
#!/usr/bin/env python3
|
||||
from flask import Flask, request, jsonify
|
||||
from datetime import datetime
|
||||
import os
|
||||
import json
|
||||
import uuid
|
||||
|
||||
app = Flask(__name__)
|
||||
|
||||
DATA_DIR = os.environ.get('DATA_DIR', '/var/tmp/themblem-research')
|
||||
os.makedirs(DATA_DIR, exist_ok=True)
|
||||
|
||||
@app.route('/')
|
||||
def index():
|
||||
return "Emblem research API\n"
|
||||
|
||||
@app.route('/event/<category>', methods=['POST'])
|
||||
def event(category):
|
||||
d = os.path.join(DATA_DIR, category, datetime.now().strftime("%Y-%m-%d"))
|
||||
os.makedirs(d, exist_ok=True)
|
||||
fname = datetime.now().strftime("%H%M%S") + '-' + str(uuid.uuid4())
|
||||
with open(os.path.join(d, fname), 'wb') as f:
|
||||
data = request.get_data()
|
||||
f.write(data)
|
||||
return {
|
||||
"ok": True,
|
||||
"message": "Event saved",
|
||||
}
|
||||
|
||||
if __name__ == '__main__':
|
||||
app.run(host='0.0.0.0', port=26966, debug=True)
|
||||
Loading…
x
Reference in New Issue
Block a user