Skip to content

Commit b577ba7

Browse files
committed
Add local signing of extra files
Because we are currently building and signing things locally in a VM for MacOS, rather than shipping files to a signing server and then shipping them back, we sign the files in-place. This adds this capability to the ExtraFilesSigner class, and adds a new project parameter to specify that local signing should be used.
1 parent d460a21 commit b577ba7

File tree

4 files changed

+58
-3
lines changed

4 files changed

+58
-3
lines changed

lib/vanagon/platform/osx.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ def generate_package(project) # rubocop:disable Metrics/AbcSize
3636
end
3737

3838
if project.extra_files_to_sign.any?
39-
sign_commands = Vanagon::Utilities::ExtraFilesSigner.commands(project, @mktemp, "/osx/build/root/#{project.name}-#{project.version}")
39+
method = project.use_local_signing ? 'local_commands' : 'commands'
40+
sign_commands = Vanagon::Utilities::ExtraFilesSigner.send(method, project, @mktemp, "/osx/build/root/#{project.name}-#{project.version}")
4041
else
4142
sign_commands = []
4243
end

lib/vanagon/project.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,12 +111,11 @@ class Project
111111
attr_accessor :no_packaging
112112

113113
# Extra files to sign
114-
# Right now just supported on windows, useful for signing powershell scripts
115-
# that need to be signed between build and MSI creation
116114
attr_accessor :extra_files_to_sign
117115
attr_accessor :signing_hostname
118116
attr_accessor :signing_username
119117
attr_accessor :signing_command
118+
attr_accessor :use_local_signing
120119

121120
# For creating reproducible builds
122121
attr_accessor :source_date_epoch
@@ -173,6 +172,7 @@ def initialize(name, platform) # rubocop:disable Metrics/AbcSize
173172
@signing_hostname = ''
174173
@signing_username = ''
175174
@signing_command = ''
175+
@use_local_signing = false
176176
@source_date_epoch = (ENV['SOURCE_DATE_EPOCH'] || Time.now.utc).to_i
177177
end
178178

lib/vanagon/project/dsl.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,14 @@ def signing_username(username)
397397
def signing_command(command)
398398
@project.signing_command = command
399399
end
400+
401+
# When true, run the signing commands locally rather than SSHing to a
402+
# signing host.
403+
#
404+
# @param [Boolean] Whether to use local signing
405+
def use_local_signing(var)
406+
@project.use_local_signing = var
407+
end
400408
end
401409
end
402410
end

lib/vanagon/utilities/extra_files_signer.rb

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,53 @@
1+
require 'open3'
2+
13
class Vanagon
24
module Utilities
35
module ExtraFilesSigner
46
class << self
7+
RED = "\033[31m".freeze
8+
GREEN = "\033[32m".freeze
9+
RESET = "\033[0m".freeze
10+
11+
def run_command(cmd, silent: true, print_command: false, report_status: false)
12+
puts "#{GREEN}Running #{cmd}#{RESET}" if print_command
13+
output = ''
14+
Open3.popen2e(cmd) do |_stdin, stdout_stderr, thread|
15+
stdout_stderr.each do |line|
16+
puts line unless silent
17+
output += line
18+
end
19+
exitcode = thread.value.exitstatus
20+
unless exitcode.zero?
21+
err = "#{RED}Command failed! Command: #{cmd}, Exit code: #{exitcode}"
22+
# Print details if we were running silent
23+
err += "\nOutput:\n#{output}" if silent
24+
err += RESET
25+
abort err
26+
end
27+
puts "#{GREEN}Command finished with status #{exitcode}#{RESET}" if report_status
28+
end
29+
output.chomp
30+
end
31+
32+
def local_commands(project, mktmp, source_dir)
33+
commands = []
34+
signing_script_path = File.join(run_command("#{mktmp} 2>/dev/null"), File.basename('sign_extra_file'))
35+
36+
project.extra_files_to_sign.each do |file|
37+
commands += [
38+
"echo '#{project.signing_command} #{file}' > #{signing_script_path}",
39+
"/bin/bash #{signing_script_path}",
40+
]
41+
end
42+
43+
commands
44+
rescue RuntimeError
45+
require 'vanagon/logger'
46+
VanagonLogger.error "Error signing extra files: #{project.extra_files_to_sign.join(',')}"
47+
raise if ENV['VANAGON_FORCE_SIGNING']
48+
[]
49+
end
50+
551
def commands(project, mktemp, source_dir) # rubocop:disable Metrics/AbcSize
652
tempdir = nil
753
commands = []

0 commit comments

Comments
 (0)