mantis-cli 20.0.0__tar.gz → 22.0.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.
Files changed (52) hide show
  1. mantis_cli-22.0.0/PKG-INFO +483 -0
  2. mantis_cli-22.0.0/README.md +442 -0
  3. mantis_cli-22.0.0/mantis/__init__.py +1 -0
  4. {mantis_cli-20.0.0 → mantis_cli-22.0.0}/mantis/__main__.py +1 -1
  5. mantis_cli-22.0.0/mantis/app.py +219 -0
  6. mantis_cli-22.0.0/mantis/command_line.py +205 -0
  7. mantis_cli-22.0.0/mantis/commands/__init__.py +30 -0
  8. mantis_cli-22.0.0/mantis/commands/compose.py +31 -0
  9. mantis_cli-22.0.0/mantis/commands/configuration.py +16 -0
  10. mantis_cli-22.0.0/mantis/commands/connection.py +20 -0
  11. mantis_cli-22.0.0/mantis/commands/containers.py +120 -0
  12. mantis_cli-22.0.0/mantis/commands/core.py +43 -0
  13. mantis_cli-22.0.0/mantis/commands/django.py +35 -0
  14. mantis_cli-22.0.0/mantis/commands/images.py +38 -0
  15. mantis_cli-22.0.0/mantis/commands/nginx.py +8 -0
  16. mantis_cli-22.0.0/mantis/commands/postgres.py +47 -0
  17. mantis_cli-22.0.0/mantis/commands/secrets.py +77 -0
  18. mantis_cli-22.0.0/mantis/commands/services.py +53 -0
  19. mantis_cli-22.0.0/mantis/commands/volumes.py +21 -0
  20. mantis_cli-22.0.0/mantis/config.py +323 -0
  21. {mantis_cli-20.0.0 → mantis_cli-22.0.0}/mantis/environment.py +22 -17
  22. mantis_cli-22.0.0/mantis/extensions/django.py +83 -0
  23. {mantis_cli-20.0.0 → mantis_cli-22.0.0}/mantis/extensions/nginx.py +1 -3
  24. {mantis_cli-20.0.0 → mantis_cli-22.0.0}/mantis/extensions/postgres.py +9 -28
  25. {mantis_cli-20.0.0 → mantis_cli-22.0.0}/mantis/helpers.py +49 -1
  26. {mantis_cli-20.0.0 → mantis_cli-22.0.0}/mantis/managers.py +579 -176
  27. mantis_cli-22.0.0/mantis/schema.py +83 -0
  28. mantis_cli-22.0.0/mantis_cli.egg-info/PKG-INFO +483 -0
  29. mantis_cli-22.0.0/mantis_cli.egg-info/SOURCES.txt +43 -0
  30. {mantis_cli-20.0.0 → mantis_cli-22.0.0}/mantis_cli.egg-info/entry_points.txt +0 -1
  31. {mantis_cli-20.0.0 → mantis_cli-22.0.0}/mantis_cli.egg-info/requires.txt +2 -0
  32. {mantis_cli-20.0.0 → mantis_cli-22.0.0}/mantis_cli.egg-info/top_level.txt +1 -0
  33. {mantis_cli-20.0.0 → mantis_cli-22.0.0}/setup.py +1 -1
  34. mantis_cli-22.0.0/tests/__init__.py +1 -0
  35. mantis_cli-22.0.0/tests/test_command_line.py +221 -0
  36. mantis_cli-22.0.0/tests/test_config.py +388 -0
  37. mantis_cli-22.0.0/tests/test_managers.py +316 -0
  38. mantis_cli-20.0.0/PKG-INFO +0 -340
  39. mantis_cli-20.0.0/README.md +0 -317
  40. mantis_cli-20.0.0/mantis/__init__.py +0 -1
  41. mantis_cli-20.0.0/mantis/command_line.py +0 -215
  42. mantis_cli-20.0.0/mantis/extensions/django.py +0 -39
  43. mantis_cli-20.0.0/mantis/logic.py +0 -222
  44. mantis_cli-20.0.0/mantis_cli.egg-info/PKG-INFO +0 -340
  45. mantis_cli-20.0.0/mantis_cli.egg-info/SOURCES.txt +0 -24
  46. {mantis_cli-20.0.0 → mantis_cli-22.0.0}/LICENSE +0 -0
  47. {mantis_cli-20.0.0 → mantis_cli-22.0.0}/MANIFEST.in +0 -0
  48. /mantis_cli-20.0.0/mantis/crypto.py → /mantis_cli-22.0.0/mantis/cryptography.py +0 -0
  49. {mantis_cli-20.0.0 → mantis_cli-22.0.0}/mantis/extensions/__init__.py +0 -0
  50. {mantis_cli-20.0.0 → mantis_cli-22.0.0}/mantis/mantis.tpl +0 -0
  51. {mantis_cli-20.0.0 → mantis_cli-22.0.0}/mantis_cli.egg-info/dependency_links.txt +0 -0
  52. {mantis_cli-20.0.0 → mantis_cli-22.0.0}/setup.cfg +0 -0
