Provision Preview-Env via CLI for End-to-End Tests

Preview apps are a fantastic way to review changes in an encapsulated environment. And a few things happened there recently with create on demand for example.

We would like to take this to the next level and run automated end-to-end tests on them. In order to do so, we need more control over their deployment:

Before e2e tests can run, the following needs to be completed:

  • create new environment
  • databases started
  • correct branch/commit set
  • applications deployed
  • predictable URL endpoints set

We therefore suggest to allow provisioning of preview apps via CLI:

qovery preview create \
  --organization <your_org_name> \
  --project <your_project_name> \
  --cluster <cluster_name_to_create_preview_app_in> \
  --environment <environment_to_clone_from> \
  --new-environment-name <preview_env_name> \
  --branch <pull_request_branch_name> \
  --commit-id <commit_id_to_deploy> \
  --applications <list_of_applications_to_deploy> \
  --watch

This allows starting the test step of CI workflow, once the above has finished. We tried different ways so far, but creating preview apps manually takes several steps using different parts of the CLI and it’s really slow. Also predictable URLs are then gone.

How did others solve this?

Hi @FlorianSuchan , thank you for your suggestion, and glad you want to push Preview Env to the next level with E2E tests. Before responding, can you share your complete CI workflow with all the Qovery CLI commands you execute? I would like to see what commands you execute to see if we can propose something that will make it simpler and faster for you. :pray:

Hi @rophilogene, yes, I’ll share the CI workflow to create a preview app below - however we still can’t use it for e2e tests because the predictable URLs are gone (type is now dev not preview anymore).

jobs:
  provision-preview-environment:
    runs-on: ubuntu-latest
    steps:
      - name: Clone Environment
        env:
          QOVERY_CLI_ACCESS_TOKEN: ${{ secrets.api-token }}
        shell: bash
        run: |
          curl -s https://get.qovery.com | bash

          qovery environment clone \
            --cluster
            --organization
            --project
            --environment ${{ inputs.clone-from }} \
            --new-environment-name ${{ inputs.new-environment-name }} \
            || exit 0

      - name: Update Branch
        env:
          QOVERY_CLI_ACCESS_TOKEN: ${{ secrets.api-token }}
        shell: bash
        run: |
          curl -s https://get.qovery.com | bash

          qovery application update \
            --organization
            --project
            --environment ${{ inputs.new-environment-name }} \
            --application application-1 \
            --branch ${{ inputs.branch }}

          qovery application update \
            --organization
            --project
            --environment ${{ inputs.new-environment-name }} \
            --application application-2 \
            --branch ${{ inputs.branch }}

          qovery application update \
            --organization
            --project
            --environment ${{ inputs.new-environment-name }} \
            --application application-3 \
            --branch ${{ inputs.branch }}
      
      - name: Deploy Environment
        env:
          QOVERY_CLI_ACCESS_TOKEN: ${{ secrets.api-token }}
        shell: bash
        run: |
          curl -s https://get.qovery.com | bash

          qovery database deploy \
            --organization
            --project
            --environment ${{ inputs.new-environment-name }} \
            --database pg-1 \
            --watch

          qovery database deploy \
            --organization
            --project
            --environment ${{ inputs.new-environment-name }} \
            --database pg-2 \
            --watch

          qovery database deploy \
            --organization
            --project
            --environment ${{ inputs.new-environment-name }} \
            --database redis \
            --watch

          qovery application deploy \
            --organization
            --project
            --environment ${{ inputs.new-environment-name }} \
            --applications application-1,application-2,application-3 \
            --commit-id ${{ inputs.commit-id }} \
            --watch

Thank you @FlorianSuchan . Here are a few optimizations you can do in your script.

Small workflow optimization

Instead of deploying each service independently, you can deploy the environment and then deploy the app version you expect (I still think we need to improve this).

So instead of this:

      - name: Deploy Environment
        env:
          QOVERY_CLI_ACCESS_TOKEN: ${{ secrets.api-token }}
        shell: bash
        run: |
          curl -s https://get.qovery.com | bash

          qovery database deploy \
            --organization
            --project
            --environment ${{ inputs.new-environment-name }} \
            --database pg-1 \
            --watch

          qovery database deploy \
            --organization
            --project
            --environment ${{ inputs.new-environment-name }} \
            --database pg-2 \
            --watch

          qovery database deploy \
            --organization
            --project
            --environment ${{ inputs.new-environment-name }} \
            --database redis \
            --watch

          qovery application deploy \
            --organization
            --project
            --environment ${{ inputs.new-environment-name }} \
            --applications application-1,application-2,application-3 \
            --commit-id ${{ inputs.commit-id }} \
            --watch

You can do this:

      - name: Deploy Environment
        env:
          QOVERY_CLI_ACCESS_TOKEN: ${{ secrets.api-token }}
        shell: bash
        run: |
          curl -s https://get.qovery.com | bash

          qovery environment deploy \
            --organization
            --project
            --environment ${{ inputs.new-environment-name }} \
            --watch

          qovery application deploy \
            --organization
            --project
            --environment ${{ inputs.new-environment-name }} \
            --applications application-1,application-2,application-3 \
            --commit-id ${{ inputs.commit-id }} \
            --watch

Note: It’s a small optimization, but it will save you seconds to minutes of deployment.

Ensure you have correctly configured your deployment order.

Predictable URL / Domain

Good news is that you can get predictable URLs with the Qovery CLI. So inside your pipeline, you could add a step to change the URLs of your applications.

Let’s say Qovery provides to your app the following URL https://p8080-zaa190093-ze2b27453-gtw.z809f9644.rustrocks.cloud. With the CLI you can create a custom domain that will be anything before .z809f9644.rustrocks.cloud. For instance, if I want to create a domain app-1-e2e-123.z809f9644.rustrocks.cloud I just need to execute the following commands from the Qovery CLI:

qovery application domain create -n "app name" --organization "your org" --environment "your env" --domain app-1-e2e-123.z809f9644.rustrocks.cloud

To make sure it works all the time, you can use the following:

# This will return "z809f9644.rustrocks.cloud"
root_domain=`qovery application domain list -n "app name"  --organization "your org" --environment "your env" | grep "BUILT_IN_DOMAIN" | head -1 | awk '{print $5}' | cut -d . -f 2-`

qovery application domain create -n "app name" --organization "your org" --environment "your env" --domain app-1-e2e-123.$root_domain

Then you must redeploy your app(s) where you added the predictable domain. You’ll be able to get access to your app via the domain you defined.

If you want to use a predictable domain with your domain, check out this guide.

–

Let me know if it helps.

1 Like

Thanks for your ideas @rophilogene on how to make this work. It does work!

We totally missed the point that adding URLs to the same root-domain works out of the box, custom domain always sounded like “our own domain”. Thanks four pointing this out.

The improvements on the deployments brought us down to 6-8 minutes which is ok for now - more speed always welcome of course :wink:

We would still be interested to see preview env creation to be simpler via CLI but this works for now and hopefully helps some others too. Cheers!

1 Like

Thank you @FlorianSuchan - we are always looking for deployment speed improvement… It’s key. :slight_smile: Glad to see it works now

1 Like

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.

Hi @FlorianSuchan - I’m following up on this thread just to let you know that we’ve published a guide on how to run e2e tests with GitHub actions and Qovery. You might find some interesting stuff

—

And concerning the performances - you might like this thread:

1 Like