CleverCloud / doc.clever-cloud.com-comments

Repository to collect comments of our documentation website
https://www.clever-cloud.com/doc/
1 stars 0 forks source link

Application creation with Clever Tools | Clever Cloud Documentation #2

Open utterances-bot opened 3 years ago

utterances-bot commented 3 years ago

Application creation with Clever Tools | Clever Cloud Documentation

https://www.clever-cloud.com/doc/reference/clever-tools/create/

Jean-Baptiste-Lasselle commented 3 years ago

Hi, maybe the feature is already implemented, if not, I think would be very valuable :

GNU option to set on which git branch Clever Cloud is listening, to trigger deployment by git pushing a new commit

This way it is possible to fully provision a component non-interactively (into a pipeline)

gaelreyrol commented 3 years ago

Hi, maybe the feature is already implemented, if not, I think would be very valuable :

GNU option to set on which git branch Clever Cloud is listening, to trigger deployment by git pushing a new commit

This way it is possible to fully provision a component non-interactively (into a pipeline)

Hi @Jean-Baptiste-Lasselle, are you referring to Github application creation ?

tancredesimonin commented 2 years ago

Seems there is a typo issue on the --GitHub flag, at least on windows, with the Windows Terminal only works with lowercase as:

```sh
clever create --type <type> <app-name> --region <zone> --alias <alias> --github <owner>/<repository>
gervaisb commented 11 months ago

(No idea where to put it)

If, for any reason, you need to deploy with git push instead of clever deploy you may want to wait for the deployment to complete. Based on the idea of Raul Archer, I was able to build a function that can be used right after your push:

$ git push clever HEAD:master --tags
$ bash -c "source clever-cloud.sh; clever-cloud_poll_for_deployment_completion ${COMMIT_SHA}"
#!/bin/bash
set -eu

RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[0;33m'
GRAY='\033[0;90m'
RESET='\033[0m'

# Poll the application activity for a completed deployment.
# This function will run indefinitely until a deployment for a specific commit
# is completed. A deployment may be completed when the status is "OK", "FAIL" or
# "CANCELLED". When the deployment is completed the function exit with a code
# matching the status (0:OK, 1:FAIL, 2:CANCELLED).
# A successful deployment will also try to print the application status for
# information.
#
# Parameters
# 1. The commit being deployed. Should be the full commit hash.
#
# This function require the Clever Tools CLI (https://www.clever-cloud.com/doc/reference/clever-tools/)
function clever-cloud_poll_for_deployment_completion() {
  local commit="$1"

  while true; do
    # 'clever activity' show last deployments of the application. Oldest first.
    # We can extract the deployment status for the current commit by getting the
    # last line matching this commit. Credit to Raul Archer from clever-cloud.com
    status=$(clever activity | grep "$commit" | tail -n1 | awk '{print $2}')
    if [[ "$status" == *"OK"* ]]; then
      echo -e "\n${GREEN}Deployment completed successfully.${RESET}"
      (clever status | head -n 1) || true
      exit 0
    elif [[ "$status" == *"FAIL"* ]]; then
      echo -e "\n${RED}Deployment failed.${RESET}"
      echo "Go to the console for more details: https://console.clever-cloud.com/"
      exit 1
    elif [[ "$status" == *"CANCELLED"* ]]; then
      echo -e "\n${YELLOW}Deployment has been cancelled.${RESET}"
      exit 2
    else
      echo -en "${GRAY}..${RESET}"
      # Get a random delay between 0 and 5
      sleep $((RANDOM % 6))
    fi
  done
}