From e904bb6c2898b7f58c5194a95e1c558c9124c7d1 Mon Sep 17 00:00:00 2001 From: missytake Date: Wed, 15 May 2024 17:00:08 +0200 Subject: [PATCH] python package basics --- .gitignore | 143 +++++++++++++++++++++++++++++++++++++++++++++++++ README.md | 43 +++++++++++++++ pyproject.toml | 5 +- 3 files changed, 190 insertions(+), 1 deletion(-) create mode 100644 .gitignore create mode 100644 README.md diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..77c8701 --- /dev/null +++ b/.gitignore @@ -0,0 +1,143 @@ +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class +_build/ +*.swp +playground/ + +# C extensions +*.so + +.idea/.gitignore +.idea/inspectionProfiles/profiles_settings.xml +.idea/mailadm.iml +.idea/modules.xml +.idea/vcs.xml + + +# Distribution / packaging +.Python +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +pip-wheel-metadata/ +share/python-wheels/ +*.egg-info/ +.installed.cfg +*.egg +MANIFEST + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.nox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*.cover +*.py,cover +.hypothesis/ +.pytest_cache/ + +# Translations +*.mo +*.pot + +# Django stuff: +*.log +local_settings.py +db.sqlite3 +db.sqlite3-journal + +# Flask stuff: +instance/ +.webassets-cache + +# Scrapy stuff: +.scrapy + +# Sphinx documentation +docs/_build/ + +# PyBuilder +target/ + +# Jupyter Notebook +.ipynb_checkpoints + +# IPython +profile_default/ +ipython_config.py + +# pyenv +.python-version + +# pipenv +# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. +# However, in case of collaboration, if having platform-specific dependencies or dependencies +# having no cross-platform support, pipenv may install dependencies that don't work, or not +# install all needed dependencies. +#Pipfile.lock + +# PEP 582; used by e.g. github.com/David-OConnor/pyflow +__pypackages__/ + +# Celery stuff +celerybeat-schedule +celerybeat.pid + +# SageMath parsed files +*.sage.py + +# Environments +.env +.venv +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ +docker-data/ + +# Spyder project settings +.spyderproject +.spyproject + +# Rope project settings +.ropeproject + +# mkdocs documentation +/site + +# mypy +.mypy_cache/ +.dmypy.json +dmypy.json + +# Pyre type checker +.pyre/ + +.mailadm.lock +mailadm.db diff --git a/README.md b/README.md new file mode 100644 index 0000000..63c7f1d --- /dev/null +++ b/README.md @@ -0,0 +1,43 @@ +# pyinfra-nginx + +This is a pyinfra module to manage an nginx web server. + +## Install + +Just install this python package with +`pip install git+https://git.0x90.space/0x90/pyinfra-nginx/` +(preferably to your virtual environment). + +## Usage + +You can use this module +from your pyinfra deploy.py file +like this: + +``` +from pyinfra_nginx import deploy_nginx, nginx_deployer + + +deploy_nginx() # install nginx via apt if it doesn't exist + +with nginx_deployer() as n: + n.add_nginx_domain(domain="example.org", webroot="/var/www/html/") +``` + +This will install nginx via apt +(only Debian-like systems are supported right now) +and deploy an example nginx config +which exposes static files +under the `/var/www/html` directory. + +### Options + +`add_nginx_domain()` supports 3 template configs for configuring your site: + +- `webroot` for serving a static page, +- `proxy_port` for passing traffic to a separate application listening on some port, +- and `redirect` for redirecting to a different website with a 301 HTTP status code. +- You can use `config_path` if your site is so special it needs a custom config. + +These 4 options are mutually exclusive. + diff --git a/pyproject.toml b/pyproject.toml index 6fdaeab..f6342f7 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -3,5 +3,8 @@ requires = ["setuptools>=45"] build-backend = "setuptools.build_meta" [project] -name = "pyinfra-mailcow" +name = "pyinfra-nginx" version = "0.1" +dependencies = [ + "pyinfra-acmetool @ git+https://github.com/deltachat/pyinfra-acmetool/", +]