Skip to content

Approving deployment does not bust environments.json cache

Summary

When approving or rejecting a deployment, the change is not loaded. In the network tab, the polling of the environments endpoint continuously returns a 304 response.

Steps to reproduce

  1. Set up a simple environment deployment pipeline:
  stages:
      - deploy
      - stop
  image: alpine:latest

  deploy-prod:
      stage: deploy
      script:
          - sleep 10
          - echo "deploying prod"
      environment:
          name: production
          url: postgres://example.com

  deploy-staging:
      stage: deploy
      script:
          - echo "deploying staging I hope"
      environment:
          name: staging
          url: https://example.com

  deploy-development:
      stage: deploy
      script:
          - echo "deploying development"
      environment:
          name: development
          url: https://example.com
      when: manual

  deploy-review:
      stage: deploy
      script:
          - echo "Deploying review/$CI_COMMIT_REF_NAME"
      environment:
          name: review/$CI_COMMIT_REF_NAME
          auto_stop_in: 1 week
      only:
          - branches
      except:
          - main
      when: manual


  stop_review_app:
  script: stop-review-app
  stage: stop
  environment:
      name: review/$CI_COMMIT_REF_SLUG
      action: stop
  rules:
      - if: $CI_MERGE_REQUEST_ID
      when: manual
  1. Run the pipeline to create environments
  2. Protect one of the environments with multiple approval rules (either via the API or :multiple_approval_rules_fe feature flag enabled)
  3. Run a pipeline, now a deployment should be pending approval.
  4. Open network tab in developer tools
  5. Approve the deployment
  6. Observe network tab

What is the current bug behavior?

The deployment is approved correctly, the request to approve the deployment returns a 201. However, the polling for environments at environments.json continues to return a 304, never returning the updated deployment with approval status.

What is the expected correct behavior?

The cache should be busted and the approval should trigger an updated response.

Relevant logs and/or screenshots

Screen_Recording_2023-03-10_at_1.21.36_PM

Possible fixes

Expire Etag cache for environment page when a deployment is approved. Here is the proposed fix:

diff --git a/ee/app/services/deployments/approval_service.rb b/ee/app/services/deployments/approval_service.rb
index b5c9313c7c13..86976a834e9e 100644
--- a/ee/app/services/deployments/approval_service.rb
+++ b/ee/app/services/deployments/approval_service.rb
@@ -19,6 +19,8 @@ def execute(deployment, status)
 
       process_build!(deployment, approval)
 
+      deployment.invalidate_cache
+
       success(approval: approval)
     end

Implementation guide

Edited by Shinya Maeda