django-deploy-toolkit 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- django_deploy_toolkit-0.1.0/LICENSE +21 -0
- django_deploy_toolkit-0.1.0/PKG-INFO +306 -0
- django_deploy_toolkit-0.1.0/README.md +267 -0
- django_deploy_toolkit-0.1.0/django_deploy_toolkit/__init__.py +4 -0
- django_deploy_toolkit-0.1.0/django_deploy_toolkit/cli.py +409 -0
- django_deploy_toolkit-0.1.0/django_deploy_toolkit/detector.py +575 -0
- django_deploy_toolkit-0.1.0/django_deploy_toolkit/generators/__init__.py +1 -0
- django_deploy_toolkit-0.1.0/django_deploy_toolkit/generators/nginx.py +89 -0
- django_deploy_toolkit-0.1.0/django_deploy_toolkit/generators/service.py +72 -0
- django_deploy_toolkit-0.1.0/django_deploy_toolkit/generators/socket.py +54 -0
- django_deploy_toolkit-0.1.0/django_deploy_toolkit/installer.py +344 -0
- django_deploy_toolkit-0.1.0/django_deploy_toolkit/reporter.py +215 -0
- django_deploy_toolkit-0.1.0/django_deploy_toolkit/rollback.py +267 -0
- django_deploy_toolkit-0.1.0/django_deploy_toolkit/utils.py +180 -0
- django_deploy_toolkit-0.1.0/django_deploy_toolkit/validators.py +349 -0
- django_deploy_toolkit-0.1.0/django_deploy_toolkit.egg-info/PKG-INFO +306 -0
- django_deploy_toolkit-0.1.0/django_deploy_toolkit.egg-info/SOURCES.txt +30 -0
- django_deploy_toolkit-0.1.0/django_deploy_toolkit.egg-info/dependency_links.txt +1 -0
- django_deploy_toolkit-0.1.0/django_deploy_toolkit.egg-info/entry_points.txt +2 -0
- django_deploy_toolkit-0.1.0/django_deploy_toolkit.egg-info/requires.txt +9 -0
- django_deploy_toolkit-0.1.0/django_deploy_toolkit.egg-info/top_level.txt +1 -0
- django_deploy_toolkit-0.1.0/pyproject.toml +80 -0
- django_deploy_toolkit-0.1.0/setup.cfg +10 -0
- django_deploy_toolkit-0.1.0/tests/test_cli.py +204 -0
- django_deploy_toolkit-0.1.0/tests/test_detector.py +513 -0
- django_deploy_toolkit-0.1.0/tests/test_generators.py +192 -0
- django_deploy_toolkit-0.1.0/tests/test_installer.py +198 -0
- django_deploy_toolkit-0.1.0/tests/test_reporter.py +127 -0
- django_deploy_toolkit-0.1.0/tests/test_rollback.py +223 -0
- django_deploy_toolkit-0.1.0/tests/test_utils.py +216 -0
- django_deploy_toolkit-0.1.0/tests/test_validators.py +241 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Antu Saha and django-deploy-toolkit contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,306 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: django-deploy-toolkit
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Auto-generate and install Gunicorn & Nginx configuration for Django projects on Ubuntu/Debian.
|
|
5
|
+
Author: Antu Saha
|
|
6
|
+
Maintainer: Antu Saha
|
|
7
|
+
License-Expression: MIT
|
|
8
|
+
Project-URL: Homepage, https://github.com/antusaha970/django-deploy-toolkit
|
|
9
|
+
Project-URL: Issues, https://github.com/antusaha970/django-deploy-toolkit/issues
|
|
10
|
+
Project-URL: Documentation, https://github.com/antusaha970/django-deploy-toolkit#readme
|
|
11
|
+
Project-URL: Changelog, https://github.com/antusaha970/django-deploy-toolkit/blob/main/CHANGELOG.md
|
|
12
|
+
Keywords: django,deployment,gunicorn,nginx,systemd,devops,automation
|
|
13
|
+
Classifier: Development Status :: 4 - Beta
|
|
14
|
+
Classifier: Environment :: Console
|
|
15
|
+
Classifier: Framework :: Django
|
|
16
|
+
Classifier: Intended Audience :: Developers
|
|
17
|
+
Classifier: Intended Audience :: System Administrators
|
|
18
|
+
Classifier: Operating System :: POSIX :: Linux
|
|
19
|
+
Classifier: Programming Language :: Python :: 3
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
22
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
23
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
24
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
25
|
+
Classifier: Topic :: System :: Installation/Setup
|
|
26
|
+
Classifier: Topic :: System :: Systems Administration
|
|
27
|
+
Requires-Python: >=3.8
|
|
28
|
+
Description-Content-Type: text/markdown
|
|
29
|
+
License-File: LICENSE
|
|
30
|
+
Requires-Dist: click>=8.0
|
|
31
|
+
Requires-Dist: rich>=12.0
|
|
32
|
+
Requires-Dist: jinja2>=3.0
|
|
33
|
+
Requires-Dist: psutil>=5.0
|
|
34
|
+
Provides-Extra: dev
|
|
35
|
+
Requires-Dist: pytest>=7.0; extra == "dev"
|
|
36
|
+
Requires-Dist: pytest-mock>=3.0; extra == "dev"
|
|
37
|
+
Requires-Dist: coverage>=7.0; extra == "dev"
|
|
38
|
+
Dynamic: license-file
|
|
39
|
+
|
|
40
|
+
# django-deploy-toolkit
|
|
41
|
+
|
|
42
|
+
**Auto-generate and install Gunicorn & Nginx configuration for Django projects on Ubuntu/Debian.**
|
|
43
|
+
|
|
44
|
+
`django-deploy-toolkit` detects your Django project's configuration, generates production-ready systemd service/socket files and Nginx server blocks, and installs them — all with a single command. It handles edge cases gracefully, supports dry-run mode, and includes full rollback on failure.
|
|
45
|
+
|
|
46
|
+
---
|
|
47
|
+
|
|
48
|
+
## Created By
|
|
49
|
+
|
|
50
|
+
**Antu Saha** — creator and lead maintainer of this package.
|
|
51
|
+
|
|
52
|
+
We also appreciate all the open-source contributors who help improve `django-deploy-toolkit`. Contributions of any kind are welcome — bug reports, feature requests, documentation improvements, and code contributions. See the [Contributing](#contributing) section below to get started.
|
|
53
|
+
|
|
54
|
+
---
|
|
55
|
+
|
|
56
|
+
## Requirements
|
|
57
|
+
|
|
58
|
+
- **OS:** Ubuntu / Debian Linux
|
|
59
|
+
- **Python:** 3.8 or higher
|
|
60
|
+
- **Django project** with a `manage.py` file
|
|
61
|
+
- **Gunicorn** installed in the project's virtual environment
|
|
62
|
+
- **Nginx** installed on the server (`sudo apt install nginx`)
|
|
63
|
+
- **systemd** available (standard on Ubuntu/Debian)
|
|
64
|
+
|
|
65
|
+
---
|
|
66
|
+
|
|
67
|
+
## Installation
|
|
68
|
+
|
|
69
|
+
```bash
|
|
70
|
+
pip install django-deploy-toolkit
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
Or install from source:
|
|
74
|
+
|
|
75
|
+
```bash
|
|
76
|
+
git clone https://github.com/antusaha970/django-deploy-toolkit.git
|
|
77
|
+
cd django-deploy-toolkit
|
|
78
|
+
pip install -e .
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
---
|
|
82
|
+
|
|
83
|
+
## Quick Start
|
|
84
|
+
|
|
85
|
+
```bash
|
|
86
|
+
# Navigate to your Django project root (where manage.py lives)
|
|
87
|
+
cd /path/to/your/django/project
|
|
88
|
+
|
|
89
|
+
# Activate your project's virtual environment
|
|
90
|
+
source venv/bin/activate
|
|
91
|
+
|
|
92
|
+
# Run the setup
|
|
93
|
+
django-deploy setup
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
That's it. The tool will:
|
|
97
|
+
1. Auto-detect your project configuration
|
|
98
|
+
2. Show you what it found and ask for confirmation
|
|
99
|
+
3. Generate and install the config files
|
|
100
|
+
4. Enable and start the services
|
|
101
|
+
5. Test and reload Nginx
|
|
102
|
+
|
|
103
|
+
---
|
|
104
|
+
|
|
105
|
+
## What Gets Auto-Detected
|
|
106
|
+
|
|
107
|
+
| Setting | Detection Method |
|
|
108
|
+
|---------|-----------------|
|
|
109
|
+
| **Project Name** | Basename of the current directory (sanitized) |
|
|
110
|
+
| **Project Path** | Current working directory (searches for `manage.py`) |
|
|
111
|
+
| **WSGI Module** | Parsed from `manage.py` → `DJANGO_SETTINGS_MODULE`, or scans for `wsgi.py` |
|
|
112
|
+
| **User** | `$USER` env var → `$LOGNAME` → `pwd.getpwuid()` |
|
|
113
|
+
| **Group** | Primary group of the detected user via `grp.getgrgid()` |
|
|
114
|
+
| **Python Path** | `sys.executable` (virtualenv-aware) |
|
|
115
|
+
| **Server IP** | `/etc/hosts` → `socket.gethostbyname()` → UDP socket trick → `_` (catch-all) |
|
|
116
|
+
| **Workers** | `(2 × CPU cores) + 1`, capped at 9 (via `psutil`) |
|
|
117
|
+
| **Static Root** | Parsed from `python manage.py diffsettings` output |
|
|
118
|
+
| **Media Root** | Same as Static Root |
|
|
119
|
+
|
|
120
|
+
---
|
|
121
|
+
|
|
122
|
+
## Dry-Run Mode
|
|
123
|
+
|
|
124
|
+
Preview everything that would happen without making any changes:
|
|
125
|
+
|
|
126
|
+
```bash
|
|
127
|
+
django-deploy setup --dry-run
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
Example output:
|
|
131
|
+
|
|
132
|
+
```
|
|
133
|
+
🚀 django-deploy-toolkit — Setup
|
|
134
|
+
|
|
135
|
+
[DRY RUN] Would write: /etc/systemd/system/myproject.socket
|
|
136
|
+
[DRY RUN] Would write: /etc/systemd/system/myproject.service
|
|
137
|
+
[DRY RUN] Would write: /etc/nginx/sites-available/myproject
|
|
138
|
+
[DRY RUN] Would remove: /etc/nginx/sites-enabled/default
|
|
139
|
+
[DRY RUN] Would remove: /etc/nginx/sites-available/default
|
|
140
|
+
[DRY RUN] Would create symlink: /etc/nginx/sites-enabled/myproject -> /etc/nginx/sites-available/myproject
|
|
141
|
+
[DRY RUN] Would run: systemctl daemon-reload
|
|
142
|
+
[DRY RUN] Would run: systemctl enable myproject.socket
|
|
143
|
+
[DRY RUN] Would run: systemctl start myproject.socket
|
|
144
|
+
[DRY RUN] Would run: systemctl enable myproject.service
|
|
145
|
+
[DRY RUN] Would run: nginx -t
|
|
146
|
+
[DRY RUN] Would run: systemctl reload nginx
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
---
|
|
150
|
+
|
|
151
|
+
## Manual Overrides
|
|
152
|
+
|
|
153
|
+
All CLI flags:
|
|
154
|
+
|
|
155
|
+
```bash
|
|
156
|
+
django-deploy setup [OPTIONS]
|
|
157
|
+
|
|
158
|
+
Options:
|
|
159
|
+
--dry-run Show what would be done without doing it
|
|
160
|
+
--project-path PATH Override the detected project path
|
|
161
|
+
--project-name NAME Override the detected project name
|
|
162
|
+
--no-confirm Skip the confirmation prompt (for scripts/CI)
|
|
163
|
+
--verbose / --no-verbose Show or hide detailed output
|
|
164
|
+
--version Show version and exit
|
|
165
|
+
--help Show this message and exit
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
Other commands:
|
|
169
|
+
|
|
170
|
+
```bash
|
|
171
|
+
django-deploy detect # Just run detection, no install
|
|
172
|
+
django-deploy generate # Generate files to current directory
|
|
173
|
+
django-deploy generate --output-dir ./configs # Generate to a specific directory
|
|
174
|
+
django-deploy rollback --name myproject # Rollback a previous install
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
---
|
|
178
|
+
|
|
179
|
+
## Generated File Examples
|
|
180
|
+
|
|
181
|
+
### Gunicorn Socket (`/etc/systemd/system/myproject.socket`)
|
|
182
|
+
|
|
183
|
+
```ini
|
|
184
|
+
[Unit]
|
|
185
|
+
Description=gunicorn socket for myproject
|
|
186
|
+
|
|
187
|
+
[Socket]
|
|
188
|
+
ListenStream=/run/myproject.sock
|
|
189
|
+
|
|
190
|
+
[Install]
|
|
191
|
+
WantedBy=sockets.target
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
### Gunicorn Service (`/etc/systemd/system/myproject.service`)
|
|
195
|
+
|
|
196
|
+
```ini
|
|
197
|
+
[Unit]
|
|
198
|
+
Description=gunicorn daemon for myproject
|
|
199
|
+
Requires=myproject.socket
|
|
200
|
+
After=network.target
|
|
201
|
+
|
|
202
|
+
[Service]
|
|
203
|
+
User=deploy
|
|
204
|
+
Group=deploy
|
|
205
|
+
WorkingDirectory=/home/deploy/myproject
|
|
206
|
+
ExecStart=/home/deploy/myproject/venv/bin/python -m gunicorn \
|
|
207
|
+
--access-logfile - \
|
|
208
|
+
--workers 5 \
|
|
209
|
+
--bind unix:/run/myproject.sock \
|
|
210
|
+
myproject.wsgi:application
|
|
211
|
+
|
|
212
|
+
[Install]
|
|
213
|
+
WantedBy=multi-user.target
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
### Nginx Config (`/etc/nginx/sites-available/myproject`)
|
|
217
|
+
|
|
218
|
+
```nginx
|
|
219
|
+
server {
|
|
220
|
+
listen 80;
|
|
221
|
+
server_name 192.168.1.100;
|
|
222
|
+
|
|
223
|
+
location /static/ {
|
|
224
|
+
root /home/deploy/myproject;
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
location /media/ {
|
|
228
|
+
root /home/deploy/myproject;
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
location / {
|
|
232
|
+
include proxy_params;
|
|
233
|
+
proxy_pass http://unix:/run/myproject.sock;
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
```
|
|
237
|
+
|
|
238
|
+
---
|
|
239
|
+
|
|
240
|
+
## Default Nginx Config Removal
|
|
241
|
+
|
|
242
|
+
During installation, `django-deploy-toolkit` removes the default Nginx configuration files:
|
|
243
|
+
|
|
244
|
+
- `/etc/nginx/sites-enabled/default`
|
|
245
|
+
- `/etc/nginx/sites-available/default`
|
|
246
|
+
|
|
247
|
+
**Why?** The default Nginx config listens on port 80 and can conflict with your project's server block. Removing it ensures your Django project is the one handling requests.
|
|
248
|
+
|
|
249
|
+
**Safety measures:**
|
|
250
|
+
- Both files are backed up to a temporary directory before deletion
|
|
251
|
+
- The tool warns you and pauses for 3 seconds before proceeding (press Ctrl+C to cancel)
|
|
252
|
+
- If you skip if they don't exist — no error
|
|
253
|
+
- During rollback, the backed-up files are restored to their original locations
|
|
254
|
+
|
|
255
|
+
---
|
|
256
|
+
|
|
257
|
+
## Rollback
|
|
258
|
+
|
|
259
|
+
If any installation step fails, `django-deploy-toolkit` automatically rolls back all changes:
|
|
260
|
+
|
|
261
|
+
1. Files created during the run are deleted
|
|
262
|
+
2. Symlinks created during the run are removed
|
|
263
|
+
3. The default Nginx config is restored from backup (if it was removed)
|
|
264
|
+
4. Services that were started are stopped and disabled
|
|
265
|
+
5. Systemd daemon is reloaded
|
|
266
|
+
6. Nginx config is tested and reloaded
|
|
267
|
+
|
|
268
|
+
You can also manually rollback a previous installation:
|
|
269
|
+
|
|
270
|
+
```bash
|
|
271
|
+
django-deploy rollback --name myproject
|
|
272
|
+
```
|
|
273
|
+
|
|
274
|
+
---
|
|
275
|
+
|
|
276
|
+
## Contributing
|
|
277
|
+
|
|
278
|
+
Contributions are welcome! Whether it's a bug fix, new feature, or documentation improvement — all help is appreciated.
|
|
279
|
+
|
|
280
|
+
```bash
|
|
281
|
+
# Clone the repository
|
|
282
|
+
git clone https://github.com/antusaha970/django-deploy-toolkit.git
|
|
283
|
+
cd django-deploy-toolkit
|
|
284
|
+
|
|
285
|
+
# Install dev dependencies
|
|
286
|
+
make install-dev
|
|
287
|
+
|
|
288
|
+
# Run tests
|
|
289
|
+
make test
|
|
290
|
+
|
|
291
|
+
# Run tests with coverage
|
|
292
|
+
make coverage
|
|
293
|
+
```
|
|
294
|
+
|
|
295
|
+
---
|
|
296
|
+
|
|
297
|
+
## Credits
|
|
298
|
+
|
|
299
|
+
- **Antu Saha** — Creator and lead maintainer
|
|
300
|
+
- All open-source contributors — Thank you for helping make this project better! 🙏
|
|
301
|
+
|
|
302
|
+
---
|
|
303
|
+
|
|
304
|
+
## License
|
|
305
|
+
|
|
306
|
+
MIT — see [LICENSE](LICENSE) for details.
|
|
@@ -0,0 +1,267 @@
|
|
|
1
|
+
# django-deploy-toolkit
|
|
2
|
+
|
|
3
|
+
**Auto-generate and install Gunicorn & Nginx configuration for Django projects on Ubuntu/Debian.**
|
|
4
|
+
|
|
5
|
+
`django-deploy-toolkit` detects your Django project's configuration, generates production-ready systemd service/socket files and Nginx server blocks, and installs them — all with a single command. It handles edge cases gracefully, supports dry-run mode, and includes full rollback on failure.
|
|
6
|
+
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## Created By
|
|
10
|
+
|
|
11
|
+
**Antu Saha** — creator and lead maintainer of this package.
|
|
12
|
+
|
|
13
|
+
We also appreciate all the open-source contributors who help improve `django-deploy-toolkit`. Contributions of any kind are welcome — bug reports, feature requests, documentation improvements, and code contributions. See the [Contributing](#contributing) section below to get started.
|
|
14
|
+
|
|
15
|
+
---
|
|
16
|
+
|
|
17
|
+
## Requirements
|
|
18
|
+
|
|
19
|
+
- **OS:** Ubuntu / Debian Linux
|
|
20
|
+
- **Python:** 3.8 or higher
|
|
21
|
+
- **Django project** with a `manage.py` file
|
|
22
|
+
- **Gunicorn** installed in the project's virtual environment
|
|
23
|
+
- **Nginx** installed on the server (`sudo apt install nginx`)
|
|
24
|
+
- **systemd** available (standard on Ubuntu/Debian)
|
|
25
|
+
|
|
26
|
+
---
|
|
27
|
+
|
|
28
|
+
## Installation
|
|
29
|
+
|
|
30
|
+
```bash
|
|
31
|
+
pip install django-deploy-toolkit
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
Or install from source:
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
git clone https://github.com/antusaha970/django-deploy-toolkit.git
|
|
38
|
+
cd django-deploy-toolkit
|
|
39
|
+
pip install -e .
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
---
|
|
43
|
+
|
|
44
|
+
## Quick Start
|
|
45
|
+
|
|
46
|
+
```bash
|
|
47
|
+
# Navigate to your Django project root (where manage.py lives)
|
|
48
|
+
cd /path/to/your/django/project
|
|
49
|
+
|
|
50
|
+
# Activate your project's virtual environment
|
|
51
|
+
source venv/bin/activate
|
|
52
|
+
|
|
53
|
+
# Run the setup
|
|
54
|
+
django-deploy setup
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
That's it. The tool will:
|
|
58
|
+
1. Auto-detect your project configuration
|
|
59
|
+
2. Show you what it found and ask for confirmation
|
|
60
|
+
3. Generate and install the config files
|
|
61
|
+
4. Enable and start the services
|
|
62
|
+
5. Test and reload Nginx
|
|
63
|
+
|
|
64
|
+
---
|
|
65
|
+
|
|
66
|
+
## What Gets Auto-Detected
|
|
67
|
+
|
|
68
|
+
| Setting | Detection Method |
|
|
69
|
+
|---------|-----------------|
|
|
70
|
+
| **Project Name** | Basename of the current directory (sanitized) |
|
|
71
|
+
| **Project Path** | Current working directory (searches for `manage.py`) |
|
|
72
|
+
| **WSGI Module** | Parsed from `manage.py` → `DJANGO_SETTINGS_MODULE`, or scans for `wsgi.py` |
|
|
73
|
+
| **User** | `$USER` env var → `$LOGNAME` → `pwd.getpwuid()` |
|
|
74
|
+
| **Group** | Primary group of the detected user via `grp.getgrgid()` |
|
|
75
|
+
| **Python Path** | `sys.executable` (virtualenv-aware) |
|
|
76
|
+
| **Server IP** | `/etc/hosts` → `socket.gethostbyname()` → UDP socket trick → `_` (catch-all) |
|
|
77
|
+
| **Workers** | `(2 × CPU cores) + 1`, capped at 9 (via `psutil`) |
|
|
78
|
+
| **Static Root** | Parsed from `python manage.py diffsettings` output |
|
|
79
|
+
| **Media Root** | Same as Static Root |
|
|
80
|
+
|
|
81
|
+
---
|
|
82
|
+
|
|
83
|
+
## Dry-Run Mode
|
|
84
|
+
|
|
85
|
+
Preview everything that would happen without making any changes:
|
|
86
|
+
|
|
87
|
+
```bash
|
|
88
|
+
django-deploy setup --dry-run
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
Example output:
|
|
92
|
+
|
|
93
|
+
```
|
|
94
|
+
🚀 django-deploy-toolkit — Setup
|
|
95
|
+
|
|
96
|
+
[DRY RUN] Would write: /etc/systemd/system/myproject.socket
|
|
97
|
+
[DRY RUN] Would write: /etc/systemd/system/myproject.service
|
|
98
|
+
[DRY RUN] Would write: /etc/nginx/sites-available/myproject
|
|
99
|
+
[DRY RUN] Would remove: /etc/nginx/sites-enabled/default
|
|
100
|
+
[DRY RUN] Would remove: /etc/nginx/sites-available/default
|
|
101
|
+
[DRY RUN] Would create symlink: /etc/nginx/sites-enabled/myproject -> /etc/nginx/sites-available/myproject
|
|
102
|
+
[DRY RUN] Would run: systemctl daemon-reload
|
|
103
|
+
[DRY RUN] Would run: systemctl enable myproject.socket
|
|
104
|
+
[DRY RUN] Would run: systemctl start myproject.socket
|
|
105
|
+
[DRY RUN] Would run: systemctl enable myproject.service
|
|
106
|
+
[DRY RUN] Would run: nginx -t
|
|
107
|
+
[DRY RUN] Would run: systemctl reload nginx
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
---
|
|
111
|
+
|
|
112
|
+
## Manual Overrides
|
|
113
|
+
|
|
114
|
+
All CLI flags:
|
|
115
|
+
|
|
116
|
+
```bash
|
|
117
|
+
django-deploy setup [OPTIONS]
|
|
118
|
+
|
|
119
|
+
Options:
|
|
120
|
+
--dry-run Show what would be done without doing it
|
|
121
|
+
--project-path PATH Override the detected project path
|
|
122
|
+
--project-name NAME Override the detected project name
|
|
123
|
+
--no-confirm Skip the confirmation prompt (for scripts/CI)
|
|
124
|
+
--verbose / --no-verbose Show or hide detailed output
|
|
125
|
+
--version Show version and exit
|
|
126
|
+
--help Show this message and exit
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
Other commands:
|
|
130
|
+
|
|
131
|
+
```bash
|
|
132
|
+
django-deploy detect # Just run detection, no install
|
|
133
|
+
django-deploy generate # Generate files to current directory
|
|
134
|
+
django-deploy generate --output-dir ./configs # Generate to a specific directory
|
|
135
|
+
django-deploy rollback --name myproject # Rollback a previous install
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
---
|
|
139
|
+
|
|
140
|
+
## Generated File Examples
|
|
141
|
+
|
|
142
|
+
### Gunicorn Socket (`/etc/systemd/system/myproject.socket`)
|
|
143
|
+
|
|
144
|
+
```ini
|
|
145
|
+
[Unit]
|
|
146
|
+
Description=gunicorn socket for myproject
|
|
147
|
+
|
|
148
|
+
[Socket]
|
|
149
|
+
ListenStream=/run/myproject.sock
|
|
150
|
+
|
|
151
|
+
[Install]
|
|
152
|
+
WantedBy=sockets.target
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
### Gunicorn Service (`/etc/systemd/system/myproject.service`)
|
|
156
|
+
|
|
157
|
+
```ini
|
|
158
|
+
[Unit]
|
|
159
|
+
Description=gunicorn daemon for myproject
|
|
160
|
+
Requires=myproject.socket
|
|
161
|
+
After=network.target
|
|
162
|
+
|
|
163
|
+
[Service]
|
|
164
|
+
User=deploy
|
|
165
|
+
Group=deploy
|
|
166
|
+
WorkingDirectory=/home/deploy/myproject
|
|
167
|
+
ExecStart=/home/deploy/myproject/venv/bin/python -m gunicorn \
|
|
168
|
+
--access-logfile - \
|
|
169
|
+
--workers 5 \
|
|
170
|
+
--bind unix:/run/myproject.sock \
|
|
171
|
+
myproject.wsgi:application
|
|
172
|
+
|
|
173
|
+
[Install]
|
|
174
|
+
WantedBy=multi-user.target
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
### Nginx Config (`/etc/nginx/sites-available/myproject`)
|
|
178
|
+
|
|
179
|
+
```nginx
|
|
180
|
+
server {
|
|
181
|
+
listen 80;
|
|
182
|
+
server_name 192.168.1.100;
|
|
183
|
+
|
|
184
|
+
location /static/ {
|
|
185
|
+
root /home/deploy/myproject;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
location /media/ {
|
|
189
|
+
root /home/deploy/myproject;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
location / {
|
|
193
|
+
include proxy_params;
|
|
194
|
+
proxy_pass http://unix:/run/myproject.sock;
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
---
|
|
200
|
+
|
|
201
|
+
## Default Nginx Config Removal
|
|
202
|
+
|
|
203
|
+
During installation, `django-deploy-toolkit` removes the default Nginx configuration files:
|
|
204
|
+
|
|
205
|
+
- `/etc/nginx/sites-enabled/default`
|
|
206
|
+
- `/etc/nginx/sites-available/default`
|
|
207
|
+
|
|
208
|
+
**Why?** The default Nginx config listens on port 80 and can conflict with your project's server block. Removing it ensures your Django project is the one handling requests.
|
|
209
|
+
|
|
210
|
+
**Safety measures:**
|
|
211
|
+
- Both files are backed up to a temporary directory before deletion
|
|
212
|
+
- The tool warns you and pauses for 3 seconds before proceeding (press Ctrl+C to cancel)
|
|
213
|
+
- If you skip if they don't exist — no error
|
|
214
|
+
- During rollback, the backed-up files are restored to their original locations
|
|
215
|
+
|
|
216
|
+
---
|
|
217
|
+
|
|
218
|
+
## Rollback
|
|
219
|
+
|
|
220
|
+
If any installation step fails, `django-deploy-toolkit` automatically rolls back all changes:
|
|
221
|
+
|
|
222
|
+
1. Files created during the run are deleted
|
|
223
|
+
2. Symlinks created during the run are removed
|
|
224
|
+
3. The default Nginx config is restored from backup (if it was removed)
|
|
225
|
+
4. Services that were started are stopped and disabled
|
|
226
|
+
5. Systemd daemon is reloaded
|
|
227
|
+
6. Nginx config is tested and reloaded
|
|
228
|
+
|
|
229
|
+
You can also manually rollback a previous installation:
|
|
230
|
+
|
|
231
|
+
```bash
|
|
232
|
+
django-deploy rollback --name myproject
|
|
233
|
+
```
|
|
234
|
+
|
|
235
|
+
---
|
|
236
|
+
|
|
237
|
+
## Contributing
|
|
238
|
+
|
|
239
|
+
Contributions are welcome! Whether it's a bug fix, new feature, or documentation improvement — all help is appreciated.
|
|
240
|
+
|
|
241
|
+
```bash
|
|
242
|
+
# Clone the repository
|
|
243
|
+
git clone https://github.com/antusaha970/django-deploy-toolkit.git
|
|
244
|
+
cd django-deploy-toolkit
|
|
245
|
+
|
|
246
|
+
# Install dev dependencies
|
|
247
|
+
make install-dev
|
|
248
|
+
|
|
249
|
+
# Run tests
|
|
250
|
+
make test
|
|
251
|
+
|
|
252
|
+
# Run tests with coverage
|
|
253
|
+
make coverage
|
|
254
|
+
```
|
|
255
|
+
|
|
256
|
+
---
|
|
257
|
+
|
|
258
|
+
## Credits
|
|
259
|
+
|
|
260
|
+
- **Antu Saha** — Creator and lead maintainer
|
|
261
|
+
- All open-source contributors — Thank you for helping make this project better! 🙏
|
|
262
|
+
|
|
263
|
+
---
|
|
264
|
+
|
|
265
|
+
## License
|
|
266
|
+
|
|
267
|
+
MIT — see [LICENSE](LICENSE) for details.
|