@@ -0,0 +1,483 @@
1
+ Metadata-Version: 2.4
2
+ Name: mantis_cli
3
+ Version: 22.0.0
4
+ Summary: Management command to build and deploy webapps, especially based on Django
5
+ Home-page: https://github.com/PragmaticMates/mantis-cli
6
+ Author: Erik Telepovský
7
+ Author-email: info@pragmaticmates.com
8
+ Maintainer: Pragmatic Mates
9
+ Maintainer-email: info@pragmaticmates.com
10
+ License: GNU General Public License (GPL)
11
+ Keywords: management deployment docker command
12
+ Classifier: Programming Language :: Python
13
+ Classifier: Operating System :: OS Independent
14
+ Classifier: Environment :: Web Environment
15
+ Classifier: Intended Audience :: Developers
16
+ Classifier: Framework :: Django
17
+ Classifier: License :: OSI Approved :: GNU General Public License (GPL)
18
+ Classifier: Development Status :: 5 - Production/Stable
19
+ Description-Content-Type: text/markdown
20
+ License-File: LICENSE
21
+ Requires-Dist: cffi
22
+ Requires-Dist: cryptography
23
+ Requires-Dist: pycryptodome
24
+ Requires-Dist: pydantic
25
+ Requires-Dist: PyYAML
26
+ Requires-Dist: rich
27
+ Requires-Dist: typer
28
+ Dynamic: author
29
+ Dynamic: author-email
30
+ Dynamic: classifier
31
+ Dynamic: description
32
+ Dynamic: description-content-type
33
+ Dynamic: home-page
34
+ Dynamic: keywords
35
+ Dynamic: license
36
+ Dynamic: license-file
37
+ Dynamic: maintainer
38
+ Dynamic: maintainer-email
39
+ Dynamic: requires-dist
40
+ Dynamic: summary
41
+
42
+ # mantis-cli
43
+
44
+ Mantis is a CLI (command line interface) tool designed as a wrapper upon docker and docker compose commands for your project.
45
+
46
+ Using few commands you can:
47
+ - encrypt and decrypt your environment files
48
+ - build and push docker images
49
+ - create docker contexts
50
+ - zero-downtime deploy your application
51
+ - print logs of your containers
52
+ - connect to bash of your containers using SSH
53
+ - clean docker resources
54
+ - use specific commands using Django, PostgreSQL and Nginx extensions
55
+ - and much more
56
+
57
+ ## Installation
58
+
59
+ ```bash
60
+ pip install mantis-cli
61
+ ```
62
+
63
+ ## Configuration
64
+
65
+ Create a **mantis.json** configuration file in JSON format.
66
+ You can use ``<MANTIS>`` variable in your paths if needed as a relative reference to your mantis file.
67
+
68
+ ### Explanation of config arguments
69
+
70
+ | argument | type | description |
71
+ |--------------------------|--------|--------------------------------------------------------------|
72
+ | manager_class | string | class path to mantis manager class |
73
+ | extensions | dict | Django, Postgres, Nginx |
74
+ | encryption | dict | encryption settings |
75
+ | encryption.deterministic | bool | if True, encryption hash is always the same for same value |
76
+ | encryption.folder | bool | path to folder with your environment files |
77
+ | configs | dict | configuration settings |
78
+ | configs.folder | string | path to folder with your configuration files |
79
+ | build | dict | build settings |
80
+ | build.tool | string | "docker" or "compose" |
81
+ | compose | dict | docker compose settings |
82
+ | compose.command | string | standalone "docker-compose" or "docker compose" plugin |
83
+ | compose.folder | string | path to folder with compose files |
84
+ | environment | dict | environment settings |
85
+ | environment.folder | string | path to folder with environment files |
86
+ | environment.file_prefix | string | file prefix of environment files |
87
+ | zero_downtime | array | list of services to deploy with zero downtime |
88
+ | project_path | string | path to folder with project files on remote server |
89
+ | connection | string | single connection string (use instead of connections) |
90
+ | connections | dict | definition of your connections for each environment |
91
+
92
+ TODO:
93
+ - default values
94
+
95
+ See [template file](https://github.com/PragmaticMates/mantis-cli/blob/master/mantis/mantis.tpl) for exact JSON structure.
96
+
97
+ ### Connections
98
+
99
+ Mantis supports two connection modes: **multi-environment** and **single connection**.
100
+
101
+ #### Multi-environment mode
102
+
103
+ Use `connections` (dict) when you have multiple environments like stage, production, etc.:
104
+
105
+ ```json
106
+ "connections": {
107
+ "stage": "context://<context_name>",
108
+ "production": "ssh://<user>@<host>:<port>"
109
+ }
110
+ ```
111
+
112
+ In this mode, you must specify the environment in every command:
113
+
114
+ ```bash
115
+ mantis -e production status
116
+ mantis -e stage deploy
117
+ ```
118
+
119
+ #### Single connection mode
120
+
121
+ Use `connection` (string) when you only have one environment. This simplifies the CLI usage by making the environment parameter optional:
122
+
123
+ ```json
124
+ "connection": "ssh://<user>@<host>:<port>"
125
+ ```
126
+
127
+ In this mode, you can run commands without specifying an environment:
128
+
129
+ ```bash
130
+ mantis status
131
+ mantis deploy
132
+ ```
133
+
134
+ Environment files are looked up directly in the `environment.folder` instead of environment-specific subfolders.
135
+
136
+ **Note:** You cannot define both `connection` and `connections` in the same config file.
137
+
138
+ ### Encryption
139
+
140
+ If you plan to use encryption and decryption of your environment files, you need to create encryption key.
141
+
142
+ Generation of new key:
143
+
144
+ ```bash
145
+ mantis generate-key
146
+ ```
147
+
148
+ Save key to **mantis.key** file:
149
+
150
+ ```bash
151
+ echo <MANTIS_KEY> > /path/to/encryption/folder/mantis.key
152
+ ```
153
+
154
+ Then you can encrypt your environment files using symmetric encryption.
155
+ Every environment variable is encrypted separately instead of encrypting the whole file for better tracking of changes in VCS.
156
+
157
+ ```bash
158
+ mantis -e <ENVIRONMENT> encrypt-env
159
+ ```
160
+
161
+ Decryption is easy like this:
162
+
163
+ ```bash
164
+ mantis -e <ENVIRONMENT> decrypt-env
165
+ ```
166
+
167
+ When decrypting, mantis prompts user for confirmation.
168
+ You can bypass that by forcing decryption which can be useful in CI/CD pipeline:
169
+
170
+ ```bash
171
+ mantis -e <ENVIRONMENT> decrypt-env --force
172
+ ```
173
+
174
+ ## Usage
175
+
176
+ General usage of mantis-cli has this format:
177
+
178
+ ```bash
179
+ mantis [OPTIONS] COMMAND [ARGS]... [+ COMMAND [ARGS]...]
180
+ ```
181
+
182
+ Use `+` to chain multiple commands:
183
+
184
+ ```bash
185
+ mantis -e production build + push + deploy
186
+ ```
187
+
188
+ ### Options
189
+
190
+ | Option | Description |
191
+ |-----------------|---------------------------------------------------|
192
+ | --env, -e | Environment ID (e.g., stage, production) |
193
+ | --mode, -m | Execution mode: remote (default), ssh, host |
194
+ | --dry-run, -n | Show commands without executing |
195
+ | --version, -v | Show version and exit |
196
+ | --help, -h | Show help message |
197
+
198
+ ### Modes
199
+
200
+ Mantis can operate in 3 different modes depending on how it connects to remote machine:
201
+
202
+ #### Remote mode `--mode=remote`
203
+
204
+ Runs commands remotely from local machine using DOCKER_HOST or DOCKER_CONTEXT (default)
205
+
206
+ #### SSH mode `--mode=ssh`
207
+
208
+ Connects to host via SSH and runs all mantis commands on remote machine directly (mantis-cli needs to be installed on server)
209
+
210
+ #### Host mode `--mode=host`
211
+
212
+ Runs mantis on host machine directly without invoking connection (used as proxy for ssh mode)
213
+
214
+ ### Environments
215
+
216
+ Environment can be either *local* or any custom environment like *stage*, *production* etc.
217
+ The environment is also used as an identifier for remote connection.
218
+
219
+ ### Commands
220
+
221
+ Run `mantis --help` to see all available commands with their descriptions.
222
+
223
+ **Core commands:**
224
+
225
+ | Command / Shortcut | Description |
226
+ |---------------------------------------|-----------------------------------------------------------|
227
+ | status / s | Prints images and containers |
228
+ | deploy [--dirty] [--strategy] / d | Runs deployment process |
229
+ | rolling-update [service] / ru | Performs rolling update of containers one-by-one |
230
+ | clean [params...] / c | Clean images, containers, networks |
231
+
232
+ **Files:**
233
+
234
+ | Command / Shortcut | Description |
235
+ |---------------------------------------|-----------------------------------------------------------|
236
+ | upload / u | Uploads config, compose and env files to server |
237
+
238
+ **Images:**
239
+
240
+ | Command / Shortcut | Description |
241
+ |---------------------------------------|-----------------------------------------------------------|
242
+ | build [SERVICES...] / b | Builds all services with Dockerfiles |
243
+ | pull [SERVICES...] / pl | Pulls required images for services |
244
+ | push [SERVICES...] / p | Push built images to repository |
245
+ | get-image-name SERVICE | Gets image name for service |
246
+
247
+ **Containers:**
248
+
249
+ | Command / Shortcut | Description |
250
+ |---------------------------------------|-----------------------------------------------------------|
251
+ | logs [CONTAINER] / l | Prints logs of containers |
252
+ | networks / n | Prints docker networks |
253
+ | healthcheck [CONTAINER] / hc | Execute health-check of container |
254
+ | stop [CONTAINERS...] | Stops containers |
255
+ | start [CONTAINERS...] | Starts containers |
256
+ | kill [CONTAINERS...] | Kills containers |
257
+ | remove [CONTAINERS...] [--force] | Removes containers |
258
+ | rename CONTAINER NEW_NAME | Rename container |
259
+ | bash CONTAINER | Runs bash in container |
260
+ | sh CONTAINER | Runs sh in container |
261
+ | exec CONTAINER COMMAND... | Executes command in container |
262
+ | exec-it CONTAINER COMMAND... | Executes command in container (interactive) |
263
+ | get-container-name SERVICE | Gets container name for service |
264
+ | remove-suffixes [PREFIX] | Removes numerical suffixes from container names |
265
+
266
+ **Compose:**
267
+
268
+ | Command | Description |
269
+ |---------------------------------------|-----------------------------------------------------------|
270
+ | up [PARAMS...] | Calls compose up |
271
+ | down [PARAMS...] | Calls compose down |
272
+ | run PARAMS... | Calls compose run with params |
273
+
274
+ **Services:**
275
+
276
+ | Command | Description |
277
+ |---------------------------------------|-----------------------------------------------------------|
278
+ | restart [SERVICE] | Restarts containers |
279
+ | scale SERVICE NUM | Scales service to given number |
280
+ | zero-downtime [SERVICE] | Runs zero-downtime deployment |
281
+ | restart-service SERVICE | Restarts a specific service |
282
+ | services | Lists all defined services |
283
+ | services-to-build | Lists services that will be built |
284
+
285
+ **Volumes:**
286
+
287
+ | Command | Description |
288
+ |---------------------------------------|-----------------------------------------------------------|
289
+ | backup-volume VOLUME | Backups volume to a file |
290
+ | restore-volume VOLUME FILE | Restores volume from a file |
291
+
292
+ **Secrets:**
293
+
294
+ | Command | Description |
295
+ |---------------------------------------|-----------------------------------------------------------|
296
+ | show-env [KEYWORD] | Shows environment variables from .env files |
297
+ | encrypt-env [--force] | Encrypts environment files |
298
+ | decrypt-env [--force] | Decrypts environment files |
299
+ | check-env | Compares encrypted and decrypted env files |
300
+ | generate-key | Creates new encryption key |
301
+ | read-key | Returns encryption key value |
302
+
303
+ **Configuration:**
304
+
305
+ | Command | Description |
306
+ |---------------------------------------|-----------------------------------------------------------|
307
+ | show-config | Shows the JSON mantis config |
308
+ | check-config | Validates config file |
309
+
310
+ **Connections:**
311
+
312
+ | Command | Description |
313
+ |---------------------------------------|-----------------------------------------------------------|
314
+ | contexts | Prints all docker contexts |
315
+ | create-context | Creates docker context |
316
+ | ssh | Connects to remote host via SSH |
317
+
318
+ **Django extension:**
319
+
320
+ | Command | Description |
321
+ |---------------------------------------|-----------------------------------------------------------|
322
+ | shell | Runs Django shell |
323
+ | manage [OPTIONS] CMD [ARGS...] | Runs Django manage command |
324
+ | send-test-email | Sends test email to admins |
325
+ | reset-migrations | Clears migration history and fakes all migrations |
326
+
327
+ The `manage` command supports health-check options:
328
+ - `--if-healthy`: Only execute if the container is currently healthy. Skips with a warning if not healthy.
329
+ - `--healthy-timeout N`: Wait up to N seconds for the container to become healthy before executing. Polls every second and skips the command if the timeout is reached.
330
+
331
+ **PostgreSQL extension:**
332
+
333
+ | Command | Description |
334
+ |---------------------------------------|-----------------------------------------------------------|
335
+ | psql | Starts psql console |
336
+ | pg-dump [--data-only] [--table] | Backups PostgreSQL database |
337
+ | pg-dump-data [--table] | Backups PostgreSQL database (data only) |
338
+ | pg-restore FILENAME [--table] | Restores database from backup |
339
+ | pg-restore-data FILENAME TABLE | Restores database data from backup |
340
+
341
+ **Nginx extension:**
342
+
343
+ | Command | Description |
344
+ |---------------------------------------|-----------------------------------------------------------|
345
+ | reload-webserver | Reloads nginx webserver |
346
+
347
+ ### Examples
348
+
349
+ ```bash
350
+ mantis --version
351
+ mantis -e local encrypt-env
352
+ mantis -e stage build
353
+ mantis -e production logs web
354
+
355
+ # Run multiple commands using + separator
356
+ mantis -e stage build + push + deploy
357
+ mantis -e stage build web api + push + deploy + status
358
+
359
+ # Commands with arguments
360
+ mantis -e production deploy --dirty
361
+ mantis -e production manage migrate
362
+ mantis -e production manage --healthy-timeout 60 migrate
363
+ mantis -e production pg-dump --data-only --table users
364
+
365
+ # Single connection mode (no environment needed)
366
+ mantis status
367
+ mantis deploy
368
+ ```
369
+
370
+ Check `mantis --help` for more details, or `mantis COMMAND --help` for command-specific help.
371
+
372
+ ## Flow
373
+
374
+ ### 1. Build
375
+
376
+ Once you define mantis config for your project and optionally create encryption key, you can build your docker images:
377
+
378
+ ```bash
379
+ mantis -e <ENVIRONMENT> build
380
+ ```
381
+
382
+ Mantis either uses `docker-compose --build` or `docker build` command depending on build tool defined in your config.
383
+ Build image names use '_' as word separator.
384
+
385
+ ### 2. Push
386
+
387
+ Built images needs to be pushed to your repository defined in compose file (you need to authenticate)
388
+
389
+ ```bash
390
+ mantis -e <ENVIRONMENT> push
391
+ ```
392
+
393
+ ### 3. Deployment
394
+
395
+ Deployment to your remote server is being executed by calling simple command:
396
+
397
+ ```bash
398
+ mantis -e <ENVIRONMENT> deploy
399
+ ```
400
+
401
+ Or chain all steps together:
402
+
403
+ ```bash
404
+ mantis -e <ENVIRONMENT> build + push + deploy
405
+ ```
406
+
407
+ The deployment process consists of multiple steps:
408
+
409
+ - If using --mode=ssh, mantis uploads mantis config, environment files and compose file to server
410
+ - pulling docker images from repositories
411
+ - [zero-downtime deployment](https://github.com/PragmaticMates/mantis-cli?tab=readme-ov-file#zero-downtime-deployment) of running containers (if any)
412
+ - calling docker compose up to start containers
413
+ - removing numeric suffixes from container names (if scale==1)
414
+ - reloading webserver (if found suitable extension)
415
+ - cleaning docker resources (without volumes)
416
+
417
+ Docker container names use '-' as word separator (docker compose v2 convention).
418
+
419
+ ### 4. Inspect
420
+
421
+ Once deployed, you can verify the container status:
422
+
423
+ ```bash
424
+ mantis -e <ENVIRONMENT> status
425
+ ```
426
+
427
+ list all docker networks:
428
+
429
+ ```bash
430
+ mantis -e <ENVIRONMENT> networks
431
+ ```
432
+
433
+ and also check all container logs:
434
+
435
+ ```bash
436
+ mantis -e <ENVIRONMENT> logs
437
+ ```
438
+
439
+ If you need to follow logs of a specific container, you can do it by passing container name to command:
440
+
441
+ ```bash
442
+ mantis -e <ENVIRONMENT> logs <container-name>
443
+ ```
444
+
445
+ ### 5. Another useful commands
446
+
447
+ Sometimes, instead of calling whole deployment process, you just need to call compose commands directly:
448
+
449
+ ```bash
450
+ mantis -e <ENVIRONMENT> up
451
+ mantis -e <ENVIRONMENT> down
452
+ mantis -e <ENVIRONMENT> restart
453
+ mantis -e <ENVIRONMENT> stop
454
+ mantis -e <ENVIRONMENT> kill
455
+ mantis -e <ENVIRONMENT> start
456
+ mantis -e <ENVIRONMENT> clean
457
+ ```
458
+
459
+ Commands over a single container:
460
+
461
+ ```bash
462
+ mantis -e <ENVIRONMENT> bash <container-name>
463
+ mantis -e <ENVIRONMENT> sh <container-name>
464
+ mantis -e <ENVIRONMENT> run <params>
465
+ ```
466
+
467
+ ## Zero-downtime deployment
468
+
469
+ Mantis has own zero-downtime deployment implementation without any third-party dependencies.
470
+ It uses docker compose service scaling and docker health-checks.
471
+
472
+ Works as follows:
473
+
474
+ - a new service container starts using scaling
475
+ - mantis waits until the new container is healthy by checking its health status. If not health-check is defined, it waits X seconds defined by start period
476
+ - reloads webserver (to proxy requests to new container)
477
+ - once container is healthy or start period ends the old container is stopped and removed
478
+ - new container is renamed to previous container's name
479
+ - webserver is reloaded again
480
+
481
+ ## Release notes
482
+
483
+ Mantis uses semantic versioning. See more in [changelog](https://github.com/PragmaticMates/mantis-cli/blob/master/CHANGES.md).