Commit 178b688a authored by Clement Bois's avatar Clement Bois
Browse files

feat: support rolling strategy

parent 96f72950
Loading
Loading
Loading
Loading
+19 −0
Original line number Diff line number Diff line
@@ -95,6 +95,7 @@ The Cloud Foundry template uses some global configuration used throughout all jo
| `default-route-path` / `CF_DEFAULT_ROUTE_PATH` | Default CF route path                  | _none_ |
| `default-push-args` / `CF_DEFAULT_PUSH_ARGS`   | Additional arguments for cf push command _(only define if you want has a specific need not med by the template)_ | _none_ |
| `scripts-dir` / `CF_SCRIPTS_DIR`               | Directory where CF scripts (manifest, hook scripts) are located| `.` _(root project dir)_ |
| `rolling-strategy` / `CF_ROLLING_STRATEGY`     | Use Cloud Foundry native zero-downtime deployment [strategy](https://docs.cloudfoundry.org/devguide/deploy-apps/rolling-deploy.html). See [Zero-downtime deployment](#zero-downtime-deployment) | `false` |

### Secrets management

@@ -292,6 +293,24 @@ So, what can be done about that?
    * remind to delete your review env **manually before deleting the branch**
    * otherwise you'll have to do it afterwards from your computer (using `cf` CLI) or from the Cloud Foundry console.

### Zero-downtime deployment

Historically Cloud Foundry did not provided any feature for deploying a new version without service interruption. The documentation proposed a [blue-green method](https://docs.cloudfoundry.org/devguide/deploy-apps/blue-green.html) with was implemented in this template. It is enabled with the `CF_XXX_ZERODOWNTIME`variable and is enabled by default in production.

- This solution is complex, runs a full copy of the application and so requires to double the allocated resources _(cpu, ram and disk)_

Starting with CF CLI v7, a new builtin feature called [rolling startegy](https://docs.cloudfoundry.org/devguide/deploy-apps/rolling-deploy.html) was added. It allow to rotate instances one by one instead of switching all instances at once.

This feature can be enabled with `rolling-strategy` input or `CF_ROLLING_STRATEGY` variable. Enabling it as a few implications:

- All environments will use this strategy. So `$CF_XXX_ZERODOWNTIME` is ignored
- The `cf-pre-start.sh` hook is only called during the first deployment as `--no-start` is incompatible with the strategy
- During the next deployments, two versions of your application will accept requests concurrently. It may have a impact on:
  - Single instance application which will temporarily become concurrent
  - Atomic actions like database migrations which might break the previous version
- Deployment won't stop if `cf-readiness-check.sh` hook fails. So the `health-check-http-endpoint` should check all services availability.
- The `cf-post-bluegreen.sh` hook is not called as it is not a blue-green deployment

### Manifest processing

Deployment jobs support a versatile way to evaluate the **deployment manifest**.
+7 −0
Original line number Diff line number Diff line
@@ -66,6 +66,13 @@
      "description": "Directory where Cloud Foundry scripts (manifest, hook scripts) are located",
      "default": ".",
      "advanced": true
    },
    {
      "name": "CF_ROLLING_STRATEGY",
      "description": "Use Cloud Foundry native zero-downtime deployment strategy instead of the historical blue-green method _(ignores $CF_XXX_ZERODOWNTIME)_",
      "type": "boolean",
      "default": "false",
      "advanced": true
    }
  ],
  "features": [
+13 −1
Original line number Diff line number Diff line
@@ -24,6 +24,10 @@ spec:
    scripts-dir:
      description: Directory where Cloud Foundry scripts (manifest, hook scripts) are located
      default: "."
    rolling-strategy:
      description: Use Cloud Foundry native zero-downtime deployment strategy instead of the historical blue-green method _(ignores $CF_XXX_ZERODOWNTIME)_
      type: boolean
      default: false
    url:
      description: Global Cloud Foundry API url
      default: ''
@@ -229,6 +233,7 @@ variables:

  CF_MANIFEST_BASENAME: $[[ inputs.manifest-basename ]]
  CF_SCRIPTS_DIR: $[[ inputs.scripts-dir ]]
  CF_ROLLING_STRATEGY: $[[ inputs.rolling-strategy ]]

  CF_URL: $[[ inputs.url ]]
  CF_ORG: $[[ inputs.org ]]
@@ -615,6 +620,13 @@ stages:
      cf start "$tmpappname"
    else
      log_info "--- auto-start: \\e[94;1myes\\e[0m"

      if [[ "$CF_ROLLING_STRATEGY" == "true" ]]
      then
        log_info "--- using rolling strategy for zero-downtime\\e[0m"
        cf_push_args+=("--strategy" "rolling")
      fi

      cf push "${cf_push_args[@]}"
    fi

@@ -831,7 +843,7 @@ stages:
    routepath=${6}
    pushargs=${7}

    if [[ "$zdt" = "true" ]]
    if [[ "$zdt" = "true" ]] && [[ "$CF_ROLLING_STRATEGY" != "true" ]]
    then
      # blue/green deploy
      blue_green_deploy "$env" "$appname" "$hostname" "$domain" "$routepath" "$pushargs"