djaploy


Namedjaploy JSON
Version 0.1.9 PyPI version JSON
download
home_pageNone
SummaryModular Django deployment system based on pyinfra
upload_time2025-10-18 08:12:30
maintainerNone
docs_urlNone
authorNone
requires_python>=3.9
licenseMIT License Copyright (c) 2024 djaploy contributors Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
keywords django deployment pyinfra automation infrastructure
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # djaploy

A modular Django deployment system based on pyinfra, designed to standardize and simplify infrastructure management across Django projects.

## Features

- **Modular Architecture**: Extensible plugin system for deployment components
- **Django Integration**: Seamless integration via Django management commands  
- **Python Compilation Support**: Compile Python from source for specific versions
- **Multiple Deployment Modes**: Support for `--local`, `--latest`, and `--release` deployments
- **Infrastructure as Code**: Define infrastructure using Python with pyinfra
- **Git-based Artifacts**: Automated artifact creation from git repository

## Installation

### From PyPI (once published)

```bash
pip install djaploy
```

Or with Poetry:
```bash
poetry add djaploy
```

### Development Installation

For testing djaploy locally without publishing to PyPI:

```bash
# Clone the repository
git clone https://github.com/techco-fi/djaploy.git
cd djaploy

# Install in editable mode
pip install -e .

# Or with Poetry  
poetry install
```

Then in your Django project:
```bash
# Using pip
pip install -e /path/to/djaploy

# Or add as a local dependency in pyproject.toml
[tool.poetry.dependencies]
djaploy = {path = "../djaploy", develop = true}
```

## Quick Start

### 1. Project Structure

```
your-django-project/
├── manage.py
├── your_app/
│   └── settings.py
└── djaploy/                    # Deployment configuration
    ├── config.py              # Main configuration
    ├── inventory/             # Host definitions
    │   ├── production.py
    │   └── staging.py  
    └── deploy_files/          # Environment-specific files
        ├── production/
        │   └── etc/systemd/system/app.service
        └── staging/
```

### 2. Django Settings

Add to your Django `settings.py`:

```python
# Required: Set project paths
BASE_DIR = '/path/to/django'  
PROJECT_DIR = BASE_DIR # folder containing manage.py
DJAPLOY_CONFIG_DIR = BASE_DIR + '/djaploy'
GIT_DIR = BASE_DIR.parent  # Git repository root
```

### 3. Create Configuration

Create `djaploy/config.py`:

```python
from djaploy.config import DjaployConfig
from pathlib import Path

config = DjaployConfig(
    # Required fields
    project_name="myapp",
    djaploy_dir=Path(__file__).parent,  # REQUIRED: This djaploy directory
    manage_py_path=Path("manage.py"),   # REQUIRED: Path to manage.py (relative to project root)
    
    # Python settings
    python_version="3.11",
    python_compile=False,  # Set True to compile from source
    
    # Server settings
    app_user="app",
    ssh_user="deploy",
    
    # Modules to use
    modules=[
        "djaploy.modules.core",      # Core setup (required)
        "djaploy.modules.nginx",     # Web server
        "djaploy.modules.systemd",   # Service management
    ],
    
    # Services to manage
    services=["myapp", "myapp-worker"],
)
```

### 4. Define Inventory

Create `djaploy/inventory/production.py`:

```python
from djaploy.config import HostConfig

hosts = [
    HostConfig(
        name="web-1",
        ssh_host="192.168.1.100",
        ssh_user="deploy",
        app_user="app",
        env="production",
        services=["myapp", "myapp-worker"],
    ),
]
```

### 5. Deploy Files

Place service files in `djaploy/deploy_files/production/`:

```ini
# etc/systemd/system/myapp.service
[Unit]
Description=My Django App
After=network.target

[Service]
Type=simple
User=app
WorkingDirectory=/home/app/apps/myapp
ExecStart=/home/app/.local/bin/poetry run gunicorn config.wsgi
Restart=on-failure

[Install]
WantedBy=multi-user.target
```

## Usage

### Configure Server

```bash
python manage.py configureserver --env production
```

This will:
- Create application user
- Install/compile Python  
- Install Poetry
- Set up directory structure

### Deploy Application

```bash
# Deploy local changes (for development)
python manage.py deploy --env production --local

# Deploy latest git commit
python manage.py deploy --env production --latest

# Deploy specific release
python manage.py deploy --env production --release v1.0.0
```

Deployment process:
1. Creates tar.gz artifact from git
2. Uploads to servers
3. Extracts application code
4. Installs dependencies
5. Runs migrations
6. Collects static files  
7. Restarts services

## Module System

Djaploy uses a modular architecture where each component (nginx, systemd, backups, etc.) is a separate module that can be enabled or disabled per project.

### Available Modules

- `nginx`: NGINX web server configuration
- `systemd`: Systemd service management
- `litestream`: Litestream database backups
- `rclone`: Rclone-based backup system
- `tailscale`: Tailscale networking
- `ssl`: SSL certificate management
- `python_build`: Python compilation from source

### Creating Custom Modules

Projects can create their own modules by extending the base module class:

```python
from djaploy.modules.base import BaseModule

class MyCustomModule(BaseModule):
    def configure_server(self, host):
        # Server configuration logic
        pass
    
    def deploy(self, host, artifact_path):
        # Deployment logic
        pass
```

## Project Customization

### prepare.py

Projects can include a `prepare.py` file for local build steps before deployment:

```python
# prepare.py
from djaploy.prepare import run_command

def prepare():
    run_command("npm run build")
    run_command("python manage.py collectstatic --noinput")
```

### Custom Deploy Files

Projects can include environment-specific configuration files in a `deploy_files/` directory that will be copied to the server during deployment.

## License

