Skip to content

Commit

Permalink
add flask
Browse files Browse the repository at this point in the history
  • Loading branch information
graykode committed Apr 12, 2019
1 parent 644716c commit b377f73
Show file tree
Hide file tree
Showing 6 changed files with 87 additions and 0 deletions.
11 changes: 11 additions & 0 deletions flask/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
FROM ubuntu:16.04
LABEL maintainer="[email protected]"

RUN apt-get update -y && \
apt-get install -y python3-pip python3 && \
pip3 install flask Pillow && mkdir /home/uploads && mkdir /home/templates

ADD server.py /home/
ADD templates /home/templates
WORKDIR /home/uploads
ENTRYPOINT ["python3", "/home/server.py"]
33 changes: 33 additions & 0 deletions flask/deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: flask-api-deployment
spec:
replicas: 1
template:
metadata:
labels:
app: flask-api
spec:
containers:
- name: flask-api
image: nlkey2022/flask_test
imagePullPolicy: Always
volumeMounts:
- mountPath: "/home/uploads"
name: pv
resources:
limits:
cpu: 150m
memory: 200Mi
requests:
cpu: 150m
memory: 100Mi
ports:
- containerPort: 5000
nodeSelector:
application: "flask"
volumes:
- name: pv
persistentVolumeClaim:
claimName: test-claim
19 changes: 19 additions & 0 deletions flask/server.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/usr/bin/env python3
from flask import Flask, render_template, request
from werkzeug import secure_filename

app = Flask(__name__)

@app.route('/')
def index():
return render_template('index.html')

@app.route('/upload', methods=['POST'])
def upload():
if request.method == 'POST':
f = request.files.get('file')
fname = secure_filename(f.filename)
f.save(fname)

if __name__ == '__main__':
app.run(host='0.0.0.0', debug=False)
11 changes: 11 additions & 0 deletions flask/service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
apiVersion: v1
kind: Service
metadata:
name: flask-api-service
spec:
type: LoadBalancer
ports:
- port: 80
targetPort: 5000
selector:
app: flask-api
13 changes: 13 additions & 0 deletions flask/templates/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>upload Test</title>
</head>
<body>
<form action = "/upload" method = "POST" enctype = "multipart/form-data">
<input type = "file" name = "file" />
<input type = "submit"/>
</form>
</body>
</html>
Empty file added flask/uploads/.keep
Empty file.

0 comments on commit b377f73

Please sign in to comment.