File: terminal.rb

package info (click to toggle)
gitlab 17.6.5-19
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 629,368 kB
  • sloc: ruby: 1,915,304; javascript: 557,307; sql: 60,639; xml: 6,509; sh: 4,567; makefile: 1,239; python: 406
file content (78 lines) | stat: -rw-r--r-- 2,591 bytes parent folder | download
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
# frozen_string_literal: true

module WebIde
  class Config
    module Entry
      ##
      # Entry that represents a concrete CI/CD job.
      #
      class Terminal < ::Gitlab::Config::Entry::Node
        include ::Gitlab::Config::Entry::Configurable
        include ::Gitlab::Config::Entry::Attributable
        include Gitlab::Utils::StrongMemoize

        # By default the build will finish in a few seconds, not giving the webide
        # enough time to connect to the terminal. This default script provides
        # those seconds blocking the build from finishing inmediately.
        DEFAULT_SCRIPT = ['sleep 60'].freeze

        ALLOWED_KEYS = %i[image services tags before_script script variables].freeze

        validations do
          validates :config, allowed_keys: ALLOWED_KEYS
          validates :config, job_port_unique: { data: ->(record) { record.ports } }

          with_options allow_nil: true do
            validates :tags, array_of_strings: true
          end
        end

        entry :before_script, ::Gitlab::Ci::Config::Entry::Commands,
          description: 'Global before script overridden in this job.'

        entry :script, ::Gitlab::Ci::Config::Entry::Commands,
          description: 'Commands that will be executed in this job.'

        entry :image, ::Gitlab::Ci::Config::Entry::Image,
          description: 'Image that will be used to execute this job.'

        entry :services, ::Gitlab::Ci::Config::Entry::Services,
          description: 'Services that will be used to execute this job.'

        entry :variables, ::Gitlab::Ci::Config::Entry::Variables,
          description: 'Environment variables available for this job.'

        attributes :tags

        def value
          to_hash.compact
        end

        private

        def to_hash
          {
            tag_list: tags || [],
            job_variables: yaml_variables,
            options: {
              image: image_value,
              services: services_value,
              before_script: before_script_value,
              script: script_value || DEFAULT_SCRIPT
            }.compact
          }.compact
        end

        def yaml_variables
          strong_memoize(:yaml_variables) do # rubocop:todo Gitlab/StrongMemoizeAttr -- legacy Web IDE is deprecated, not fixing this because. Also not sure if strong_memoize_attr will change behavior
            next unless variables_value

            variables_value.map do |key, value|
              { key: key.to_s, value: value, public: true }
            end
          end
        end
      end
    end
  end
end