diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..53f013b --- /dev/null +++ b/Dockerfile @@ -0,0 +1,19 @@ +# start by pulling the python image +FROM python:3.8-alpine + +# copy the requirements file into the image +COPY ./requirements.txt /app/requirements.txt + +# switch working directory +WORKDIR /app + +# install the dependencies and packages in the requirements file +RUN pip install -r requirements.txt + +# copy every content from the local file to the image +COPY . /app + +# configure the container to run in an executed manner +ENTRYPOINT [ "python" ] + +CMD ["webapp.py" ] diff --git a/README.md b/README.md index aafe673..9f94653 100644 --- a/README.md +++ b/README.md @@ -1 +1,50 @@ -# python3-webapps \ No newline at end of file +https://pythonbasics.org/flask-tutorial-templates/ + +Tested this on ubuntu: + +`apt-get update -y && apt-get upgrade -y` + +`apt-get install python3 -y && apt-get install python3-pip -y` + +`git clone -b 4-webapp-flask-docker https://github.com/DIGITALAPPLICATION/python3-webapps.git` +`cd python3-webapps` + +`pip install -r requirements.txt` + +`output: Successfully installed Jinja2-3.1.2 MarkupSafe-2.1.1 Werkzeug-2.2.2 click-8.1.3 flask-2.2.2 importlib-metadata-4.12.0 itsdangerous-2.1.2` + +`python3 webapp.py` + +``` + * Serving Flask app 'sam' + * Debug mode: off +WARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead. + * Running on all addresses (0.0.0.0) + * Running on http://127.0.0.1:5000 + * Running on http://10.0.0.4:5000 +Press CTRL+C to quit +49.37.130.119 - - [25/Sep/2022 08:00:45] "GET / HTTP/1.1" 200 - +49.37.130.119 - - [25/Sep/2022 08:00:46] "GET / HTTP/1.1" 200 - +49.37.130.119 - - [25/Sep/2022 08:00:47] "GET / HTTP/1.1" 200 - +49.37.130.119 - - [25/Sep/2022 08:00:47] "GET / HTTP/1.1" 200 - +49.37.130.119 - - [25/Sep/2022 08:00:48] "GET / HTTP/1.1" 200 - +``` + +open browser and check http://localhost:5000 or http://{publicIp}:5000 + +Ctrl+c = stop the lcoally runnign app at the same port 5000 + +once local testing completed, try docker build + +`apt-get install docker.io -y` + +`docker image build -t flask_docker .` + +`docker run -p 5000:5000 -d flask_docker` + +open browser and check http://localhost:81 or http://{publicIp}:5000 + + + + + diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..e8f5408 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,8 @@ +click==8.0.3 +colorama==0.4.4 +Flask==2.2.2 +itsdangerous==2.0.1 +Jinja2==3.0.3 +#MarkupSafe==2.0.1 +#Werkzeug==2.0.2 +gunicorn==20.1.0 diff --git a/templates/index.html b/templates/index.html new file mode 100644 index 0000000..df5a564 --- /dev/null +++ b/templates/index.html @@ -0,0 +1,12 @@ + + + {{ title }} + + + + + diff --git a/webapp.py b/webapp.py new file mode 100644 index 0000000..a0b4f02 --- /dev/null +++ b/webapp.py @@ -0,0 +1,15 @@ +from flask import Flask, render_template +import os + +app = Flask(__name__) + + +@app.route('/') +def home(): + users = [ 'Jenkins','GitHUB','Nexus' ] + return render_template('index.html', title='Welcome', members=users) + + +if __name__ == "__main__": + port = int(os.environ.get('PORT', 5000)) + app.run(debug=True, host='0.0.0.0', port=port)