Skip to content

Commit

Permalink
support forcing a rebuild of deb packages
Browse files Browse the repository at this point in the history
Signed-off-by: Adam Stokes <51892+adam-stokes@users.noreply.github.com>
  • Loading branch information
adam-stokes committed Nov 20, 2020
1 parent 5a9dfe0 commit 4550195
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 20 deletions.
38 changes: 22 additions & 16 deletions cilib/service/deb.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,20 +68,6 @@ def sync_from_upstream(self):
changelog_out = self.render(changelog_fn_tpl, changelog_context)
changelog_fn.write_text(changelog_out)

kube_git_version_fn = src_path / "DEBVERSION"
kube_git_version = textwrap.dedent(
"""KUBE_GIT_TREE_STATE=archive
KUBE_GIT_VERSION={}
KUBE_GIT_MAJOR={}
KUBE_GIT_MINOR={}
""".format(
f"v{str(k8s_major_minor)}",
k8s_major_minor.major,
k8s_major_minor.minor,
)
)
kube_git_version_fn.write_text(kube_git_version)

self.log(f"Committing {branch}")
self.deb_model.base.add(
[str(changelog_fn), str(kube_git_version_fn)], cwd=str(src_path)
Expand All @@ -91,7 +77,7 @@ def sync_from_upstream(self):
)
self.deb_model.base.push(ref=branch, cwd=str(src_path))

def sync_debs(self):
def sync_debs(self, force=False):
""" Builds latest deb from each major.minor and uploads to correct ppa"""
for _version in self.supported_versions:
exclude_pre = True
Expand All @@ -108,7 +94,8 @@ def sync_debs(self):
_version, exclude_pre
)
if (
not latest_deb_version
force
or not latest_deb_version
or semver.compare(str(latest_branch_version), latest_deb_version_mmp)
> 0
):
Expand All @@ -132,6 +119,22 @@ def bump_revision(self, **subprocess_kwargs):
"""Bumps upstream revision for builds"""
cmd_ok("dch -U 'Automated Build' -D focal", **subprocess_kwargs)

def write_debversion(self, latest_branch_version, src_path):
"""Writes out the DEBVERSION file to be used in building the deps"""
kube_git_version_fn = src_path / "DEBVERSION"
kube_git_version = textwrap.dedent(
"""KUBE_GIT_TREE_STATE=archive
KUBE_GIT_VERSION={}
KUBE_GIT_MAJOR={}
KUBE_GIT_MINOR={}
""".format(
f"v{str(latest_branche_version)}",
latest_branch_version.major,
latest_branch_version.minor,
)
)
kube_git_version_fn.write_text(kube_git_version)

def source(self, **subprocess_kwargs):
"""Builds the source deb package"""
cmd = ["dpkg-buildpackage", "-S", f"--sign-key={self.sign_key}"]
Expand Down Expand Up @@ -171,6 +174,9 @@ def build(self, latest_branch_version):
cwd=f"{tmpdir}/{self.deb_model.name}",
)
self.bump_revision(cwd=f"{tmpdir}/{self.deb_model.name}")
self.write_debversion(
latest_branch_version, src_path=Path(tmpdir) / self.deb_model.name
)
cmd_ok(
f"cp -a {tmpdir}/{self.deb_model.name}/* {self.upstream_model.name}/.",
shell=True,
Expand Down
5 changes: 5 additions & 0 deletions jobs/build-debs/run.sh.j2
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,18 @@ export LPCREDS=/root/lpcreds.ini
export DEBEMAIL="Kubernetes Engineering <k8s-team-ci@canonical.com>"
K8STEAMCI_GPG_KEY="{{ lookup('env', 'K8STEAMCI_GPG_KEY') }}"
DRY_RUN="{{ lookup('env', 'DRY_RUN') }}"
FORCE="{{ lookup('env', 'FORCE') }}"

OPTS="--sign-key $K8STEAMCI_GPG_KEY"

if [[ $DRY_RUN = "true" ]]; then
OPTS="$OPTS --dry-run"
fi

if [[ $FORCE = "true" ]]; then
OPTS="$OPTS --force"
fi

cd /root/jenkins

tox -e py3 --workdir .tox -- python jobs/sync-upstream/sync.py debs $OPTS
4 changes: 4 additions & 0 deletions jobs/ci-master.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@
name: DRY_RUN
default: false
description: dry-run nothing is actually done
- bool:
name: FORCE
default: false
description: force run regardless of condition


- parameter:
Expand Down
9 changes: 5 additions & 4 deletions jobs/sync-upstream/sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,8 @@ def ppas(dry_run):
@cli.command()
@click.option("--sign-key", help="GPG Sign key ID", required=True)
@click.option("--dry-run", is_flag=True)
def debs(sign_key, dry_run):
@click.option("--force", is_flag=True)
def debs(sign_key, dry_run, force):
"""Syncs debs"""
dryrun(dry_run)

Expand All @@ -249,21 +250,21 @@ def debs(sign_key, dry_run):
for _deb in debs_to_process:
deb_service_obj = DebService(_deb, kubernetes_repo, ppas, sign_key)
deb_service_obj.sync_from_upstream()
deb_service_obj.sync_debs()
deb_service_obj.sync_debs(force)

cri_tools = DebCriToolsRepoModel()
cri_tools_service_obj = DebCriToolsService(
cri_tools, InternalCriToolsRepoModel(), ppas, sign_key
)
cri_tools_service_obj.sync_from_upstream()
cri_tools_service_obj.sync_debs()
cri_tools_service_obj.sync_debs(force)

kubernetes_cni = DebKubernetesCniRepoModel()
kubernetes_cni_service_obj = DebCNIService(
kubernetes_cni, InternalCNIPluginsRepoModel(), ppas, sign_key
)
kubernetes_cni_service_obj.sync_from_upstream()
kubernetes_cni_service_obj.sync_debs()
kubernetes_cni_service_obj.sync_debs(force)


@cli.command()
Expand Down

0 comments on commit 4550195

Please sign in to comment.