peak-sdk 1.6.0__py3-none-any.whl → 1.7.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.
Files changed (41) hide show
  1. peak/_metadata.py +22 -2
  2. peak/_version.py +1 -1
  3. peak/cli/args.py +1 -0
  4. peak/cli/press/apps/specs.py +2 -0
  5. peak/cli/press/blocks/specs.py +66 -22
  6. peak/cli/press/deployments.py +41 -0
  7. peak/cli/resources/images.py +18 -6
  8. peak/cli/resources/tenants.py +4 -1
  9. peak/cli/resources/workflows.py +12 -12
  10. peak/press/apps.py +10 -3
  11. peak/press/blocks.py +388 -139
  12. peak/press/deployments.py +28 -0
  13. peak/resources/images.py +309 -86
  14. peak/sample_yaml/press/apps/specs/create_app_spec.yaml +2 -0
  15. peak/sample_yaml/press/apps/specs/create_app_spec_release.yaml +2 -0
  16. peak/sample_yaml/press/blocks/specs/service/api/create_block_spec.yaml +102 -0
  17. peak/sample_yaml/press/blocks/specs/service/api/create_block_spec_release.yaml +88 -0
  18. peak/sample_yaml/press/blocks/specs/service/webapp/create_block_spec.yaml +103 -0
  19. peak/sample_yaml/press/blocks/specs/service/webapp/create_block_spec_release.yaml +89 -0
  20. peak/sample_yaml/press/blocks/specs/{create_block_spec.yaml → workflow/create_block_spec.yaml} +20 -1
  21. peak/sample_yaml/press/blocks/specs/{create_block_spec_release.yaml → workflow/create_block_spec_release.yaml} +20 -1
  22. peak/sample_yaml/resources/images/dockerfile/create_image.yaml +3 -0
  23. peak/sample_yaml/resources/images/dockerfile/create_image_version.yaml +3 -0
  24. peak/sample_yaml/resources/images/dockerfile/update_version.yaml +3 -0
  25. peak/sample_yaml/resources/images/github/create_image.yaml +3 -0
  26. peak/sample_yaml/resources/images/github/create_image_version.yaml +3 -0
  27. peak/sample_yaml/resources/images/github/update_version.yaml +3 -0
  28. peak/sample_yaml/resources/images/upload/create_image.yaml +3 -0
  29. peak/sample_yaml/resources/images/upload/create_image_version.yaml +3 -0
  30. peak/sample_yaml/resources/images/upload/create_or_update_image.yaml +3 -0
  31. peak/sample_yaml/resources/images/upload/update_version.yaml +3 -0
  32. peak/sample_yaml/resources/workflows/create_or_update_workflow.yaml +9 -1
  33. peak/sample_yaml/resources/workflows/create_workflow.yaml +9 -1
  34. peak/sample_yaml/resources/workflows/patch_workflow.yaml +9 -1
  35. peak/sample_yaml/resources/workflows/update_workflow.yaml +9 -1
  36. peak/session.py +1 -1
  37. {peak_sdk-1.6.0.dist-info → peak_sdk-1.7.0.dist-info}/METADATA +14 -14
  38. {peak_sdk-1.6.0.dist-info → peak_sdk-1.7.0.dist-info}/RECORD +41 -37
  39. {peak_sdk-1.6.0.dist-info → peak_sdk-1.7.0.dist-info}/LICENSE +0 -0
  40. {peak_sdk-1.6.0.dist-info → peak_sdk-1.7.0.dist-info}/WHEEL +0 -0
  41. {peak_sdk-1.6.0.dist-info → peak_sdk-1.7.0.dist-info}/entry_points.txt +0 -0
peak/press/blocks.py CHANGED
@@ -19,6 +19,7 @@
19
19
  # # along with this program. If not, see <https://apache.org/licenses/LICENSE-2.0>
20
20
  #
21
21
  """Blocks client module."""
22
+
22
23
  from __future__ import annotations
23
24
 
24
25
  import json
@@ -152,6 +153,7 @@ class Block(BaseClient):
152
153
  scope: Optional[str] = None,
153
154
  tenants: Optional[List[str]] = None,
