2
0

deploy.go 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. package client
  2. import (
  3. "context"
  4. "fmt"
  5. "github.com/porter-dev/porter/api/types"
  6. )
  7. // GetReleaseWebhook retrieves the release webhook for a given release
  8. func (c *Client) GetReleaseWebhook(
  9. ctx context.Context,
  10. projID, clusterID uint,
  11. name, namespace string,
  12. ) (*types.PorterRelease, error) {
  13. resp := &types.PorterRelease{}
  14. err := c.getRequest(
  15. fmt.Sprintf(
  16. "/projects/%d/clusters/%d/namespaces/%s/releases/%s/webhook",
  17. projID,
  18. clusterID,
  19. namespace,
  20. name,
  21. ),
  22. nil,
  23. resp,
  24. )
  25. return resp, err
  26. }
  27. // DeployWithWebhook deploys an application with an image tag using a unique webhook URI
  28. func (c *Client) DeployWithWebhook(
  29. ctx context.Context,
  30. webhook string,
  31. req *types.WebhookRequest,
  32. ) error {
  33. return c.postRequest(
  34. fmt.Sprintf(
  35. "/webhooks/deploy/%s",
  36. webhook,
  37. ),
  38. req,
  39. nil,
  40. )
  41. }
  42. // UpdateBatchImage updates all releases that use a certain image with a new tag,
  43. // within a single namespace
  44. func (c *Client) UpdateBatchImage(
  45. ctx context.Context,
  46. projID, clusterID uint,
  47. namespace string,
  48. req *types.UpdateImageBatchRequest,
  49. ) error {
  50. return c.postRequest(
  51. fmt.Sprintf("/projects/%d/clusters/%d/namespaces/%s/releases/image/batch", projID, clusterID, namespace),
  52. req,
  53. nil,
  54. )
  55. }
  56. func (c *Client) DeployTemplate(
  57. ctx context.Context,
  58. projID, clusterID uint,
  59. namespace string,
  60. req *types.CreateReleaseRequest,
  61. ) error {
  62. return c.postRequest(
  63. fmt.Sprintf("/projects/%d/clusters/%d/namespaces/%s/releases", projID, clusterID, namespace),
  64. req,
  65. nil,
  66. )
  67. }
  68. func (c *Client) DeployAddon(
  69. ctx context.Context,
  70. projID, clusterID uint,
  71. namespace string,
  72. req *types.CreateAddonRequest,
  73. ) error {
  74. return c.postRequest(
  75. fmt.Sprintf("/projects/%d/clusters/%d/namespaces/%s/addons", projID, clusterID, namespace),
  76. req,
  77. nil,
  78. )
  79. }
  80. // UpgradeRelease upgrades a specific release with new values or chart version
  81. func (c *Client) UpgradeRelease(
  82. ctx context.Context,
  83. projID, clusterID uint,
  84. namespace, name string,
  85. req *types.UpgradeReleaseRequest,
  86. ) error {
  87. return c.postRequest(
  88. fmt.Sprintf(
  89. "/projects/%d/clusters/%d/namespaces/%s/releases/%s/0/upgrade",
  90. projID, clusterID,
  91. namespace, name,
  92. ),
  93. req,
  94. nil,
  95. postRequestOpts{
  96. retryCount: 3,
  97. },
  98. )
  99. }
  100. // DeleteRelease deletes a Porter release
  101. func (c *Client) DeleteRelease(
  102. ctx context.Context,
  103. projID, clusterID uint,
  104. namespace, name string,
  105. ) error {
  106. return c.deleteRequest(
  107. fmt.Sprintf(
  108. "/projects/%d/clusters/%d/namespaces/%s/releases/%s/0",
  109. projID, clusterID,
  110. namespace, name,
  111. ),
  112. nil,
  113. nil,
  114. )
  115. }