Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update builder.py for Secure Package Verification #802

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 32 additions & 4 deletions kiwixbuild/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
target_steps,
)
from . import _global

import subprocess
import tarfile

class Builder:
def __init__(self):
Expand All @@ -32,6 +33,24 @@ def __init__(self):
)
self.targetDefs = config.add_targets(option("target"), self._targets)

def make_dist(self):
build_output_dir = "/path/to/build/output" # Replace with your actual output directory
tarball_path = "/path/to/output/kiwix.tar.gz" # Desired tarball location
Comment on lines +37 to +38
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hardcoded paths shouldn't be present in the final version of a PR

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i'll fix that

# Create the tarball
print(f"Creating tarball at {tarball_path}")
with tarfile.open(tarball_path, "w:gz") as tar:
tar.add(build_output_dir, arcname=os.path.basename(build_output_dir))
print(f"Tarball created successfully: {tarball_path}")
Comment on lines +39 to +43
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that this should be delegated to the subclasses of Builder (look at the make_dist() and _make_dist() methods in kiwix-build/kiwixbuild/dependencies/base.py). However the big problem here is that those methods don't return the paths of their artifacts.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i didn't look at the base.py file this being my first draft i was focusing on signing the tarballs that were being released, i'll move on focusing the verification of the tarballs


# Sign the tarball with GPG
print(f"Signing tarball {tarball_path}")
sig_command = ["gpg", "--detach-sign", tarball_path]
try:
subprocess.run(sig_command, check=True)
print(f"Signature created: {tarball_path}.sig")
except subprocess.CalledProcessError as e:
print(f"Error signing tarball: {e}")

def finalize_target_steps(self):
steps = []
for targetDef in self.targetDefs:
Expand Down Expand Up @@ -116,11 +135,20 @@ def build(self):
builder = get_target_step(builderDef)
if option("make_dist") and builderDef[1] == option("target"):
print("make dist {} ({}):".format(builder.name, builderDef[0]))
builder.make_dist()
try:
builder.make_dist()
print("Distribution tarball and signature created successfully.")
except AttributeError:
print(f"ERROR: The target {builder.name} does not implement make_dist().")
except Exception as e:
print(f"ERROR while creating tarball or signature: {e}")
continue
print("build {} ({}):".format(builder.name, builderDef[0]))
print(f"build {builder.name} ({builderDef[0]}):")
add_target_step(builderDef, builder)
builder.build()
try:
builder.build()
except Exception as e:
print(f"ERROR during build of {builder.name}: {e}")

def _get_packages(self):
packages_list = []
Expand Down