154
155
  parameters: Optional[Dict[str, List[Dict[str, Any]]]] = None,
156
+ auto_run_on_deploy: Optional[bool] = None,
155
157
  ) -> Dict[str, str]:
156
158
  """Create a new Block spec.
157
159
 
@@ -171,101 +173,228 @@ class Block(BaseClient):
171
173
  and `shared` allows specifying what set of tenants can access and use this spec.
172
174
  By default it is `private`.
173
175
  tenants (List[str] | None): Given a shared scope, specify what other tenants can discover and deploy this spec.
174
- parameters (Optional[Dict[str, List[Dict[str, Any]]]]): A dictionary containing optional keys 'build' and 'run'.
175
- The structure of the dictionary is as follows:
176
- - 'build' (List[Dict[str, Any]], optional): A list of parameter objects, the values of which will be given and used at deployment time
177
- - 'run' (List[Dict[str, Any]], optional): A list of parameter objects, the values of which will be given at deployment time and will be used at run time
178
- The dictionary can have one or both of these keys.
176
+ parameters (Optional[Dict[str, List[Dict[str, Any]]]]): A dictionary containing optional keys `build` and `run`. The structure of the dictionary is as follows:
177
+
178
+ - `build` (List[Dict[str, Any]], optional): A list of parameter objects, the values of which will be given and used at deployment time.
179
+ - `run` (List[Dict[str, Any]], optional): A list of parameter objects, the values of which will be given at deployment time and will be used at run time.
180
+ auto_run_on_deploy (bool | None): Whether to execute the resource after the block is deployed. By default it is False.
179
181
 
180
182
  Returns:
181
183
  Dict[str, str]: Id of the created block spec.
182
184
 
183
- SCHEMA(body):
184
- .. code-block:: json
185
+ SCHEMA (body):
186
+ Information about providing image details in blocks can be found `here <https://docs.peak.ai/sdk/latest/snippets/press-examples.html#providing-image-details-for-block-specs>`__.
185
187
 
186
- {
187
- "version": "number(required)",
188
- "kind": "string(required)",
189
- "metadata": {
190
- "name": "string(required)",
191
- "title": "string",
192
- "summary": "string(required)",
193
- "description": "string",
194
- "descriptionContentType": "string",
195
- "imageUrl": "string",
196
- "tags": [
197
- {
198
- "name": "string",
199
- }
200
- ]
201
- },
202
- "release": {
203
- "notes": "string(required)",
204
- "version": "string(required)",
205
- },
206
- "config": {
207
- "images": {
208
- "image-name": {
209
- "version": "string",
210
- "dockerfile": "string",
211
- "context": "string",
212
- "useCache": "string",
213
- "buildArguments": {
214
- "key (string)": "value (string)"
188
+ .. tabs::
189
+
190
+ .. tab:: Workflow Block Spec
191
+
192
+ .. code-block:: json
193
+
194
+ {
195
+ "version": "number(required)",
196
+ "kind": "string(required)",
197
+ "metadata": {
198
+ "name": "string(required)",
199
+ "title": "string",
200
+ "summary": "string(required)",
201
+ "description": "string",
202
+ "descriptionContentType": "string",
203
+ "imageUrl": "string",
204
+ "tags": [
205
+ {
206
+ "name": "string",
207
+ }
208
+ ]
209
+ },
210
+ "release": {
211
+ "notes": "string",
212
+ "version": "string (required)",
213
+ },
214
+ "config": {
215
+ "images": {
216
+ "image-name": {
217
+ "version": "string",
218
+ "dockerfile": "string",
219
+ "context": "string",
220
+ "useCache": "boolean",
221
+ "buildArguments": {
222
+ "key (string)": "value (string)"
223
+ },
224
+ }
215
225
  },
226
+ "steps": {
227
+ "stepName": {
228
+ "type": "string",
229
+ "image": {
230
+ "version": "string",
231
+ "dockerfile": "string",
232
+ "context": "string",
233
+ "useCache": "boolean",
234
+ "buildArguments": {
235
+ "key (string)": "value (string)"
236
+ },
237
+ "secrets": []
238
+ }
239
+ "imageRef": "string",
240
+ "imageDetails": {
241
+ "id": "number (required)",
242
+ "versionId": "number"
243
+ },
244
+ "command": "string (required)",
245
+ "resources": {
246
+ "instanceTypeId": "number",
247
+ "storage": "string"
248
+ },
249
+ "parents": [],
250
+ "stepTimeout": "number",
251
+ "clearImageCache": "boolean",
252
+ "repository": {
253
+ "branch": "string",
254
+ "token": "string",
255
+ "url": "string"
256
+ },
257
+ "runConfiguration": {
258
+ "retryOptions": {
259
+ "duration": "number",
260
+ "exitCodes": [],
261
+ "exponentialBackoff": "boolean",
262
+ "numberOfRetries": "number"
263
+ },
264
+ "skipConfiguration": {
265
+ "skip": "boolean",
266
+ "skipDAG": "boolean",
267
+ }
268
+ },
269
+ "parameters": {
270
+ "env": {
271
+ "key (string)": "value (string)"
272
+ },
273
+ "secrets": [],
274
+ },
275
+ "outputParameters": {
276
+ "key (string)": "value (string)"
277
+ },
278
+ "executionParameters": {
279
+ "conditional": [
280
+ {
281
+ "condition": "string",
282
+ "paramName": "string",
283
+ "stepName": "string",
284
+ "value": "string"
285
+ }
286
+ ],
287
+ "parentStatus": [
288
+ {
289
+ "condition": "string",
290
+ "parents": [],
291
+ "status": []
292
+ }
293
+ ]
294
+ }
295
+ }
296
+ },
297
+ "triggers": [
298
+ {
299
+ "cron": "string"
300
+ },
301
+ {
302
+ "webhook": "boolean"
303
+ },
304
+ ],
305
+ "watchers": [
306
+ {
307
+ "events": {
308
+ "success": "boolean",
309
+ "fail": "boolean",
310
+ "runtimeExceeded": "number"
311
+ },
312
+ "user": "string",
313
+ },
314
+ {
315
+ "events": {
316
+ "success": "boolean",
317
+ "fail": "boolean",
318
+ "runtimeExceeded": "number"
319
+ },
320
+ "webhook": {
321
+ "name": "string(required)",
322
+ "url": "string(required)",
323
+ "payload": "string(required)"
324
+ }
325
+ },
326
+ {
327
+ "events": {
328
+ "success": "boolean",
329
+ "fail": "boolean",
330
+ "runtimeExceeded": "number"
331
+ },
332
+ "email": {
333
+ "name": "string",
334
+ "recipients": {
335
+ "to": ["string"]
336
+ }
337
+ }
338
+ }
339
+ ],
216
340
  }
217
- },
218
- "steps": {
219
- "stepName": {
220
- "type": "string",
221
- "imageId": "number",
222
- "imageVersionId": "number",
223
- "command": "string",
341
+ }
342
+
343
+ .. tab:: Service Block Spec
344
+
345
+ .. code-block:: json
346
+
347
+ {
348
+ "version": "number(required)",
349
+ "kind": "string(required)",
350
+ "metadata": {
351
+ "name": "string(required)",
352
+ "title": "string",
353
+ "summary": "string(required)",
354
+ "description": "string",
355
+ "descriptionContentType": "string",
356
+ "imageUrl": "string",
357
+ "tags": [
358
+ {
359
+ "name": "string",
360
+ }
361
+ ]
362
+ },
363
+ "release": {
364
+ "notes": "string",
365
+ "version": "string (required)",
366
+ },
367
+ "config": {
368
+ "serviceType": "string",
369
+ "image": {
370
+ "version": "string",
371
+ "dockerfile": "string",
372
+ "context": "string",
373
+ "useCache": "boolean",
374
+ "buildArguments": {
375
+ "key (string)": "value (string)"
376
+ },
377
+ "secrets": []
378
+ },
379
+ "imageDetails": {
380
+ "id": "number (required)",
381
+ "versionId": "number"
382
+ },
224
383
  "resources": {
225
- "instanceTypeId": "number",
226
- "storage": "string"
384
+ "instanceTypeId": "number (required)",
227
385
  },
228
- "parents": [],
229
- "stepTimeout": "number",
230
- "clearImageCache": "boolean",
231
386
  "parameters": {
232
387
  "env": {
233
388
  "key (string)": "value (string)"
234
389
  },
235
- "secrets": [],
390
+ "secrets": []
236
391
  },
237
- "repository": {
238
- "branch": "string",
239
- "token": "string",
240
- "url": "string"
241
- }
392
+ "sessionStickiness": "boolean (only for web-app service)",
393
+ "entrypoint": "string",
394
+ "healthCheckURL": "string",
395
+ "minInstances": "number. Default is 1 and maximum is 2",
242
396
  }
243
397
  }
244
- "triggers": [
245
- {
246
- "cron": "string"
247
- },
248
- {
249
- "webhook": "boolean"
250
- },
251
- ],
252
- "watchers": [
253
- {
254
- "events": {
255
- "success": "boolean",
256
- "fail": "boolean",
257
- "runtimeExceeded": "number"
258
- },
259
- "user": "string",
260
- "webhook": {
261
- "name": "string(required)",
262
- "url": "string(required)",
263
- "payload": "string(required)",
264
- }
265
- }
266
- ],
267
- }
268
- }
269
398
 
270
399
  SCHEMA(Parameters):
271
400
  .. code-block:: json
@@ -309,6 +438,7 @@ class Block(BaseClient):
309
438
  "spec": json.dumps(body),
310
439
  "featured": json.dumps(featured),
311
440
  "scope": scope,
441
+ "autoRunOnDeploy": json.dumps(auto_run_on_deploy),
312
442
  }
313
443
 
314
444
  if tenants:
@@ -454,6 +584,7 @@ class Block(BaseClient):
454
584
  body: Dict[str, Any],
455
585
  artifact: Optional[ArtifactInfo] = None,
456
586
  parameters: Optional[Dict[str, List[Dict[str, Any]]]] = None,
587
+ auto_run_on_deploy: Optional[bool] = None,
457
588
  ) -> Dict[str, str]:
458
589
  """Publish a new release to an existing Block spec.
