Class: AppCommand::Build

Inherits:
Convoy::ActionCommand::Base
  • Object
show all
Defined in:
lib/routes/build.rb

Instance Method Summary collapse

Instance Method Details

#build_serviceObject



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
# File 'lib/routes/build.rb', line 70

def build_service

    App::Tools::verify_vm_is_reachable if @is_lib == false

    if App::Tools::this_is_a_mac

        args = @args.dup
        args.shift

        commands = [
            "mvn clean install#{@opts[:deploy] ? ' deploy' : ''}#{args.any? ? " #{args.join(' ')}" : ''}",
        ]
        if @is_lib == false

            output = App::Terminal::command_capture(commands, @service_dir)

            lines = output[0].chomp
            lines = lines.split("\n")

            war_file_ws = nil
            build_failed = false
            build_fail_url = nil

            lines.each do |line|
                if line =~ /\A\[INFO\] Building war: (.*).war\z/
                    war_file_ws = line
                end
                if line =~ /\A\[INFO\] BUILD FAILURE\z/
                    build_failed = true
                end
                if line =~ /\[ERROR\] Please refer to (.*)surefire-reports/
                    build_fail_url = line
                    build_fail_url = build_fail_url.split('Please refer to ')
                    build_fail_url = build_fail_url[1].split(' for the individual')
                    build_fail_url = build_fail_url[0]
                end
            end

            if build_failed
                App::Terminal::error('Build failed', nil, false)
                puts output[0]
                puts
                # If a build fail URL was found, launch it in default browser.
                unless build_fail_url.nil?
                    if App::Terminal::prompt_yes_no("Would you like to #{App::Terminal::format_action('open a stack-trace')} in your default browser?", build_fail_url)
                        system("open -a Google\\ Chrome #{build_fail_url}")
                    end
                end
                exit
            end

            puts output

            war_file_ws = war_file_ws.split('war: ')
            war_file_ws = war_file_ws[1].chomp

            war_file_vm = war_file_ws.split('/')
            war_file_vm = war_file_vm[war_file_vm.length - 1]

            commands = [
                "scp #{war_file_ws} #{App::Config.param(App::Config::VM_USER)}@#{App::Config.param(App::Config::VM_IP)}:/tmp",
                "sshpass -p#{App::Config.param(App::Config::VM_USER_PASSWORD)} ssh #{App::Config.param(App::Config::VM_USER)}@#{App::Config.param(App::Config::VM_IP)} 'cd /brightpearl-source/dev-vm-control-scripts/scm && ~/generated-scripts/deploy-uploaded-service #{war_file_vm}'"

            ]
            App::Terminal::command(commands)

        else

            App::Terminal::command(commands, @service_dir)

        end

    else

        commands = [
            'mvn clean install -P deploy-service',
        ]
        App::Terminal::command(commands, @service_dir)

    end

end

#executeObject



5
6
7
8
9
10
11
12
13
14
# File 'lib/routes/build.rb', line 5

def execute

    @opts = command_options
    @args = arguments
    @service_dir = nil
    @is_lib = false
    opts_validate
    opts_routing

end

#opts_routingObject



64
65
66
67
68
# File 'lib/routes/build.rb', line 64

def opts_routing

    build_service

end

#opts_validateObject



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
# File 'lib/routes/build.rb', line 16

def opts_validate

    if @args[0].nil?
        App::Terminal::error('Must specify service name', "The script cannot build your service because you haven't told it what service to build.", true)
    end

    # Set 'service only' to default.
    if !@opts[:serviceOnly] && !@opts[:apiOnly] && !@opts[:both]
        @opts[:serviceOnly] = true
    end

    if @options[:serviceOnly]
        suffix = "/#{@args[0]}-service"
    elsif @opts[:apiOnly]
        suffix = "/#{@args[0]}-api"
    else
        suffix = ''
    end

    service_dir = App::Config.param(App::Config::WORKSTATION_PATH_TO_BP_CODE)
    dir_dev_support = "#{service_dir}/services/dev-support/#{@args[0]}#{suffix}"
    dir_functional = "#{service_dir}/services/functional/#{@args[0]}#{suffix}"
    dir_infrastructure = "#{service_dir}/services/infrastructure/#{@args[0]}#{suffix}"
    dir_integration = "#{service_dir}/services/integration/#{@args[0]}#{suffix}"
    dir_lib = "#{service_dir}/services/lib/#{@args[0]}"

    if File.directory?(dir_dev_support)
        @service_dir = dir_dev_support
    end
    if File.directory?(dir_functional)
        @service_dir = dir_functional
    end
    if File.directory?(dir_infrastructure)
        @service_dir = dir_infrastructure
    end
    if File.directory?(dir_integration)
        @service_dir = dir_integration
    end
    if File.directory?(dir_lib)
        @service_dir = dir_lib
        @is_lib = true
    end
    if @service_dir.nil?
        App::Terminal::error('Cannot find service', "The script is unable to find a service called: \x1B[38;5;202m#{@args[0].downcase}\x1B[0m\nPlease check your spelling and try again.")
    end

end