portainer-redeploy-cli 0.1.0__py3-none-any.whl
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.
- portainer_redeploy_cli/__init__.py +1 -0
- portainer_redeploy_cli/__main__.py +972 -0
- portainer_redeploy_cli-0.1.0.dist-info/METADATA +172 -0
- portainer_redeploy_cli-0.1.0.dist-info/RECORD +7 -0
- portainer_redeploy_cli-0.1.0.dist-info/WHEEL +4 -0
- portainer_redeploy_cli-0.1.0.dist-info/entry_points.txt +2 -0
- portainer_redeploy_cli-0.1.0.dist-info/licenses/LICENSE +661 -0
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: portainer-redeploy-cli
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Redeploy Portainer stacks from the terminal, with a version check and a live rollout view
|
|
5
|
+
Project-URL: Repository, https://gitlab.com/alexandra.tapkova/portainer-redeploy-cli
|
|
6
|
+
Author-email: Alexandra Ťapková <git@ouppy.space>
|
|
7
|
+
License: MIT
|
|
8
|
+
License-File: LICENSE
|
|
9
|
+
Keywords: cli,compose,deploy,devops,docker,portainer,swarm
|
|
10
|
+
Classifier: Development Status :: 3 - Alpha
|
|
11
|
+
Classifier: Environment :: Console
|
|
12
|
+
Classifier: Intended Audience :: Developers
|
|
13
|
+
Classifier: Intended Audience :: System Administrators
|
|
14
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
15
|
+
Classifier: Programming Language :: Python :: 3
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
22
|
+
Classifier: Topic :: System :: Software Distribution
|
|
23
|
+
Classifier: Topic :: System :: Systems Administration
|
|
24
|
+
Requires-Python: >=3.9
|
|
25
|
+
Requires-Dist: expandvars>=1.0
|
|
26
|
+
Requires-Dist: httpx>=0.24
|
|
27
|
+
Requires-Dist: pyyaml>=5.1
|
|
28
|
+
Requires-Dist: rich>=13
|
|
29
|
+
Provides-Extra: dev
|
|
30
|
+
Requires-Dist: build; extra == 'dev'
|
|
31
|
+
Requires-Dist: twine; extra == 'dev'
|
|
32
|
+
Description-Content-Type: text/markdown
|
|
33
|
+
|
|
34
|
+
# portainer-redeploy-cli
|
|
35
|
+
|
|
36
|
+
Redeploy Portainer stacks from the terminal.
|
|
37
|
+
|
|
38
|
+
When you give a version, the tool first checks that the new images exist. It pulls them through Portainer, with the registry credentials that Portainer already has. A mistyped tag therefore stops the run before the tool changes the stack. Then the tool shows the rollout live until the stack settles. If a container becomes unhealthy, the tool reports a failure.
|
|
39
|
+
|
|
40
|
+
```
|
|
41
|
+
════════════════════════════════════════════════════════════════════════════════
|
|
42
|
+
Portainer Redeploy · shop → 1.4.2 · prod
|
|
43
|
+
|
|
44
|
+
✓ Stack shop · compose · environment docker-prod
|
|
45
|
+
▶ IMAGE_TAG 1.4.1 → 1.4.2
|
|
46
|
+
|
|
47
|
+
── images
|
|
48
|
+
✓ registry.gitlab.com/acme/shop/app:1.4.2 downloaded newer image
|
|
49
|
+
✓ registry.gitlab.com/acme/shop/nginx:1.4.2 image is up to date
|
|
50
|
+
|
|
51
|
+
── rollout
|
|
52
|
+
✓ app 1/1 replaced healthy
|
|
53
|
+
- migrate 1/1 replaced exited (0)
|
|
54
|
+
✓ nginx 1/1 replaced running
|
|
55
|
+
✓ redis 0/1 replaced running
|
|
56
|
+
|
|
57
|
+
✓ Redeployed shop · 3/4 containers replaced · 3/4 running · 41s
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
## Install
|
|
61
|
+
|
|
62
|
+
```
|
|
63
|
+
pipx install portainer-redeploy-cli
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
To install from a source checkout, run `pipx install .`
|
|
67
|
+
|
|
68
|
+
The tool needs Python 3.9 or later. You can run it using the `redeploy` command.
|
|
69
|
+
|
|
70
|
+
## Usage
|
|
71
|
+
|
|
72
|
+
```
|
|
73
|
+
redeploy [options] [INSTANCE] STACK [VERSION]
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
```
|
|
77
|
+
redeploy prod shop # redeploy "shop" on the "prod" instance and pull its images again
|
|
78
|
+
redeploy prod shop 1.4.2 # the same, but set IMAGE_TAG to 1.4.2
|
|
79
|
+
redeploy shop 1.4.2 # you can omit INSTANCE when only one instance is configured
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
When you give a `VERSION`, the tool sets the stack's `IMAGE_TAG` variable to it. If the stack does not have that variable yet, the tool adds it. To set a different variable, use `tag_var` in the config file or the `PORTAINER_TAG_VAR` environment variable.
|
|
83
|
+
|
|
84
|
+
Before the redeploy, the tool checks the images:
|
|
85
|
+
|
|
86
|
+
1. It finds every image in the stack file that uses the tag variable (`IMAGE_TAG` or the variable that you set).
|
|
87
|
+
2. It expands the variables in each image name the same way compose does (`${IMAGE_TAG}-nginx`, `${REGISTRY:-…}/app:$IMAGE_TAG`, YAML anchors, …).
|
|
88
|
+
3. It pulls each image at the new version onto the stack's environment.
|
|
89
|
+
|
|
90
|
+
If a pull fails, the tool does not redeploy the stack. If the pulls pass, the redeploy has less to download.
|
|
91
|
+
|
|
92
|
+
Then the tool tells Portainer to redeploy the stack and to pull its images again. It watches the containers until the rollout settles. The rollout settles when all of these are true:
|
|
93
|
+
|
|
94
|
+
- The deploy is done.
|
|
95
|
+
- The set of containers stops changing.
|
|
96
|
+
- No container is still starting.
|
|
97
|
+
|
|
98
|
+
Services that are one-off jobs may exit.
|
|
99
|
+
|
|
100
|
+
Exit codes:
|
|
101
|
+
|
|
102
|
+
- `0`: the stack settled, and nothing failed.
|
|
103
|
+
- `1`: any failure, including unhealthy containers and timeouts.
|
|
104
|
+
- `130`: you pressed Ctrl-C.
|
|
105
|
+
|
|
106
|
+
If you press Ctrl-C after the redeploy starts, the tool only stops watching. Portainer continues the redeploy.
|
|
107
|
+
|
|
108
|
+
When the output does not go to a terminal, the tool writes plain text without colors or animation. This keeps CI logs easy to read. `NO_COLOR` also disables colors on a terminal.
|
|
109
|
+
|
|
110
|
+
## Setup
|
|
111
|
+
|
|
112
|
+
You need a Portainer API key. To create one in Portainer, go to *My account › Access tokens › Add access token*. The user of the key needs access to the stacks that you redeploy.
|
|
113
|
+
|
|
114
|
+
**One instance:** set `PORTAINER_URL` and `PORTAINER_API_KEY` in your environment.
|
|
115
|
+
|
|
116
|
+
**Several instances:** describe them in `~/.config/portainer-redeploy.json`, as in the example below. Give the instance name as the first argument.
|
|
117
|
+
|
|
118
|
+
```json
|
|
119
|
+
{
|
|
120
|
+
"prod": {
|
|
121
|
+
"url": "https://portainer.example.com",
|
|
122
|
+
"api_key_file": "/run/secrets/portainer_prod_api_key"
|
|
123
|
+
},
|
|
124
|
+
"lab": {
|
|
125
|
+
"url_file": "/run/secrets/portainer_lab_url",
|
|
126
|
+
"api_key": "ptr_…",
|
|
127
|
+
"insecure": true,
|
|
128
|
+
"tag_var": "APP_VERSION"
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
| Key | Description |
|
|
134
|
+
|---|---|
|
|
135
|
+
| `url` or `url_file` | Portainer base URL, or a file that contains it |
|
|
136
|
+
| `api_key` or `api_key_file` | API key, or a file that contains it. A file keeps the key out of the config file and out of your shell's environment. It also works with sops-nix, agenix, Docker secrets and similar tools |
|
|
137
|
+
| `insecure` | `true` skips TLS certificate verification. Use it for instances with self-signed certificates on a network that you trust |
|
|
138
|
+
| `tag_var` | Stack variable that the tool sets to `VERSION` on this instance (default: `IMAGE_TAG`) |
|
|
139
|
+
|
|
140
|
+
The tool always reads a named instance from the config file. If you do not name an instance, the tool uses `PORTAINER_URL` when it is set. Otherwise, it uses the only instance in the config file.
|
|
141
|
+
|
|
142
|
+
## Options
|
|
143
|
+
|
|
144
|
+
| Option | Description |
|
|
145
|
+
|---|---|
|
|
146
|
+
| `-i`, `--instance NAME` | Instance from the config file. This is the same as giving the instance as the first argument |
|
|
147
|
+
| `-E`, `--environment NAME\|ID` | Portainer environment that has the stack. Use it when stacks in several environments have the same name |
|
|
148
|
+
| `--timeout SECONDS` | How long to wait for the rollout to settle (default: `600`) |
|
|
149
|
+
| `-k`, `--insecure` | Skip TLS certificate verification |
|
|
150
|
+
|
|
151
|
+
## Environment variables
|
|
152
|
+
|
|
153
|
+
| Variable | Description |
|
|
154
|
+
|---|---|
|
|
155
|
+
| `PORTAINER_URL` | Portainer base URL. The tool uses it when you do not name an instance |
|
|
156
|
+
| `PORTAINER_API_KEY` | API key for `PORTAINER_URL` |
|
|
157
|
+
| `PORTAINER_INSECURE` | `1` skips TLS certificate verification for `PORTAINER_URL` |
|
|
158
|
+
| `PORTAINER_TAG_VAR` | Stack variable that the tool sets to `VERSION` for `PORTAINER_URL` (default: `IMAGE_TAG`) |
|
|
159
|
+
| `PORTAINER_REDEPLOY_CONFIG` | Config file to use instead of `~/.config/portainer-redeploy.json` |
|
|
160
|
+
| `NO_COLOR` | Disables colors |
|
|
161
|
+
|
|
162
|
+
## Compatibility
|
|
163
|
+
|
|
164
|
+
The tool works with Portainer CE and BE 2.x. It supports compose and swarm stacks, both file-based stacks and stacks from git. The tool does not support Kubernetes stacks.
|
|
165
|
+
|
|
166
|
+
For git stacks, the tool uses Portainer's git redeploy, so the stacks stay linked to their repository. The git redeploy pulls the latest commit of the stack's branch.
|
|
167
|
+
|
|
168
|
+
Portainer 2.36 and later deploy in the background. The tool follows the deploy status. If the deploy fails, the tool shows the error from Portainer. Older versions of Portainer reply only when the deploy is done. If a reverse proxy in front of Portainer stops waiting for such a long request, the tool still follows the deploy.
|
|
169
|
+
|
|
170
|
+
## License
|
|
171
|
+
|
|
172
|
+
AGPLv3
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
portainer_redeploy_cli/__init__.py,sha256=kUR5RAFc7HCeiqdlX36dZOHkUI5wI6V_43RpEcD8b-0,22
|
|
2
|
+
portainer_redeploy_cli/__main__.py,sha256=dl5qNYKzOrIg_AKVd0i6pfTCQwarxp-Y9859pXcmGXU,43059
|
|
3
|
+
portainer_redeploy_cli-0.1.0.dist-info/METADATA,sha256=NaXAb7f_SzmGA33Fg8d7x9RP4e8yZXgwXM0c8-7OivA,7862
|
|
4
|
+
portainer_redeploy_cli-0.1.0.dist-info/WHEEL,sha256=W3fkpkm7-wf9vBI5Z-7s0eWkeM-spu78I8Neb98DeEg,87
|
|
5
|
+
portainer_redeploy_cli-0.1.0.dist-info/entry_points.txt,sha256=2CwPIhe5gEKaiEy4jYj0pLriq4zUP002cJzj8dzc2to,66
|
|
6
|
+
portainer_redeploy_cli-0.1.0.dist-info/licenses/LICENSE,sha256=VyavO10BwYKbJpi3BZogRALKoteKMVxYcQdR9EjgqHw,34524
|
|
7
|
+
portainer_redeploy_cli-0.1.0.dist-info/RECORD,,
|