459
590
 
@@ -466,81 +597,198 @@ class Block(BaseClient):
466
597
  artifact (ArtifactInfo | None): Mapping of artifact attributes that specifies how the artifact will be generated,
467
598
  it accepts two keys `path`, which is required and `ignore_files` which is optional, and defaults to `.dockerignore`, it is strongly advised that users use `ignore_files` when generating artifacts to avoid copying any extra files in artifact.
468
599
  It is not required if an existing image and version is used for creating the spec.
469
- parameters (Optional[Dict[str, List[Dict[str, Any]]]]): A dictionary containing optional keys 'build' and 'run'.
470
- The structure of the dictionary is as follows:
471
- - 'build' (List[Dict[str, Any]], optional): A list of parameter objects, the values of which will be given and used at deployment time
472
- - 'run' (List[Dict[str, Any]], optional): A list of parameter objects, the values of which will be given at deployment time and will be used at run time
600
+ parameters (Optional[Dict[str, List[Dict[str, Any]]]]): A dictionary containing optional keys `build` and `run`. The structure of the dictionary is as follows:
601
+
602
+ - `build` (List[Dict[str, Any]], optional): A list of parameter objects, the values of which will be given and used at deployment time.
603
+ - `run` (List[Dict[str, Any]], optional): A list of parameter objects, the values of which will be given at deployment time and will be used at run time.
604
+ auto_run_on_deploy (bool | None): Whether to execute the resource after the block is deployed. By default it is False.
473
605
 
