Deployment rules doesn't apply to newly created environments

Hi there,

I just setup the following deployment rule:

Our CI creates environments with the following name pattern:

I was hoping to auto-turn on and off our [PR-{pr.id}] {ticket.name} environments but no deployment rules are being applied on creation.

Is there anything that I’m missing on that feature?

Hello John,

It should do what you describe/try to achieve.
I tested on my organization and I don’t encounter the issue.

Can you give me the console.qovery.com url of the project where you are trying to do that so I can take a closer look ?

Hi Romain,

Sure, it’s https://console.qovery.com/organization/12e0c625-6fb8-434b-adeb-041614fa7a46/project/a7f79a8f-8c0e-46a5-8748-1ba9846481c9/environments/general

Thanks for your help

I just tried to create a new environment named [PR-10350] fix(DEV-1966): keep me alive on this project and the settings are correctly applied (I used the API to do it).

Can you let me know how you are creating those environments from your CI ?

That’s already a good news. Now let’s figure out what’s wrong with our deployment :stuck_out_tongue:

Here is the portion of our github workflow that might interest you:

    - name: Create environment
      if: ${{ github.event.action == 'opened' || github.event.action == 'reopened' }}
      shell: bash
      run: |
        qovery environment clone \
          --organization <my_org> \
          --project WebApp \
          --environment blueprint \
          --environment-type preview \
          --new-environment-name "${{ env.environment_name }}"

    - name: Deploy databases
      if: ${{ github.event.action == 'opened' || github.event.action == 'reopened' }}
      shell: bash
      run: |
        qovery database deploy \
          --organization <my_org> \
          --project WebApp \
          --environment "${{ env.environment_name }}" \
          --database postgresql \
          --watch

        qovery database deploy \
          --organization <my_org> \
          --project WebApp \
          --environment "${{ env.environment_name }}" \
          --database redis \
          --watch

    - name: Clone Staging Database
      if: ${{ github.event.action == 'opened' || github.event.action == 'reopened' }}
      shell: bash
      run: |
        qovery lifecycle deploy \
          --organization <my_org> \
          --project WebApp \
          --environment "${{ env.environment_name }}" \
          --lifecycle "DB - Clone Staging" \
          --tag ${{ env.image_tag }} \
          --watch

    - name: Configure environment
      if: ${{ github.event.action == 'opened' || github.event.action == 'reopened' }}
      shell: bash
      run: |
        qovery container env create \
          --organization <my_org> \
          --project WebApp \
          --environment "${{ env.environment_name }}" \
          --container web \
          --scope environment \
          --key PULL_REQUEST_ID \
          --value ${{ steps.PR.outputs.number }}

        qovery lifecycle deploy \
          --organization <my_org> \
          --project WebApp \
          --environment "${{ env.environment_name }}" \
          --lifecycle "ENV - Setup / Destroy preview environment" \
          --tag ${{ env.image_tag }} \
          --watch

    - name: Deploy containers
      shell: bash
      run: |
        qovery container deploy \
          --organization <my_org> \
          --project WebApp \
          --environment "${{ env.environment_name }}" \
          --containers "web,worker,crontab" \
          --tag ${{ env.image_tag }} \
          --watch

Thank you, I understand now.
Your issue is due because you are cloning the environment. When you clone, the environment inherits the same settings of the parent. So it bypasses the deployment rules logic of creation.

To change those settings while still cloning the environment, you either

  1. Need to edit/modify the cloned environment after its creation
  2. modify your blueprint environment to have the wanted settings

If you go with 1, there is no easy way for now to change those settings with the CLI.
The only way is to use the API

https://api-doc.qovery.com/#tag/Environment-Deployment-Rule/operation/getEnvironmentDeploymentRule

An example

curl 'https://api.qovery.com/environment/ee9fa826-9747-47d1-8044-9c34423dac46/deploymentRule/99c1bee4-f2c3-4b0d-8ffb-062d699b46c1' -H 'Content-Type: application/json' -H 'Authorization: Token xxxxx'  --data-raw '{"auto_deploy":true,"auto_delete":false,"auto_preview":false,"auto_stop":true,"timezone":"UTC","start_time":"1970-01-01T08:00:00.000Z","stop_time":"1970-01-01T19:00:00.000Z","weekdays":["MONDAY","TUESDAY","WEDNESDAY","THURSDAY","FRIDAY"]}'

Ok now I got it, thanks for the explanation.

I there a reason why you went for that implementation of not applying the Deployment rules when it’s a cloned environment?

Because if I apply the rule to the environment I clone. It means that the environment will turn on and off the same way the cloned environments will.

Meaning that I’ll pay for that “useless” environment, while the purpose of that feature is specifically to make us save money :confused:

Do you think it’s doable to add such a feature to the CLI?

You are right, this is a lack of flexibility on our side regarding cloning.
I am creating a ticket to allow enabling/or not the application of deployment rules when cloning.

Regarding the reasoning, this is due because most users want a pristine clone of the resource.
But we’re already applying deployment rule when a clone is trigerred by webhook for PRs, so there is no reason we can allow this possibility also in the API.

We are going to try to do it for next sprint (nex couple weeks) as it should not be much work.

1 Like

Sweet! Thanks a lot for your help and for adding the ticket :wink:

Hello @jmeiss,

Just to let you know that the feature is now available in the CLI (and soon to be in the UI).
If you use the latest version of the qovery-cli (v0.58.8) you have a new flag in the environment clone, called --apply-deployment-rule. If you set your new env is going to apply the deployment rule logic.

❯ qovery environment clone -h
Clone an environment

Usage:
  qovery environment clone [flags]

Flags:
      --apply-deployment-rule         Enable applying deployment rules on the new environment instead of having a pristine clone. Default: false
  -c, --cluster string                Cluster Name where to clone the environment
  -e, --environment string            Environment Name to clone
  -t, --environment-type string       Environment type for the new environment (DEVELOPMENT|STAGING|PRODUCTION)
  -h, --help                          help for clone
  -n, --new-environment-name string   New Environment Name
  -o, --organization string           Organization Name
  -p, --project string                Project Name

Let me know if it is not enough for you

:open_mouth:

Thanks a lot, guys! That was blazing fast! I appreciate :pray: