1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155
|
# 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 :deploy_job do
name { 'deploy job' }
environment { 'env' }
options do
{
script: %w(ls),
environment: { name: environment, action: 'start' }
}
end
set_expanded_environment_name
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
|