Skip to content

Add a default expire_in for Pages extra versions

What does this MR do and why?

This MR adds a default expiration time for Pages extra deployments. This will cause Pages extra deployments to expire after a certain time. After this time they are first deactivated and subsequently deleted.

The default expiry time can be configured by the instance admin as part of the Pages preferences.

MR acceptance checklist

Please evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.

Screenshots or screen recordings

Screenshots are required for UI changes, and strongly recommended for all other merge requests.

Before After
- Screenshot_2024-08-19_at_12.53.46
Screenshot_2024-08-19_at_12.56.03 Screenshot_2024-08-19_at_12.55.15

How to set up and validate locally

  1. Set up your GDK to support Runners and Pages
  2. Enable the multi version feature flag with echo "Feature.enable(\"pages_multiple_versions_setting\")" | rails c
  3. Log in to your GDK as an instance admin, go to the admin area's Settings > Preferences, expand Pages.
  4. Confirm the Input Default expiration for extra deployments in seconds is present and enter a value that you think is reasonable for testing, e.g. 60 (default is 24 hours)
  5. Inside a group, create a Pages project, by creating a new project with the "pages/Plain HTML" template.
  6. Replace the below config in the .gitlab-ci.yml:
image: busybox

pages:
  stage: deploy
  script:
    - echo "Pages accessible through ${CI_PAGES_URL}/${PAGES_PREFIX}"
  variables:
    PAGES_PREFIX: "" # no prefix by default (master)
  pages:
    path_prefix: "$PAGES_PREFIX"
  artifacts:
    paths:
    - public
  rules:
    - if: $CI_COMMIT_BRANCH == "master" # ensure to run on master (with default PAGES_PREFIX)
      variables:
        PAGES_PREFIX: '' # prefix with _stg for the staging branch
    - if: $CI_PIPELINE_SOURCE == "merge_request_event" # conditionally change the prefix on Merge Requests
      variables:
        PAGES_PREFIX: 'mr$CI_MERGE_REQUEST_IID' # prefix with the mr<iid>, like `mr123`
  1. Ensure the pipeline runs successfully and you have a pages deployment
  2. Enable multiple deployments for your new project
  3. Create at least one MR in the project. Ensure each MR's pipeline creates a Pages deployment.
  4. In the project's sidebar go to Deploy > Pages, view the MR's deployments, click on the chevron and confirm that they now show an expiry date and time.
  5. Wait until that expiry date has passed* and confirm that the deployments have been removed (note that they will go first into a "stopped" state before they are permanently removed)
  • the cron job only runs at every 10 minute mark, so you may have to wait for the next job run, or update the cron schedule at line 730 of config/initializers/1_settings.rb

Query

DeactivateExpiredDeploymentsCronWorker.perform runs the below query:

SELECT "pages_deployments"."id" FROM "pages_deployments" WHERE (expires_at < '2024-08-23 10:26:28.866346') ORDER BY "pages_deployments"."id" ASC

Query Plan

thanks @jdrpereira for helping me on this one!

 Sort  (cost=30336.92..30717.05 rows=152052 width=8) (actual time=0.031..0.031 rows=0 loops=1)
   Sort Key: pages_deployments.id
   Sort Method: quicksort  Memory: 25kB
   Buffers: shared hit=4
   I/O Timings: read=0.000 write=0.000
   ->  Index Scan using index_pages_deployments_on_expires_at on public.pages_deployments  (cost=0.12..17249.65 rows=152052 width=8) (actual time=0.003..0.003 rows=0 loops=1)
         Index Cond: (pages_deployments.expires_at < '2024-08-23 10:26:28.866346+00'::timestamp with time zone)
         Buffers: shared hit=1
         I/O Timings: read=0.000 write=0.000

Related to #456477 (closed)

Edited by Janis Altherr

Merge request reports

Loading