apt_stage_artifacts 0.4.0 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/apt_stage_artifacts.gemspec +1 -1
- data/lib/apt_add_to_freight_library.rb +13 -12
- data/lib/apt_stage_artifacts.rb +49 -42
- data/lib/apt_stage_from_tarball.rb +10 -10
- data/lib/apt_update_freight_cache.rb +8 -9
- data/lib/mixins/constants.rb +21 -0
- data/lib/version.rb +1 -1
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0e81f4aec93257b9ff5c06aa0cf5e29f4b3331f99c76252140b56e2cd12f721b
|
4
|
+
data.tar.gz: db1f53e4c5d5dd0b54ae44bc2ce471e04fbaa89bb520a6a7068262713e34d132
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7fb6659180b34b6307ff0ec42d5f0759bc37c62292bb85ba03c6365f5a9c403493dae8370e04fc93ab267dd725cb3f8fb2344db7656ec8cce0fc89d1340dc008
|
7
|
+
data.tar.gz: 4c7042632cfe97bf1cb8716d741b6a7608807157cb47c3faba8792da5dc9acb470f85f27afbfa19d51ad4db65a65163e63ff3d7e237fc9b5ae7688eb72749cb8
|
data/apt_stage_artifacts.gemspec
CHANGED
@@ -14,7 +14,7 @@ Gem::Specification.new do |spec|
|
|
14
14
|
|
15
15
|
spec.metadata['homepage_uri'] = spec.homepage
|
16
16
|
spec.metadata['source_code_uri'] = spec.homepage
|
17
|
-
spec.metadata['changelog_uri'] = File.join(spec.homepage, 'CHANGELOG.md')
|
17
|
+
spec.metadata['changelog_uri'] = File.join(spec.homepage, 'blob', 'main', 'CHANGELOG.md')
|
18
18
|
|
19
19
|
# Specify which files should be added to the gem when it is released.
|
20
20
|
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'version'
|
2
|
+
require 'mixins/constants'
|
2
3
|
require 'mixins/logging'
|
3
4
|
|
4
5
|
require 'English'
|
@@ -33,11 +34,6 @@ require 'tmpdir'
|
|
33
34
|
class AptAddToFreightLibrary
|
34
35
|
include Logging
|
35
36
|
|
36
|
-
FREIGHT_COMMAND = '/usr/bin/freight'
|
37
|
-
VALID_PUPPET_VERSIONS = %w[6 7 8]
|
38
|
-
VALID_REPO_TYPES = %w[archive nightly stable]
|
39
|
-
VALID_CODENAMES = %w[bionic jessie stretch buster bullseye bookwork focal xenial]
|
40
|
-
|
41
37
|
DOCUMENTATION = <<~DOCOPT
|
42
38
|
Adds debian .deb files to a freight library.
|
43
39
|
|
@@ -47,9 +43,9 @@ class AptAddToFreightLibrary
|
|
47
43
|
apt-add-to-freight-library --version
|
48
44
|
|
49
45
|
Options:
|
50
|
-
-p --puppet-version=VERSION Puppet version (Valid: #{VALID_PUPPET_VERSIONS.join(', ')})
|
51
|
-
-r --repo-type=REPO_TYPE Puppet debian repo type (Valid: #{VALID_REPO_TYPES.join(', ')})
|
52
|
-
-c --codename=DEBIAN_CODENAME Debian codename to deliver to (Valid: #{VALID_CODENAMES.join(', ')})
|
46
|
+
-p --puppet-version=VERSION Puppet version (Valid: #{AptStageArtifacts::VALID_PUPPET_VERSIONS.join(', ')})
|
47
|
+
-r --repo-type=REPO_TYPE Puppet debian repo type (Valid: #{AptStageArtifacts::VALID_REPO_TYPES.join(', ')})
|
48
|
+
-c --codename=DEBIAN_CODENAME Debian codename to deliver to (Valid: #{AptStageArtifacts::VALID_CODENAMES.join(', ')})
|
53
49
|
|
54
50
|
-v --verbose Be verbose
|
55
51
|
-h --help Show this help
|
@@ -65,7 +61,7 @@ class AptAddToFreightLibrary
|
|
65
61
|
@script_name = File.basename($PROGRAM_NAME)
|
66
62
|
@version_string = "#{@script_name} version #{AptStageArtifacts::VERSION}"
|
67
63
|
if @user_options['--version'] # rubocop:disable Style/GuardClause
|
68
|
-
|
64
|
+
warn @version_string
|
69
65
|
exit 0
|
70
66
|
end
|
71
67
|
end
|
@@ -73,7 +69,7 @@ class AptAddToFreightLibrary
|
|
73
69
|
def parse_options(argv = nil)
|
74
70
|
Docopt.docopt(DOCUMENTATION, { argv: argv })
|
75
71
|
rescue Docopt::Exit => e
|
76
|
-
|
72
|
+
warn e.message
|
77
73
|
exit 1
|
78
74
|
end
|
79
75
|
|
@@ -87,9 +83,14 @@ class AptAddToFreightLibrary
|
|
87
83
|
fatal "Invalid repo type '#{@repo_type}'" unless VALID_REPO_TYPES.include? @repo_type
|
88
84
|
|
89
85
|
@codename = @user_options['--codename']
|
90
|
-
|
86
|
+
unless AptStageArtifacts::VALID_CODENAMES.include? @codename
|
87
|
+
fatal "Invalid codename '#{@codename}'"
|
88
|
+
end
|
91
89
|
|
92
|
-
freight_config_file =
|
90
|
+
freight_config_file = File.join(
|
91
|
+
FREIGHT_CONFIG_DIRECTORY,
|
92
|
+
"puppet_#{@puppet_version}_#{@repo_type}.conf"
|
93
|
+
)
|
93
94
|
fatal "Cannot read '#{freight_config_file} on #{`hostname`.chomp}." unless
|
94
95
|
File.readable?(freight_config_file)
|
95
96
|
|
data/lib/apt_stage_artifacts.rb
CHANGED
@@ -1,11 +1,12 @@
|
|
1
1
|
require 'version'
|
2
2
|
require 'mixins/logging'
|
3
|
+
require 'mixins/constants'
|
3
4
|
|
4
5
|
require 'English'
|
5
6
|
require 'docopt'
|
6
7
|
require 'fileutils'
|
8
|
+
require 'json'
|
7
9
|
require 'open-uri'
|
8
|
-
require 'tempfile'
|
9
10
|
require 'yaml'
|
10
11
|
|
11
12
|
class AptStageArtifacts
|
@@ -15,35 +16,34 @@ class AptStageArtifacts
|
|
15
16
|
Stages .deb artifacts into a freight library from a Vanagon or packaging directory.
|
16
17
|
|
17
18
|
Usage:
|
18
|
-
apt-stage-artifacts
|
19
|
-
apt-stage-artifacts <top_directory>
|
19
|
+
apt-stage-artifacts [--version]
|
20
|
+
apt-stage-artifacts [--version] <top_directory>
|
20
21
|
DOCOPT
|
21
22
|
|
22
23
|
def initialize(argv)
|
23
24
|
@script_name = File.basename($PROGRAM_NAME)
|
24
25
|
@log_level = Logger::INFO
|
25
26
|
@user_options = parse_options(argv)
|
26
|
-
@version_string = "
|
27
|
+
@version_string = "Version #{AptStageArtifacts::VERSION}"
|
27
28
|
|
28
29
|
@artifacts_tarball_name = 'artifacts.tgz'
|
29
30
|
@local_tarball_path = File.join(Dir.pwd, @artifacts_tarball_name)
|
30
31
|
|
31
32
|
@builder_data_yaml = 'https://raw.githubusercontent.com/puppetlabs/build-data/release/builder_data.yaml'
|
32
33
|
|
33
|
-
@manifest_file_name = 'apt_stage.manifest'
|
34
34
|
@remote_staging_command = 'apt-stage-from-tarball'
|
35
35
|
end
|
36
36
|
|
37
37
|
def parse_options(argv = nil)
|
38
38
|
Docopt.docopt(DOCUMENTATION, { argv: argv })
|
39
39
|
rescue Docopt::Exit => e
|
40
|
-
|
40
|
+
warn e.message
|
41
41
|
exit 1
|
42
42
|
end
|
43
43
|
|
44
44
|
def run
|
45
45
|
logger.info @version_string
|
46
|
-
|
46
|
+
exit 0 if @user_options['--version']
|
47
47
|
load_builder_data_yaml
|
48
48
|
collect_artifacts
|
49
49
|
create_remote_staging_directory
|
@@ -66,6 +66,9 @@ class AptStageArtifacts
|
|
66
66
|
def collect_artifacts
|
67
67
|
if !@user_options['<top_directory>'].to_s.empty?
|
68
68
|
@top_directory = @user_options['<top_directory>']
|
69
|
+
if File.directory?(File.join(@top_directory, 'deb'))
|
70
|
+
@top_directory = File.join(@top_directory, 'deb')
|
71
|
+
end
|
69
72
|
elsif File.directory?('./output/deb')
|
70
73
|
@top_directory = './output/deb'
|
71
74
|
elsif File.directory?('./pkg/deb')
|
@@ -77,7 +80,7 @@ class AptStageArtifacts
|
|
77
80
|
|
78
81
|
logger.info "Searching for .deb packages in #{@top_directory}"
|
79
82
|
Dir.chdir(@top_directory) do
|
80
|
-
@debian_artifacts = Dir['
|
83
|
+
@debian_artifacts = Dir['**/*.deb']
|
81
84
|
end
|
82
85
|
return unless @debian_artifacts.empty?
|
83
86
|
|
@@ -109,25 +112,50 @@ class AptStageArtifacts
|
|
109
112
|
logger.info "Artifacts will be staged on '#{@staging_server}'."
|
110
113
|
end
|
111
114
|
|
112
|
-
# A manifest is a staging to-do list
|
115
|
+
# A manifest is a staging to-do list represented in JSON as an array of hashes
|
113
116
|
# containing:
|
114
|
-
#
|
117
|
+
# deb_file_path:
|
118
|
+
# codename:
|
119
|
+
# puppet_version:
|
120
|
+
# repo_type:
|
115
121
|
def generate_manifest
|
116
|
-
|
122
|
+
manifest = []
|
117
123
|
|
118
124
|
@debian_artifacts.each do |deb_file_path|
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
125
|
+
artifact_components = deb_file_path.split('/')
|
126
|
+
|
127
|
+
repo_name = artifact_components[-2]
|
128
|
+
case repo_name
|
129
|
+
when /^puppet(\d+)-nightly$/
|
130
|
+
puppet_version = Regexp.last_match(1)
|
131
|
+
repo_type = 'nightly'
|
132
|
+
when /^puppet(\d+)-archive/
|
133
|
+
puppet_version = Regexp.last_match(1)
|
134
|
+
repo_type = 'archive'
|
135
|
+
when /^puppet(\d+)+$/
|
136
|
+
puppet_version = Regexp.last_match(1)
|
137
|
+
repo_type = 'stable'
|
138
|
+
else
|
139
|
+
fatal("Unknown repo name \"#{repo_name}\" in #{deb_file_path}")
|
140
|
+
end
|
141
|
+
|
142
|
+
codename = deb_file_path.split('/')[-3]
|
143
|
+
unless AptStageArtifacts::VALID_CODENAMES.include?(codename)
|
144
|
+
fatal("#{deb_file_path} contains an unknown codename: #{codename}")
|
145
|
+
end
|
146
|
+
|
147
|
+
manifest << {
|
148
|
+
deb_file_path: deb_file_path,
|
149
|
+
puppet_version: puppet_version,
|
150
|
+
codename: codename,
|
151
|
+
repo_type: repo_type
|
152
|
+
}
|
126
153
|
end
|
127
154
|
|
128
|
-
|
129
|
-
|
130
|
-
|
155
|
+
manifest_path = File.join(@top_directory, AptStageArtifacts::MANIFEST_JSON_FILENAME)
|
156
|
+
File.open(manifest_path, 'w') do |f|
|
157
|
+
f.write(manifest.to_json)
|
158
|
+
end
|
131
159
|
logger.info("Staging manifest written to '#{manifest_path}'")
|
132
160
|
end
|
133
161
|
|
@@ -148,27 +176,6 @@ class AptStageArtifacts
|
|
148
176
|
File.delete @local_tarball_path
|
149
177
|
end
|
150
178
|
|
151
|
-
# The target apt repository is described in the REPO_NAME environment variable.
|
152
|
-
# A better solution is called for, perhaps as part of vanagon config or as a commandline
|
153
|
-
# parameter.
|
154
|
-
def parse_repo_type
|
155
|
-
case ENV['REPO_NAME']
|
156
|
-
when /\A\z/, nil
|
157
|
-
fatal "The environment variable 'REPO_NAME', containing the target apt repo, is unset.\n" \
|
158
|
-
"It should be set to something like 'puppet7' or 'puppet7-nightly'."
|
159
|
-
when /\Apuppet(\d+)\z/
|
160
|
-
@puppet_version = Regexp.last_match(1)
|
161
|
-
@repo_type = 'stable'
|
162
|
-
when /\Apuppet(\d+)-nightly\z/
|
163
|
-
@puppet_version = Regexp.last_match(1)
|
164
|
-
@repo_type = 'nightly'
|
165
|
-
else
|
166
|
-
fatal "The environment variable 'REPO_NAME' is set to '#{ENV['REPO_NAME']}'\n" \
|
167
|
-
"This is not a recognized setting.\n" \
|
168
|
-
"It should be set to something like 'puppet7' or 'puppet7-nightly'."
|
169
|
-
end
|
170
|
-
end
|
171
|
-
|
172
179
|
# Send the tarball over to the staging server for further processing with freight.
|
173
180
|
def ship_tarball_to_staging_server
|
174
181
|
logger.info "Sending '#{@local_tarball_path}' to '#{@staging_server}:#{@remote_tarball_path}'"
|
@@ -2,6 +2,7 @@ require 'version'
|
|
2
2
|
require 'mixins/logging'
|
3
3
|
|
4
4
|
require 'English'
|
5
|
+
require 'json'
|
5
6
|
require 'mkmf'
|
6
7
|
|
7
8
|
class AptStageFromTarball
|
@@ -9,12 +10,12 @@ class AptStageFromTarball
|
|
9
10
|
|
10
11
|
def initialize(tarball_path = nil)
|
11
12
|
@tarball_path = tarball_path
|
12
|
-
@
|
13
|
+
@manifest_json_file_name = AptStageArtifacts::MANIFEST_JSON_FILENAME
|
13
14
|
@log_level = Logger::INFO
|
14
15
|
@repo_types_updated = {}
|
15
16
|
|
16
17
|
@script_name = File.basename($PROGRAM_NAME)
|
17
|
-
@version_string = "
|
18
|
+
@version_string = "Version #{AptStageArtifacts::VERSION}"
|
18
19
|
|
19
20
|
# External commands
|
20
21
|
@apt_add_to_freight_library_command = 'apt-add-to-freight-library'
|
@@ -57,7 +58,7 @@ class AptStageFromTarball
|
|
57
58
|
fatal "#{tarball_extract_command} failed."
|
58
59
|
end
|
59
60
|
|
60
|
-
@manifest_path = File.join(@tarball_directory, @
|
61
|
+
@manifest_path = File.join(@tarball_directory, @manifest_json_file_name)
|
61
62
|
|
62
63
|
fatal "Staging manifest file '#{@manifest_path}' is missing or unreadable" unless
|
63
64
|
File.readable?(@manifest_path)
|
@@ -69,16 +70,15 @@ class AptStageFromTarball
|
|
69
70
|
# library.
|
70
71
|
def add_artifacts_to_freight_library
|
71
72
|
Dir.chdir(@tarball_directory) do
|
72
|
-
File.
|
73
|
-
|
74
|
-
debian_filename, puppet_version, repo_type, codename = line.split(':')
|
73
|
+
manifest_file = File.read(@manifest_path)
|
74
|
+
JSON.parse(manifest_file, symbolize_names: true).each do |artifact|
|
75
75
|
add_to_freight_library_command = %W[
|
76
76
|
#{@apt_add_to_freight_library_command}
|
77
77
|
--verbose
|
78
|
-
--puppet-version=#{puppet_version}
|
79
|
-
--repo-type=#{repo_type}
|
80
|
-
--codename=#{codename}
|
81
|
-
#{File.join(Dir.pwd,
|
78
|
+
--puppet-version=#{artifact[:puppet_version]}
|
79
|
+
--repo-type=#{artifact[:repo_type]}
|
80
|
+
--codename=#{artifact[:codename]}
|
81
|
+
#{File.join(Dir.pwd, artifact[:deb_file_path])}
|
82
82
|
].join(' ')
|
83
83
|
|
84
84
|
%x(#{add_to_freight_library_command})
|
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'version'
|
2
|
+
require 'mixins/constants'
|
2
3
|
require 'mixins/logging'
|
3
4
|
|
4
5
|
require 'English'
|
@@ -26,10 +27,6 @@ require 'yaml'
|
|
26
27
|
class AptUpdateFreightCache
|
27
28
|
include Logging
|
28
29
|
|
29
|
-
FREIGHT_COMMAND = '/usr/bin/freight'
|
30
|
-
VALID_PUPPET_VERSIONS = %w[6 7 8]
|
31
|
-
VALID_REPO_TYPES = %w[archive nightly stable]
|
32
|
-
|
33
30
|
DOCUMENTATION = <<~DOCOPT
|
34
31
|
Generates a freight cache from a freight library.
|
35
32
|
|
@@ -39,8 +36,8 @@ class AptUpdateFreightCache
|
|
39
36
|
apt-update-freight-cache --version
|
40
37
|
|
41
38
|
Options:
|
42
|
-
-p --puppet-version=VERSION Puppet version (Valid: #{VALID_PUPPET_VERSIONS.join(', ')})
|
43
|
-
-r --repo-type=REPO_TYPE Puppet debian repo type (Valid: #{VALID_REPO_TYPES.join(', ')})
|
39
|
+
-p --puppet-version=VERSION Puppet version (Valid: #{AptStageArtifacts::VALID_PUPPET_VERSIONS.join(', ')})
|
40
|
+
-r --repo-type=REPO_TYPE Puppet debian repo type (Valid: #{AptStageArtifacts::VALID_REPO_TYPES.join(', ')})
|
44
41
|
|
45
42
|
-v --verbose Be verbose
|
46
43
|
-h --help Show this help
|
@@ -56,7 +53,7 @@ class AptUpdateFreightCache
|
|
56
53
|
@script_name = File.basename($PROGRAM_NAME)
|
57
54
|
@version_string = "#{@script_name} version #{AptStageArtifacts::VERSION}"
|
58
55
|
if @user_options['--version'] # rubocop:disable Style/GuardClause
|
59
|
-
|
56
|
+
warn @version_string
|
60
57
|
exit 0
|
61
58
|
end
|
62
59
|
end
|
@@ -73,10 +70,12 @@ class AptUpdateFreightCache
|
|
73
70
|
load_builder_data_yaml
|
74
71
|
@puppet_version = @user_options['--puppet-version']
|
75
72
|
fatal "Invalid Puppet version '#{@puppet_version}'" unless
|
76
|
-
VALID_PUPPET_VERSIONS.include? @puppet_version
|
73
|
+
AptStageArtifacts::VALID_PUPPET_VERSIONS.include? @puppet_version
|
77
74
|
|
78
75
|
@repo_type = @user_options['--repo-type']
|
79
|
-
|
76
|
+
unless AptStageArtifacts::VALID_REPO_TYPES.include? @repo_type
|
77
|
+
fatal "Invalid repo type '#{@repo_type}'"
|
78
|
+
end
|
80
79
|
|
81
80
|
freight_config_file = "/etc/freight.conf.d/puppet_#{@puppet_version}_#{@repo_type}.conf"
|
82
81
|
fatal "Cannot read '#{freight_config_file} on #{`hostname`.chomp}." unless
|
@@ -0,0 +1,21 @@
|
|
1
|
+
##
|
2
|
+
## Some constants that are used throughout the code
|
3
|
+
##
|
4
|
+
|
5
|
+
class AptStageArtifacts
|
6
|
+
# Details about freight itself
|
7
|
+
FREIGHT_COMMAND = '/usr/bin/freight'
|
8
|
+
|
9
|
+
# Name of the manifest.json file
|
10
|
+
MANIFEST_JSON_FILENAME = 'apt_stage_manifest.json'
|
11
|
+
|
12
|
+
# Debian/Ubuntu codenames that we care about.
|
13
|
+
# Some codenames are skipped because we don't/haven't shipped for them.
|
14
|
+
DEBIAN_CODENAMES = %w[jessie stretch buster bullseye bookworm trixie]
|
15
|
+
UBUNTU_CODENAMES = %w[xenial bionic focal groovy]
|
16
|
+
VALID_CODENAMES = DEBIAN_CODENAMES | UBUNTU_CODENAMES
|
17
|
+
|
18
|
+
# Validation constraints
|
19
|
+
VALID_PUPPET_VERSIONS = %w[6 7 8]
|
20
|
+
VALID_REPO_TYPES = %w[archive nightly stable]
|
21
|
+
end
|
data/lib/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: apt_stage_artifacts
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Puppet Release Engineering
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-06-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: pry
|
@@ -154,6 +154,7 @@ files:
|
|
154
154
|
- lib/apt_stage_artifacts.rb
|
155
155
|
- lib/apt_stage_from_tarball.rb
|
156
156
|
- lib/apt_update_freight_cache.rb
|
157
|
+
- lib/mixins/constants.rb
|
157
158
|
- lib/mixins/logging.rb
|
158
159
|
- lib/version.rb
|
159
160
|
homepage: https://github.com/puppetlabs/apt_stage_artifacts
|
@@ -162,7 +163,7 @@ metadata:
|
|
162
163
|
allowed_push_host: https://rubygems.org
|
163
164
|
homepage_uri: https://github.com/puppetlabs/apt_stage_artifacts
|
164
165
|
source_code_uri: https://github.com/puppetlabs/apt_stage_artifacts
|
165
|
-
changelog_uri: https://github.com/puppetlabs/apt_stage_artifacts/CHANGELOG.md
|
166
|
+
changelog_uri: https://github.com/puppetlabs/apt_stage_artifacts/blob/main/CHANGELOG.md
|
166
167
|
post_install_message:
|
167
168
|
rdoc_options: []
|
168
169
|
require_paths:
|