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

jool: T160: Added scripts to build jool package #346

Merged
merged 1 commit into from
May 2, 2023
Merged
Show file tree
Hide file tree
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
10 changes: 10 additions & 0 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,16 @@ RUN apt-get update && apt-get install -y \
libssl-dev \
libpcre3-dev

# debmake: a native Debian tool for preparing sources for packaging
RUN apt-get update && apt-get install -y \
debmake \
python3-debian

# Packages for jool
RUN apt-get update && apt-get install -y \
libnl-genl-3-dev \
libxtables-dev

# Allow password-less 'sudo' for all users in group 'sudo'
RUN sed "s/^%sudo.*/%sudo\tALL=(ALL) NOPASSWD:ALL/g" -i /etc/sudoers && \
echo "vyos_bld\tALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers && \
Expand Down
3 changes: 3 additions & 0 deletions packages/linux-kernel/Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ def pkgList = [

// Intel-QAT
['name': 'qat', 'buildCmd': 'cd ..; ./build-intel-qat.sh'],

// Jool
['name': 'jool', 'buildCmd': 'cd ..; ./build-jool.py'],
]

// Start package build using library function from https://github.com/vyos/vyos-build
Expand Down
94 changes: 94 additions & 0 deletions packages/linux-kernel/build-jool.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
#!/usr/bin/env python3
zdc marked this conversation as resolved.
Show resolved Hide resolved

from tomllib import loads as toml_loads
from requests import get
from pathlib import Path
from subprocess import run


# dependency modifier
def add_depends(package_dir: str, package_name: str,
depends: list[str]) -> None:
"""Add dependencies to a package

Args:
package_dir (str): a directory where package sources are located
package_name (str): a name of package
depends (list[str]): a list of dependencies to add
"""
depends_list: str = ', '.join(depends)
depends_line: str = f'misc:Depends={depends_list}\n'

substvars_file = Path(f'{package_dir}/debian/{package_name}.substvars')
substvars_file.write_text(depends_line)


# find kernel version and source path
defaults_file: str = Path('../../data/defaults.toml').read_text()
architecture_file: str = Path('../../data/architectures/amd64.toml').read_text()
KERNEL_VER: str = toml_loads(defaults_file).get('kernel_version')
KERNEL_FLAVOR: str = toml_loads(architecture_file).get('kernel_flavor')
KERNEL_SRC: str = Path.cwd().as_posix() + '/linux'

# define variables
PACKAGE_NAME: str = 'jool'
PACKAGE_VERSION: str = '4.1.9+bf4c7e3669'
PACKAGE_DIR: str = f'{PACKAGE_NAME}-{PACKAGE_VERSION}'
SOURCES_ARCHIVE: str = 'jool-4.1.9+bf4c7e3669.tar.gz'
SOURCES_URL: str = f'https://github.com/NICMx/Jool/archive/bf4c7e3669672367934dc50c8b257b7790f0e27e.tar.gz'
Copy link
Member

Choose a reason for hiding this comment

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

Is there a particular reason to use a commit tarball URL instead of a tag URL? Generally, a tag URL would look more obvious and easier to update.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For the history. It cannot be built without this. This is the reason why a specific commit-id is required.


# download sources
sources_archive = Path(SOURCES_ARCHIVE)
sources_archive.write_bytes(get(SOURCES_URL).content)

# prepare sources
debmake_cmd: list[str] = [
'debmake', '-e', '[email protected]', '-f', 'VyOS Support', '-p',
PACKAGE_NAME, '-u', PACKAGE_VERSION, '-a', SOURCES_ARCHIVE
]
run(debmake_cmd)

# add kernel to dependencies
add_depends(PACKAGE_DIR, PACKAGE_NAME,
[f'linux-image-{KERNEL_VER}-{KERNEL_FLAVOR}'])

# configure build rules
build_rules_text: str = f'''#!/usr/bin/make -f
# config
export KERNEL_DIR := {KERNEL_SRC}
PACKAGE_BUILD_DIR := debian/{PACKAGE_NAME}
KVER := {KERNEL_VER}-{KERNEL_FLAVOR}
MODULES_DIR := extra

# main packaging script based on dh7 syntax
%:
dh $@

override_dh_clean:
dh_clean --exclude=debian/{PACKAGE_NAME}.substvars

override_dh_prep:
dh_prep --exclude=debian/{PACKAGE_NAME}.substvars

# override_dh_auto_clean:
# make -C src/mod clean

override_dh_auto_build:
dh_auto_build $@
make -C ${{KERNEL_DIR}} M=$$PWD/src/mod/common modules
make -C ${{KERNEL_DIR}} M=$$PWD/src/mod/nat64 modules
make -C ${{KERNEL_DIR}} M=$$PWD/src/mod/siit modules

override_dh_auto_install:
dh_auto_install $@
install -D -m 644 src/mod/common/jool_common.ko ${{PACKAGE_BUILD_DIR}}/lib/modules/${{KVER}}/${{MODULES_DIR}}/jool_common.ko
install -D -m 644 src/mod/nat64/jool.ko ${{PACKAGE_BUILD_DIR}}/lib/modules/${{KVER}}/${{MODULES_DIR}}/jool.ko
install -D -m 644 src/mod/siit/jool_siit.ko ${{PACKAGE_BUILD_DIR}}/lib/modules/${{KVER}}/${{MODULES_DIR}}/jool_siit.ko

'''
bild_rules = Path(f'{PACKAGE_DIR}/debian/rules')
bild_rules.write_text(build_rules_text)

# build a package
debuild_cmd: list[str] = ['debuild']
run(debuild_cmd, cwd=PACKAGE_DIR)