Last active
March 7, 2021 01:17
-
-
Save mathieu-benoit/0b5b6be805fd1549352da5e89150e916 to your computer and use it in GitHub Desktop.
"Hello, World!" in python
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import datetime | |
import time | |
from flask import Flask | |
app = Flask(__name__) | |
@app.route('/') | |
def hello_world(): | |
target = os.environ.get('TARGET', 'World') | |
timestamp = str(datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')) | |
return timestamp + ' Hello, {}!\n'.format(target) | |
if __name__ == "__main__": | |
app.run(debug=True,host='0.0.0.0',port=int(os.environ.get('PORT', 8080))) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Use the official lightweight Python image. | |
# https://hub.docker.com/_/python | |
FROM python:3.7-slim | |
# Allow statements and log messages to immediately appear in the Knative logs | |
ENV PYTHONUNBUFFERED True | |
# Copy local code to the container image. | |
WORKDIR /app | |
COPY . ./ | |
# Install production dependencies. | |
RUN pip install Flask gunicorn | |
# Run the web service on container startup. Here we use the gunicorn | |
# webserver, with one worker process and 8 threads. | |
# For environments with multiple CPU cores, increase the number of workers | |
# to be equal to the cores available. | |
CMD exec gunicorn --bind :8080 --workers 1 --threads 8 --timeout 0 app:app |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment