Last active
June 30, 2020 02:25
-
-
Save guinslym/621dac62c755a93bf6b89164a59dd2af to your computer and use it in GitHub Desktop.
Redoing a tutorial using Ansible https://www.digitalocean.com/community/tutorials/how-to-serve-flask-applications-with-gunicorn-and-nginx-on-ubuntu-20-04
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
## my box VMs ## | |
[DigitialOceanExample] | |
PPP.PPP.PPP.PPP (redacted by author) |
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
from flask import Flask | |
app = Flask(__name__) | |
@app.route("/") | |
def hello(): | |
return "<h1 style='color:blue'>Hello There!</h1>" | |
if __name__ == "__main__": | |
app.run(host='0.0.0.0') |
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
--- | |
- hosts: DigitialOceanExample | |
become: yes | |
tasks: | |
- name: Update apt-get repo and cache | |
apt: | |
update_cache: yes | |
force_apt_get: yes | |
cache_valid_time: 3600 | |
- name: Install a list of packages | |
apt: | |
pkg: | |
- python3-pip | |
- python3-dev | |
- build-essential | |
- libssl-dev | |
- libffi-dev | |
- python3-setuptools | |
- python3-venv | |
- name: ensure a directory exists or create it | |
file: | |
path: /myproject | |
state: directory | |
- name: Manually create the initial virtualenv | |
command: | |
cmd: python3 -m venv /myproject/myprojectenv | |
creates: "/myproject/myprojectenv" | |
- name: "install python packages with the local instance of pip" | |
shell: "/myproject/myprojectenv/bin/pip3 install wheel flask gunicorn" | |
- name: copy file to server | |
copy: | |
src: "{{ item }}" | |
dest: /myproject | |
loop: | |
- ./myproject.py | |
- name: Install ufw | |
apt: | |
name: ufw | |
update_cache: true | |
- name: "Allow port 5000" | |
shell: "ufw allow 5000" | |
- name: copy file to server | |
copy: | |
src: ./wsgi.py | |
dest: /myproject | |
- name: "starting gunicorn" | |
shell: "/myproject/myprojectenv/bin/gunicorn --preload --bind 0.0.0.0:5000 wsgi:app" | |
become: yes |
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
from myproject import app | |
if __name__ == "__main__": | |
app.run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment