rules_pkg icon indicating copy to clipboard operation
rules_pkg copied to clipboard

Provide deb package upload to ppa

Open daohu527 opened this issue 3 years ago • 4 comments

I learned that bazel can be packaged in deb format, can it be uploaded to the ppa repository currently?

daohu527 avatar May 16 '22 08:05 daohu527

Bazel releases are available. https://tracker.debian.org/teams/bazel/ We probably need an update, but you should ask that question in github.com/bazelbuild/bazel.

Is your question really, does rule_pkg provide an upload to ppa command? The answer to that is no. I'm not adverse to adding it, but I would like to see someone propose a robust design first before they try to implement it.

aiuto avatar May 16 '22 20:05 aiuto

@aiuto I may not have stated clearly, I want to use bazel to package other software and want to publish it to ppa repository.

I found some implementation

  1. use bzr builddeb -S to build a deb and use dput to upload to ppa repository link
  2. use dpkg -b to package or use debuild link

Packaging without uploads feels very incomplete and I'd love to have a discussion about it and make it happen

daohu527 avatar May 17 '22 00:05 daohu527

We have pkg_deb() to create the package, so the first part is done. It sounds like you want to build a wrapper around dput.

If you are interested in doing that, why don't you write a design (preferably Google Docs for easier commenting) for that and post to [email protected]. I don't use dput myself, so I won't be a the best sounding board, but we can find some people from Debian who could be reviewers.

aiuto avatar May 17 '22 02:05 aiuto

I have a similar need and an almost-working solution (you will still need a dput.cfg lying around):

# Rules for dealing with packaging
dput_script_template = """\
#!/bin/bash
set -eux

# Upload .change and .deb
dput --debug --config {dput_cfg} {repository} {changes_file}

# SSH to aptly and have it work with the file
ssh aptly1.example.com sudo -i /usr/sbin/parsechangesfile --repository={repository} --file={remote_changes_file}
"""

def _dput_impl(ctx):
    # Below, we ask for a 'OutputGroupInfo' provider, which we can query about both .deb and .changes files
    groupinfo = ctx.attr.package[OutputGroupInfo]
    changes_file = groupinfo.changes.to_list()[0]

    # Calculate remote path
    remote_path = "/var/lib/aptly/incoming/%s" % ctx.attr.repository
    remote_changes_file = "%s/%s" % (remote_path, changes_file.basename)

    script_content = dput_script_template.format(
        changes_file = changes_file.short_path,
        dput_cfg = ctx.file._dput_cfg.path,
        remote_changes_file = remote_changes_file,
        repository = ctx.attr.repository,
    )

    # Generate upload-script (ctx.outputs.executable is magic, seems to be implied by having `rule(executable = True)`
    ctx.actions.write(ctx.outputs.executable, script_content, is_executable = True)

    # We have to explicitly add the changes-file here, as it isn't included in ctx.files.package by default.
    runfiles = ctx.runfiles(files = ctx.files.package + ctx.files._dput_cfg + [changes_file])
    return [DefaultInfo(runfiles = runfiles)]

dput = rule(
    attrs = {
        "package": attr.label(
            doc = "Debian package to upload",
            mandatory = True,
            providers = [OutputGroupInfo],
        ),
        "repository": attr.string(
            default = "systems-testing",
            doc = "repository to upload to",
        ),
        "_dput_cfg": attr.label(
            allow_single_file = True,
            doc = "Dput configuration file",
            default = "dput.cfg",
        ),
    },
    implementation = _dput_impl,
    executable = True,
)
#BUILD.bazel
exports_files([
    "dput.cfg",  # Exported for use by dput()
])

Notes:

  • We only upload using scp and use few fancy dput-features, so theoretically a lot of the work could be internalized by internalizing the repository => remote path map and just scp <.deb> <.changes> <hostname>:<remote-path> the stuff. Then we could dump both dput.cfg and dput itself.
  • rant It took me quite a while to figure out using OutputGroupInfo to get to the .changes-file. I would've loved an example of doing that in a rule (would something like this be welcome in https://github.com/bazelbuild/rules_pkg/tree/main/examples/where_is_my_output?)
  • Also, I'm a occasional Bazel-user; this rule can probably be improved.

msiebuhr avatar Aug 02 '22 07:08 msiebuhr