Skip to content

Commit 8cdfb75

Browse files
ravanellijlebon
authored andcommitted
cmd-koji-upload: Add support for node-image
- cmd-koji-upload is tightly coupled to the Build class and cosalib internals, which makes supporting the new node-image layout challenging. This commit introduces a way to maintain compatibility with both the legacy and updated node-image styles for brew uploads. - This is a transitional fix — once the migration to Konflux is complete, this compatibility layer will no longer be necessary. Signed-off-by: Renata Ravanelli <[email protected]>
1 parent 3372dd8 commit 8cdfb75

File tree

1 file changed

+52
-20
lines changed

1 file changed

+52
-20
lines changed

src/cmd-koji-upload

+52-20
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,13 @@ def md5sum_file(path):
9797
return h.hexdigest()
9898

9999

100+
class RpmListType(IntEnum):
101+
COMMITMETA = 1
102+
EXTENSIONS = 2
103+
HOST = 3
104+
META = 4
105+
106+
100107
class Build(_Build):
101108
"""
102109
Koji implementation of Build.
@@ -113,12 +120,28 @@ class Build(_Build):
113120
"require_commit": True,
114121
"require_cosa": True,
115122
})
116-
_Build.__init__(self, **kwargs)
117-
self.version, self.release = self.build_id.split('-')
118-
self.name = f"{self.build_name}-{self.basearch}"
119-
self.source = self.get_meta_key(
120-
"meta", self.ckey("container-config-git"))
121-
self.host_rpms = self.get_rpm_list(RpmListType.HOST)
123+
if kwargs.get('node_image') is True:
124+
self.version = kwargs['build'].replace("-", ".")
125+
self.release = "0"
126+
self._build_dir = self.buildroot
127+
self._basearch = kwargs['arch']
128+
self.name = f"rhcos-{self.basearch}"
129+
self.source = "https://github.com/openshift/os"
130+
self.meta_file_path = f"{kwargs['buildroot']}/meta.json"
131+
self._found_files = {}
132+
self._build_json = {}
133+
with open(self.meta_file_path) as f:
134+
self._build_json['meta'] = json.load(f)
135+
# We use podman build, there is no need for host rpms
136+
self.host_rpms = ""
137+
else:
138+
_Build.__init__(self, **kwargs)
139+
self.version, self.release = self.build_id.split('-')
140+
self.name = f"{self.build_name}-{self.basearch}"
141+
self.source = self.get_meta_key(
142+
"meta", self.ckey("container-config-git"))
143+
self.host_rpms = self.get_rpm_list(RpmListType.HOST)
144+
122145
def __del__(self):
123146
try:
124147
shutil.rmtree(self._tmpdir)
@@ -388,11 +411,6 @@ def kinit(keytab, principle):
388411
except Exception as err:
389412
raise Exception("failed to auth: ", err)
390413

391-
class RpmListType(IntEnum):
392-
COMMITMETA = 1
393-
EXTENSIONS = 2
394-
HOST = 3
395-
META = 4
396414

397415
class _KojiBase():
398416
"""
@@ -561,7 +579,11 @@ class Reserve(_KojiBase):
561579
'token': koji_reservation['token'],
562580
'release': build.release
563581
}
564-
build.meta_write()
582+
if hasattr(build, 'meta_file_path') and build.meta_file_path:
583+
with open(build.meta_file_path, "w") as f:
584+
json.dump(build.meta, f, indent=2)
585+
else:
586+
build.meta_write()
565587

566588

567589
class Upload(_KojiBase):
@@ -745,9 +767,16 @@ class Upload(_KojiBase):
745767
'public-url': self._s3_url
746768
}
747769
self.build.meta_write()
770+
if 'origin' in self.build.source:
771+
source = self.build.source['origin']
772+
commit = self.build.source['commit']
773+
meta = False
774+
else:
775+
source = self.build.source
776+
commit = ""
777+
meta = True
748778

749-
750-
log.debug(f"Preparing manifest for {(len(self.image_files))} files")
779+
log.debug(f"Preparing manifest for {(len(self.get_image_files(meta=meta)))} files")
751780
# The koji/brew NVR is constructed like so:
752781
# Name = "rhcos-$arch", like `rhcos-x86_64`
753782
# Version = Everything before `-` in RHCOS version
@@ -773,7 +802,7 @@ class Upload(_KojiBase):
773802
"name": self.build.name,
774803
"release": self.build.release,
775804
"owner": self._owner,
776-
"source": self.build.source['origin'],
805+
"source": source,
777806
"start_time": stamp,
778807
"version": self.build.version
779808
},
@@ -785,7 +814,7 @@ class Upload(_KojiBase):
785814
},
786815
"content_generator": {
787816
"name": "coreos-assembler",
788-
"version": self.build.source['commit']
817+
"version": commit
789818
},
790819
"container": {
791820
"type": "docker",
@@ -803,11 +832,11 @@ class Upload(_KojiBase):
803832
"tools": [
804833
{
805834
"name": "coreos-assembler",
806-
"version": self.build.source['commit']
835+
"version": commit
807836
}
808837
]
809838
}],
810-
"output": self.image_files
839+
"output": self.get_image_files(meta=meta)
811840
}
812841

813842
return self._manifest
@@ -960,7 +989,9 @@ Environment variables are supported:
960989
help="Do not upload, just parse the build")
961990
parent_parser.add_argument("--arch", default=get_basearch(),
962991
help="Set the build architecture")
963-
992+
# Node image sytle update
993+
parent_parser.add_argument("--node-image", action='store_true', required=False,
994+
help="Brew uploads for node image sytle")
964995
# Koji specific options
965996
parent_parser.add_argument("--no-auth", action='store_false', dest="auth",
966997
help="Skip Kerberos auth, use if already auth'd")
@@ -1043,7 +1074,8 @@ Environment variables are supported:
10431074

10441075
args = parser.parse_args(namespace=args)
10451076

1046-
build = Build(buildroot=args.buildroot, build=args.build, arch=args.arch)
1077+
build = Build(buildroot=args.buildroot, build=args.build, arch=args.arch,
1078+
node_image=args.node_image)
10471079

10481080
if args.auth:
10491081
kinit(args.keytab, args.owner)

0 commit comments

Comments
 (0)