MIT

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "djaploy",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.9",
    "maintainer_email": null,
    "keywords": "django, deployment, pyinfra, automation, infrastructure",
    "author": null,
    "author_email": "Johanna Mae Dimayuga <johanna@techco.fi>",
    "download_url": "https://files.pythonhosted.org/packages/1f/b1/27350a89e3ff5c79d05ef686d48e5e7e700c1da4380b9ad6a85a9ed02564/djaploy-0.1.9.tar.gz",
    "platform": null,
    "description": "# djaploy\n\nA modular Django deployment system based on pyinfra, designed to standardize and simplify infrastructure management across Django projects.\n\n## Features\n\n- **Modular Architecture**: Extensible plugin system for deployment components\n- **Django Integration**: Seamless integration via Django management commands  \n- **Python Compilation Support**: Compile Python from source for specific versions\n- **Multiple Deployment Modes**: Support for `--local`, `--latest`, and `--release` deployments\n- **Infrastructure as Code**: Define infrastructure using Python with pyinfra\n- **Git-based Artifacts**: Automated artifact creation from git repository\n\n## Installation\n\n### From PyPI (once published)\n\n```bash\npip install djaploy\n```\n\nOr with Poetry:\n```bash\npoetry add djaploy\n```\n\n### Development Installation\n\nFor testing djaploy locally without publishing to PyPI:\n\n```bash\n# Clone the repository\ngit clone https://github.com/techco-fi/djaploy.git\ncd djaploy\n\n# Install in editable mode\npip install -e .\n\n# Or with Poetry  \npoetry install\n```\n\nThen in your Django project:\n```bash\n# Using pip\npip install -e /path/to/djaploy\n\n# Or add as a local dependency in pyproject.toml\n[tool.poetry.dependencies]\ndjaploy = {path = \"../djaploy\", develop = true}\n```\n\n## Quick Start\n\n### 1. Project Structure\n\n```\nyour-django-project/\n\u251c\u2500\u2500 manage.py\n\u251c\u2500\u2500 your_app/\n\u2502   \u2514\u2500\u2500 settings.py\n\u2514\u2500\u2500 djaploy/                    # Deployment configuration\n    \u251c\u2500\u2500 config.py              # Main configuration\n    \u251c\u2500\u2500 inventory/             # Host definitions\n    \u2502   \u251c\u2500\u2500 production.py\n    \u2502   \u2514\u2500\u2500 staging.py  \n    \u2514\u2500\u2500 deploy_files/          # Environment-specific files\n        \u251c\u2500\u2500 production/\n        \u2502   \u2514\u2500\u2500 etc/systemd/system/app.service\n        \u2514\u2500\u2500 staging/\n```\n\n### 2. Django Settings\n\nAdd to your Django `settings.py`:\n\n```python\n# Required: Set project paths\nBASE_DIR = '/path/to/django'  \nPROJECT_DIR = BASE_DIR # folder containing manage.py\nDJAPLOY_CONFIG_DIR = BASE_DIR + '/djaploy'\nGIT_DIR = BASE_DIR.parent  # Git repository root\n```\n\n### 3. Create Configuration\n\nCreate `djaploy/config.py`:\n\n```python\nfrom djaploy.config import DjaployConfig\nfrom pathlib import Path\n\nconfig = DjaployConfig(\n    # Required fields\n    project_name=\"myapp\",\n    djaploy_dir=Path(__file__).parent,  # REQUIRED: This djaploy directory\n    manage_py_path=Path(\"manage.py\"),   # REQUIRED: Path to manage.py (relative to project root)\n    \n    # Python settings\n    python_version=\"3.11\",\n    python_compile=False,  # Set True to compile from source\n    \n    # Server settings\n    app_user=\"app\",\n    ssh_user=\"deploy\",\n    \n    # Modules to use\n    modules=[\n        \"djaploy.modules.core\",      # Core setup (required)\n        \"djaploy.modules.nginx\",     # Web server\n        \"djaploy.modules.systemd\",   # Service management\n    ],\n    \n    # Services to manage\n    services=[\"myapp\", \"myapp-worker\"],\n)\n```\n\n### 4. Define Inventory\n\nCreate `djaploy/inventory/production.py`:\n\n```python\nfrom djaploy.config import HostConfig\n\nhosts = [\n    HostConfig(\n        name=\"web-1\",\n        ssh_host=\"192.168.1.100\",\n        ssh_user=\"deploy\",\n        app_user=\"app\",\n        env=\"production\",\n        services=[\"myapp\", \"myapp-worker\"],\n    ),\n]\n```\n\n### 5. Deploy Files\n\nPlace service files in `djaploy/deploy_files/production/`:\n\n```ini\n# etc/systemd/system/myapp.service\n[Unit]\nDescription=My Django App\nAfter=network.target\n\n[Service]\nType=simple\nUser=app\nWorkingDirectory=/home/app/apps/myapp\nExecStart=/home/app/.local/bin/poetry run gunicorn config.wsgi\nRestart=on-failure\n\n[Install]\nWantedBy=multi-user.target\n```\n\n## Usage\n\n### Configure Server\n\n```bash\npython manage.py configureserver --env production\n```\n\nThis will:\n- Create application user\n- Install/compile Python  \n- Install Poetry\n- Set up directory structure\n\n### Deploy Application\n\n```bash\n# Deploy local changes (for development)\npython manage.py deploy --env production --local\n\n# Deploy latest git commit\npython manage.py deploy --env production --latest\n\n# Deploy specific release\npython manage.py deploy --env production --release v1.0.0\n```\n\nDeployment process:\n1. Creates tar.gz artifact from git\n2. Uploads to servers\n3. Extracts application code\n4. Installs dependencies\n5. Runs migrations\n6. Collects static files  \n7. Restarts services\n\n## Module System\n\nDjaploy uses a modular architecture where each component (nginx, systemd, backups, etc.) is a separate module that can be enabled or disabled per project.\n\n### Available Modules\n\n- `nginx`: NGINX web server configuration\n- `systemd`: Systemd service management\n- `litestream`: Litestream database backups\n- `rclone`: Rclone-based backup system\n- `tailscale`: Tailscale networking\n- `ssl`: SSL certificate management\n- `python_build`: Python compilation from source\n\n### Creating Custom Modules\n\nProjects can create their own modules by extending the base module class:\n\n```python\nfrom djaploy.modules.base import BaseModule\n\nclass MyCustomModule(BaseModule):\n    def configure_server(self, host):\n        # Server configuration logic\n        pass\n    \n    def deploy(self, host, artifact_path):\n        # Deployment logic\n        pass\n```\n\n## Project Customization\n\n### prepare.py\n\nProjects can include a `prepare.py` file for local build steps before deployment:\n\n```python\n# prepare.py\nfrom djaploy.prepare import run_command\n\ndef prepare():\n    run_command(\"npm run build\")\n    run_command(\"python manage.py collectstatic --noinput\")\n```\n\n### Custom Deploy Files\n\nProjects can include environment-specific configuration files in a `deploy_files/` directory that will be copied to the server during deployment.\n\n## License\n\nMIT\n",
    "bugtrack_url": null,
    "license": "MIT License\n        \n        Copyright (c) 2024 djaploy contributors\n        \n        Permission is hereby granted, free of charge, to any person obtaining a copy\n        of this software and associated documentation files (the \"Software\"), to deal\n        in the Software without restriction, including without limitation the rights\n        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n        copies of the Software, and to permit persons to whom the Software is\n        furnished to do so, subject to the following conditions:\n        \n        The above copyright notice and this permission notice shall be included in all\n        copies or substantial portions of the Software.\n        \n        THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n        SOFTWARE.",
    "summary": "Modular Django deployment system based on pyinfra",
    "version": "0.1.9",
    "project_urls": {
        "Documentation": "https://github.com/techco-fi/djaploy#readme",
        "Homepage": "https://github.com/techco-fi/djaploy",
        "Issues": "https://github.com/techco-fi/djaploy/issues",
        "Repository": "https://github.com/techco-fi/djaploy"
    },
    "split_keywords": [
        "django",
        " deployment",
        " pyinfra",
        " automation",
        " infrastructure"
    ],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "321a3250b3d37462ff328185cbdbe9a839044af19c8f67a1637907b30bed0fbc",
                "md5": "cbcfd787f6edbeb79dba491a72fe2333",
                "sha256": "965d62243fb055bdc02d1ec9481d7a780a2474476c864d6089b8db558ea4c73e"
            },
            "downloads": -1,
            "filename": "djaploy-0.1.9-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "cbcfd787f6edbeb79dba491a72fe2333",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.9",
            "size": 44856,
            "upload_time": "2025-10-18T08:12:28",
            "upload_time_iso_8601": "2025-10-18T08:12:28.015708Z",
            "url": "https://files.pythonhosted.org/packages/32/1a/3250b3d37462ff328185cbdbe9a839044af19c8f67a1637907b30bed0fbc/djaploy-0.1.9-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "1fb127350a89e3ff5c79d05ef686d48e5e7e700c1da4380b9ad6a85a9ed02564",
                "md5": "f7156de3920de760a3d162565d02a94c",
                "sha256": "ad551f78f1820a04f2274d76e2828b858b5c02562c5359a4f3dc8450b079d152"
            },
            "downloads": -1,
            "filename": "djaploy-0.1.9.tar.gz",
            "has_sig": false,
            "md5_digest": "f7156de3920de760a3d162565d02a94c",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.9",
            "size": 37503,
            "upload_time": "2025-10-18T08:12:30",
            "upload_time_iso_8601": "2025-10-18T08:12:30.775873Z",
            "url": "https://files.pythonhosted.org/packages/1f/b1/27350a89e3ff5c79d05ef686d48e5e7e700c1da4380b9ad6a85a9ed02564/djaploy-0.1.9.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-10-18 08:12:30",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "techco-fi",
    "github_project": "djaploy#readme",
    "github_not_found": true,
    "lcname": "djaploy"
}
        
Elapsed time: 1.78962s