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