diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-08-18 13:50:51 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-08-18 13:50:51 +0300 |
commit | db384e6b19af03b4c3c82a5760d83a3fd79f7982 (patch) | |
tree | 34beaef37df5f47ccbcf5729d7583aae093cffa0 /spec/factories/ci/deployable.rb | |
parent | 54fd7b1bad233e3944434da91d257fa7f63c3996 (diff) |
Add latest changes from gitlab-org/gitlab@16-3-stable-eev16.3.0-rc42
Diffstat (limited to 'spec/factories/ci/deployable.rb')
-rw-r--r-- | spec/factories/ci/deployable.rb | 141 |
1 files changed, 141 insertions, 0 deletions
diff --git a/spec/factories/ci/deployable.rb b/spec/factories/ci/deployable.rb new file mode 100644 index 00000000000..15b37e44e07 --- /dev/null +++ b/spec/factories/ci/deployable.rb @@ -0,0 +1,141 @@ +# frozen_string_literal: true + +module Factories + module Ci + module Deployable + def self.traits + <<-RUBY + trait :teardown_environment do + environment { 'staging' } + options do + { + script: %w(ls), + environment: { name: 'staging', + action: 'stop', + url: 'http://staging.example.com/$CI_JOB_NAME' } + } + end + end + + trait :environment_with_deployment_tier do + environment { 'test_portal' } + options do + { + script: %w(ls), + environment: { name: 'test_portal', + action: 'start', + url: 'http://staging.example.com/$CI_JOB_NAME', + deployment_tier: 'testing' } + } + end + end + + trait :deploy_to_production do + environment { 'production' } + + options do + { + script: %w(ls), + environment: { name: 'production', + url: 'http://prd.example.com/$CI_JOB_NAME' } + } + end + end + + trait :start_review_app do + environment { 'review/$CI_COMMIT_REF_NAME' } + + options do + { + script: %w(ls), + environment: { name: 'review/$CI_COMMIT_REF_NAME', + url: 'http://staging.example.com/$CI_JOB_NAME', + on_stop: 'stop_review_app' } + } + end + end + + trait :stop_review_app do + name { 'stop_review_app' } + environment { 'review/$CI_COMMIT_REF_NAME' } + + options do + { + script: %w(ls), + environment: { name: 'review/$CI_COMMIT_REF_NAME', + url: 'http://staging.example.com/$CI_JOB_NAME', + action: 'stop' } + } + end + end + + trait :prepare_staging do + name { 'prepare staging' } + environment { 'staging' } + + options do + { + script: %w(ls), + environment: { name: 'staging', action: 'prepare' } + } + end + + set_expanded_environment_name + end + + trait :start_staging do + name { 'start staging' } + environment { 'staging' } + + options do + { + script: %w(ls), + environment: { name: 'staging', action: 'start' } + } + end + + set_expanded_environment_name + end + + trait :stop_staging do + name { 'stop staging' } + environment { 'staging' } + + options do + { + script: %w(ls), + environment: { name: 'staging', action: 'stop' } + } + end + + set_expanded_environment_name + end + + trait :set_expanded_environment_name do + after(:build) do |job, evaluator| + job.assign_attributes( + metadata_attributes: { + expanded_environment_name: job.expanded_environment_name + } + ) + end + end + + trait :with_deployment do + after(:build) do |job, evaluator| + ## + # Build deployment/environment relations if environment name is set + # to the job. If `job.deployment` has already been set, it doesn't + # build a new instance. + Environments::CreateForJobService.new.execute(job) + end + + after(:create) do |job, evaluator| + Deployments::CreateForJobService.new.execute(job) + end + end + RUBY + end + end + end +end |