Welcome to mirror list, hosted at ThFree Co, Russian Federation.

deployment.rb « seed « pipeline « ci « gitlab « lib - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 69dfd6be8d52130bb4c3fa76e33c44da8ccd861b (plain)
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
# frozen_string_literal: true

module Gitlab
  module Ci
    module Pipeline
      module Seed
        class Deployment < Seed::Base
          attr_reader :job, :environment

          def initialize(job, environment)
            @job = job
            @environment = environment
          end

          def to_resource
            return job.deployment if job.deployment
            return unless job.starts_environment?

            deployment = ::Deployment.new(attributes)

            # If there is a validation error on environment creation, such as
            # the name contains invalid character, the job will fall back to a
            # non-environment job.
            return unless deployment.valid? && deployment.environment.persisted?

            if cluster = deployment.environment.deployment_platform&.cluster
              # double write cluster_id until 12.9: https://gitlab.com/gitlab-org/gitlab/issues/202628
              deployment.cluster_id = cluster.id
              deployment.deployment_cluster = ::DeploymentCluster.new(
                cluster_id: cluster.id,
                kubernetes_namespace: cluster.kubernetes_namespace_for(deployment.environment, deployable: job)
              )
            end

            # Allocate IID for deployments.
            # This operation must be outside of transactions of pipeline creations.
            deployment.ensure_project_iid!

            deployment
          end

          private

          def attributes
            {
              project: job.project,
              environment: environment,
              user: job.user,
              ref: job.ref,
              tag: job.tag,
              sha: job.sha,
              on_stop: job.on_stop
            }
          end
        end
      end
    end
  end
end