Create an echo service docker image.
This commit is contained in:
parent
09c7cc8d03
commit
2a225de2f9
17
kubernetes/autoscale/service/Dockerfile
Normal file
17
kubernetes/autoscale/service/Dockerfile
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
FROM python:3.9
|
||||||
|
|
||||||
|
RUN useradd -m -g nogroup server
|
||||||
|
USER server
|
||||||
|
|
||||||
|
WORKDIR /home/server
|
||||||
|
ENV FLASK_APP=main.py
|
||||||
|
|
||||||
|
# Perform the install of requirements first to avoid re-installing on every code change
|
||||||
|
COPY requirements.txt /home/server/
|
||||||
|
RUN pip install -r /home/server/requirements.txt
|
||||||
|
|
||||||
|
COPY *.py /home/server/
|
||||||
|
|
||||||
|
# CMD ["python", "/home/server/main.py"]
|
||||||
|
|
||||||
|
CMD ["/home/server/.local/bin/gunicorn", "--config", "/home/server/gunicorn.conf.py", "main:app"]
|
21
kubernetes/autoscale/service/Makefile
Normal file
21
kubernetes/autoscale/service/Makefile
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
IMAGE_NAME:=echoservice
|
||||||
|
|
||||||
|
.PHONY: all
|
||||||
|
all: build push
|
||||||
|
|
||||||
|
.PHONY: build
|
||||||
|
build:
|
||||||
|
docker build -t $(IMAGE_NAME) .
|
||||||
|
|
||||||
|
.PHONY: push
|
||||||
|
push:
|
||||||
|
docker tag $(IMAGE_NAME) gcr.io/hip-wharf-319304/$(IMAGE_NAME)
|
||||||
|
docker push gcr.io/hip-wharf-319304/$(IMAGE_NAME)
|
||||||
|
|
||||||
|
.PHONY: clean
|
||||||
|
clean:
|
||||||
|
docker rmi $(IMAGE_NAME) gcr.io/hip-wharf-319304/$(IMAGE_NAME) $(IMAGE_NAME)
|
||||||
|
|
||||||
|
.PHONY: run
|
||||||
|
run:
|
||||||
|
docker run --rm -i -t -p "8080:8080" $(IMAGE_NAME)
|
10
kubernetes/autoscale/service/gunicorn.conf.py
Normal file
10
kubernetes/autoscale/service/gunicorn.conf.py
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
import multiprocessing
|
||||||
|
import os
|
||||||
|
|
||||||
|
env_port = int(os.environ.get("PORT", 8080))
|
||||||
|
|
||||||
|
bind = f"0.0.0.0:{env_port}"
|
||||||
|
workers = max(2, multiprocessing.cpu_count() * 2 + 1)
|
||||||
|
preload_app = True
|
||||||
|
max_requests = 100
|
||||||
|
max_requests_jitter = 50
|
28
kubernetes/autoscale/service/main.py
Normal file
28
kubernetes/autoscale/service/main.py
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
import json
|
||||||
|
import os
|
||||||
|
|
||||||
|
from flask import Flask, request
|
||||||
|
|
||||||
|
app = Flask(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
def get_request_params():
|
||||||
|
request_json = request.get_json(silent=True)
|
||||||
|
request_args = request.args
|
||||||
|
if request_json:
|
||||||
|
return request_json
|
||||||
|
elif request_args:
|
||||||
|
return request_args
|
||||||
|
else:
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
@app.route("/", methods=("GET", "POST"))
|
||||||
|
def index():
|
||||||
|
return json.dumps(
|
||||||
|
{"headers": {k: v for k, v in request.headers}, "params": get_request_params()}
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
app.run(host="0.0.0.0", port=int(os.environ.get("PORT", 8080)), debug=True)
|
2
kubernetes/autoscale/service/requirements.txt
Normal file
2
kubernetes/autoscale/service/requirements.txt
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
flask==1.1.2
|
||||||
|
gunicorn==20.1.0
|
Loading…
x
Reference in New Issue
Block a user