474
606
  Returns:
475
- Dict[str, str]: Dictionary containing spec id and release version
607
+ Dict[str, str]: Dictionary containing spec id and release version.
476
608
 
477
- SCHEMA:
478
- .. code-block:: json
609
+ SCHEMA (body):
610
+ Information about providing image details in blocks can be found `here <https://docs.peak.ai/sdk/latest/snippets/press-examples.html#providing-image-details-for-block-specs>`__.
479
611
 
480
- {
481
- "config": {
482
- "images": {
483
- "image-name": {
484
- "version": "string",
485
- "dockerfile": "string",
486
- "context": "string",
487
- "useCache": "string",
488
- "buildArguments": {
489
- "key (string)": "value (string)"
612
+ .. tabs::
613
+
614
+ .. tab:: Workflow Block Spec
615
+
616
+ .. code-block:: json
617
+
618
+ {
619
+ "release": {
620
+ "notes": "string",
621
+ "version": "string (required)",
622
+ },
623
+ "config": {
624
+ "images": {
625
+ "image-name": {
626
+ "version": "string",
627
+ "dockerfile": "string",
628
+ "context": "string",
629
+ "useCache": "boolean",
630
+ "buildArguments": {
631
+ "key (string)": "value (string)"
632
+ },
633
+ }
634
+ },
635
+ "steps": {
636
+ "stepName": {
637
+ "type": "string",
638
+ "image": {
639
+ "version": "string",
640
+ "dockerfile": "string",
641
+ "context": "string",
642
+ "useCache": "boolean",
643
+ "buildArguments": {
644
+ "key (string)": "value (string)"
645
+ },
646
+ "secrets": []
647
+ }
648
+ "imageRef": "string",
649
+ "imageDetails": {
650
+ "id": "number (required)",
651
+ "versionId": "number"
652
+ },
653
+ "command": "string (required)",
654
+ "resources": {
655
+ "instanceTypeId": "number",
656
+ "storage": "string"
657
+ },
658
+ "parents": [],
659
+ "stepTimeout": "number",
660
+ "clearImageCache": "boolean",
661
+ "repository": {
662
+ "branch": "string",
663
+ "token": "string",
664
+ "url": "string"
665
+ },
666
+ "runConfiguration": {
667
+ "retryOptions": {
668
+ "duration": "number",
669
+ "exitCodes": [],
670
+ "exponentialBackoff": "boolean",
671
+ "numberOfRetries": "number"
672
+ },
673
+ "skipConfiguration": {
674
+ "skip": "boolean",
675
+ "skipDAG": "boolean",
676
+ }
677
+ },
678
+ "parameters": {
679
+ "env": {
680
+ "key (string)": "value (string)"
681
+ },
682
+ "secrets": [],
683
+ },
684
+ "outputParameters": {
685
+ "key (string)": "value (string)"
686
+ },
687
+ "executionParameters": {
688
+ "conditional": [
689
+ {
690
+ "condition": "string",
691
+ "paramName": "string",
692
+ "stepName": "string",
693
+ "value": "string"
694
+ }
695
+ ],
696
+ "parentStatus": [
697
+ {
698
+ "condition": "string",
699
+ "parents": [],
700
+ "status": []
701
+ }
702
+ ]
703
+ }
704
+ }
490
705
  },
706
+ "triggers": [
707
+ {
708
+ "cron": "string"
709
+ },
710
+ {
711
+ "webhook": "boolean"
712
+ }
713
+ ],
714
+ "watchers": [
715
+ {
716
+ "events": {
717
+ "success": "boolean",
718
+ "fail": "boolean",
719
+ "runtimeExceeded": "number"
720
+ },
721
+ "user": "string",
722
+ },
723
+ {
724
+ "events": {
725
+ "success": "boolean",
726
+ "fail": "boolean",
727
+ "runtimeExceeded": "number"
728
+ },
729
+ "webhook": {
730
+ "name": "string(required)",
731
+ "url": "string(required)",
732
+ "payload": "string(required)"
733
+ }
734
+ },
735
+ {
736
+ "events": {
737
+ "success": "boolean",
738
+ "fail": "boolean",
739
+ "runtimeExceeded": "number"
740
+ },
741
+ "email": {
742
+ "name": "string",
743
+ "recipients": {
744
+ "to": ["string"]
745
+ }
746
+ }
747
+ }
748
+ ],
491
749
  }
492
- },
493
- "steps": {
494
- "stepName": {
495
- "type": "string",
496
- "imageId": "number",
497
- "imageVersionId": "number",
498
- "command": "string",
750
+ }
751
+
752
+ .. tab:: Service Block Spec
753
+
754
+ .. code-block:: json
755
+
756
+ {
757
+ "release": {
758
+ "notes": "string",
759
+ "version": "string (required)",
760
+ },
761
+ "config": {
762
+ "serviceType": "string",
763
+ "image": {
764
+ "version": "string",
765
+ "dockerfile": "string",
766
+ "context": "string",
767
+ "useCache": "boolean",
768
+ "buildArguments": {
769
+ "key (string)": "value (string)"
770
+ },
771
+ "secrets": []
772
+ },
773
+ "imageDetails": {
774
+ "id": "number (required)",
775
+ "versionId": "number"
776
+ },
499
777
  "resources": {
500
- "instanceTypeId": "number",
501
- "storage": "string"
778
+ "instanceTypeId": "number (required)",
502
779
  },
503
- "parents": [],
504
- "stepTimeout": "number",
505
- "clearImageCache": "boolean",
506
780
  "parameters": {
507
781
  "env": {
508
782
  "key (string)": "value (string)"
509
783
  },
510
- "secrets": [],
784
+ "secrets": []
511
785
  },
512
- "repository": {
513
- "branch": "string",
514
- "token": "string",
515
- "url": "string"
516
- }
786
+ "sessionStickiness": "boolean (only for web-app service)",
787
+ "entrypoint": "string",
788
+ "healthCheckURL": "string",
789
+ "minInstances": "number. Default is 1 and maximum is 2",
517
790
  }
518
791
  }
519
- "triggers": [
520
- {
521
- "cron": "string"
522
- },
523
- {
524
- "webhook": "boolean"
525
- }
526
- ],
527
- "watchers": [
528
- {
529
- "events": {
530
- "success": "boolean",
531
- "fail": "boolean",
532
- "runtimeExceeded": "number"
533
- },
534
- "user": "string",
535
- "webhook": {
536
- "name": "string(required)",
537
- "url": "string(required)",
538
- "payload": "string(required)",
539
- }
540
- }
541
- ],
542
- }
543
- }
544
792
 
545
793
  Raises:
546
794
  BadRequestException: The given parameters are invalid.
@@ -556,6 +804,7 @@ class Block(BaseClient):
556
804
 
557
805
  request_body = {
558
806
  "spec": json.dumps(body),
807
+ "autoRunOnDeploy": json.dumps(auto_run_on_deploy),
559
808
  }
560
809
 
561
810
  if parameters:
peak/press/deployments.py CHANGED
@@ -19,6 +19,7 @@
19
19
  # # along with this program. If not, see <https://apache.org/licenses/LICENSE-2.0>
20
20
  #
21
21
  """Deployments client module."""
22
+
22
23
  from __future__ import annotations
23
24
 
24
25
  from typing import Any, Dict, Iterator, List, Literal, Optional, overload
@@ -128,6 +129,33 @@ class Deployment(BaseClient):
128
129
  subdomain="press",
129
130
  )
130
131
 
132
+ def execute_resources(self, deployment_id: str) -> Dict[str, Any]:
133
+ """Trigger the resources of an app or block deployment. This will execute the resources of the latest revision of the deployment.
134
+
135
+ REFERENCE:
136
+ 🔗 `API Documentation <https://press.peak.ai/api-docs/index.htm#/Deployments/post_v1_deployments__deploymentId__trigger>`__
137
+
138
+ Args:
139
+ deployment_id (str): ID of the app or block deployment to trigger resources for.
140
+
141
+ Returns:
142
+ Dict[str, Any]: A dictionary containing the details of the triggered deployment.
143
+
144
+ Raises:
145
+ BadRequestException: The given parameters are invalid.
146
+ UnauthorizedException: The credentials are invalid.
147
+ ForbiddenException: The user does not have permission to perform the operation.
148
+ InternalServerErrorException: The server encountered an unexpected condition that
149
+ prevented it from fulfilling the request.
150
+ """
151
+ method, endpoint = HttpMethods.POST, f"{self.BASE_ENDPOINT}/{deployment_id}/execute"
152
+ return self.session.create_request( # type: ignore[no-any-return]
153
+ endpoint,
154
+ method,
155
+ content_type=ContentType.APPLICATION_JSON,
156
+ subdomain="press",
157
+ )
158
+
131
159
 
132
160
  def get_client(session: Optional[Session] = None) -> Deployment:
133
161
  """Returns a Deployment client.