koyeb / koyeb-cli

Koyeb cli
Apache License 2.0
56 stars 29 forks source link

Add `--git-sha` to specify the sha to deploy #222

Closed brmzkw closed 4 months ago

brmzkw commented 4 months ago

The API endpoint PUT /v1/services/{id} takes a DeploymentDefinition object as input. For git sources, this project has an optional attribute "git.sha". If this parameter is not provided, the API creates a deployment with the latest commit of the branch. If the parameter is provided, the API creates a deployment with the commit specified by the parameter.

When a service is configured to automatically deploy when a new commit is pushed to GitHub, the hook creates a deployment with the "git.sha" attribute set to the commit of the push.

Currently, to update a service with the CLI (for example to update an environment variable), the command koyeb service update <app>/<service> creates a new deployment and resets the "git.sha" attribute, which causes the deployment to be created with the latest commit of the branch. Instead, the CLI should preserve the "git.sha" attribute if it is present in the existing deployment, and only reset it if the --git-sha flag is provided.

To avoid confusion, a warning message should be displayed if the --git-sha flag is not provided and the "git.sha" attribute is present in the existing deployment. This message could be:

"Warning: you are updating the service without specifying a commit with the --git-sha flag, and the service is currently deployed with a specific commit. The commit is being used for the deployment. If you want to deploy the latest commit of the branch instead, use --git-sha ''."

Use case 1

  1. A service is created from the control panel with the flag "deploy on push"
  2. The service has an empty "git.sha" attribute
  3. The user pushes a new commit to the GitHub repository, which triggers a deployment with the "git.sha" attribute set to the new commit
  4. The user runs the command koyeb service update <app>/<service> without the --git-sha flag. A warning message is displayed, and the same commit as the previous deployment is used for the new deployment.

Use case 2

  1. A service is created from the control panel with the flag "deploy on push"
  2. The service has an empty "git.sha" attribute
  3. The user pushes a new commit to the GitHub repository, which triggers a deployment with the "git.sha" attribute set to the new commit
  4. The user runs the command koyeb service update <app>/<service> with the --git-sha flag. This specific commit is used for the new deployment.

Use case 3

  1. A service is created from the control panel without the flag "deploy on push"
  2. The service has an empty "git.sha" attribute
  3. The user runs the command koyeb service update <app>/<service> without the --git-sha flag. The latest commit of the branch is used for the new deployment.

Use case 4

  1. A service is created from the control panel without the flag "deploy on push"
  2. The service has an empty "git.sha" attribute
  3. The user runs the command koyeb service update <app>/<service> with the --git-sha flag. This specific commit is used for the new deployment.
  4. The user runs the command koyeb service update <app>/<service> without the --git-sha flag. A warning message is displayed, and the same commit as the previous deployment is used for the new deployment.