Skip to content

Commit 4b6437c

Browse files
TUN-5943: Add RPM support
This PR extends release_pkgs.py to now also support uploading rpm based assets to R2. The packages are not signed yet and will be done in a subsequent PR. This PR - Packs the .rpm assets into relevant directories - Calls createrepo on them to make them yum repo ready - Uploads them to R2
1 parent f7fd4ea commit 4b6437c

File tree

3 files changed

+51
-3
lines changed

3 files changed

+51
-3
lines changed

Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,10 @@ github-release: cloudflared
261261
github-release-built-pkgs:
262262
python3 github_release.py --path $(PWD)/built_artifacts --release-version $(VERSION)
263263

264+
.PHONY: release-pkgs-linux
265+
release-pkgs-linux:
266+
python3 ./release_pkgs.py
267+
264268
.PHONY: github-message
265269
github-message:
266270
python3 github_message.py --release-version $(VERSION)

cfsetup.yaml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,19 @@ stretch: &stretch
4040
- libffi-dev
4141
- python3-setuptools
4242
- python3-pip
43+
- reprepro
44+
- createrepo
4345
pre-cache: &github_release_pkgs_pre_cache
4446
- wget https://github.com/sudarshan-reddy/msitools/releases/download/v0.101b/wixl -P /usr/local/bin
4547
- chmod a+x /usr/local/bin/wixl
4648
- pip3 install pynacl==1.4.0
4749
- pip3 install pygithub==1.55
50+
- pip3 install boto3==1.22.9
4851
post-cache:
4952
# build all packages (except macos and FIPS) and move them to /cfsetup/built_artifacts
5053
- ./build-packages.sh
54+
# publish packages to linux repos
55+
# TODO TUN-6180: Uncomment this - make release-pkgs-linux
5156
# release the packages built and moved to /cfsetup/built_artifacts
5257
- make github-release-built-pkgs
5358
# handle FIPS separately so that we built with gofips compiler
@@ -255,4 +260,4 @@ centos-7:
255260
- export PATH=$PATH:/usr/local/go/bin
256261
- export GOOS=linux
257262
- export GOARCH=amd64
258-
- make publish-rpm
263+
- make publish-rpm

release_pkgs.py

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import os
1313
import argparse
1414
import logging
15+
import shutil
1516
from hashlib import sha256
1617

1718
import boto3
@@ -100,13 +101,38 @@ def create_distribution_conf(self,
100101
"""
101102
def create_deb_pkgs(self, release, deb_file):
102103
self._clean_build_resources()
103-
subprocess.call(("reprepro", "includedeb", release, deb_file))
104+
subprocess.call(("reprepro", "includedeb", release, deb_file), timeout=120)
104105

105106
"""
106107
This is mostly useful to clear previously built db, dist and pool resources.
107108
"""
108109
def _clean_build_resources(self):
109-
subprocess.call(("reprepro", "clearvanished"))
110+
subprocess.call(("reprepro", "clearvanished"), timeout=120)
111+
112+
# TODO https://jira.cfops.it/browse/TUN-6209 : Sign these packages.
113+
def create_rpm_pkgs(self, artifacts_path):
114+
self._setup_rpm_pkg_directories(artifacts_path)
115+
subprocess.call(("createrepo", "./rpm"), timeout=120)
116+
117+
"""
118+
sets up the RPM directories in the following format:
119+
- rpm
120+
- aarch64
121+
- x86_64
122+
- 386
123+
124+
this assumes the assets are in the format <prefix>-<aarch64/x86_64/386>.rpm
125+
"""
126+
def _setup_rpm_pkg_directories(self, artifacts_path, archs=["aarch64", "x86_64", "386"]):
127+
for arch in archs:
128+
for root, _ , files in os.walk(artifacts_path):
129+
for file in files:
130+
if file.endswith(f"{arch}.rpm"):
131+
new_dir = f"./rpm/{arch}"
132+
os.makedirs(new_dir, exist_ok=True)
133+
old_path = os.path.join(root, file)
134+
new_path = os.path.join(new_dir, file)
135+
shutil.copyfile(old_path, new_path)
110136

111137
"""
112138
Walks through a directory and uploads it's assets to R2.
@@ -167,6 +193,17 @@ def create_deb_packaging(pkg_creator, pkg_uploader, releases, gpg_key_id, binary
167193
upload_from_directories(pkg_uploader, "dists", release_version, binary_name)
168194
upload_from_directories(pkg_uploader, "pool", release_version, binary_name)
169195

196+
def create_rpm_packaging(pkg_creator, pkg_uploader, artifacts_path, release_version, binary_name):
197+
print(f"creating rpm pkgs...")
198+
pkg_creator.create_rpm_pkgs(artifacts_path)
199+
200+
print("uploading latest to r2...")
201+
upload_from_directories(pkg_uploader, "rpm", None, binary_name)
202+
203+
print(f"uploading versioned release {release_version} to r2...")
204+
upload_from_directories(pkg_uploader, "rpm", release_version, binary_name)
205+
206+
170207
def parse_args():
171208
parser = argparse.ArgumentParser(
172209
description="Creates linux releases and uploads them in a packaged format"
@@ -223,3 +260,5 @@ def parse_args():
223260
pkg_uploader = PkgUploader(args.account, args.bucket, args.id, args.secret)
224261
create_deb_packaging(pkg_creator, pkg_uploader, args.deb_based_releases, args.gpg_key_id, args.binary,
225262
args.archs, "main", args.release_tag)
263+
264+
create_rpm_packaging(pkg_creator, pkg_uploader, "./built_artifacts", args.release_tag, args.binary )

0 commit comments

Comments
 (0)