Skip to content

Latest commit

 

History

History
 
 

package_manager

Examples

Downloading minimal python library packages from a snapshot of debian stretch.

dpkg_src and dpkg_list are repository rules, and therefore made to be used in the WORKSPACE.

First, set up the package source with dpkg_src rule. This example uses a snapshot of debian stretch from November 1st 2017. The rule outputs a file:Packages.json which contains a parsed and formatted Packages.gz for dpkg_list to consume.

dpkg_src(
    name = "debian_stretch",
    arch = "amd64",
    distro = "stretch",
    sha256 = "9aea0e4c9ce210991c6edcb5370cb9b11e9e554a0f563e7754a4028a8fd0cb73",
    snapshot = "20171101T160520Z",
    url = "http://snapshot.debian.org/archive",
)

You can also set up the package source using the full url for the Packages.gz file. The package_prefix is used to prepend to the value of Filename in the Packages.gz file. In the following example, if the value of Filename is pool/jdk1.8/b/bazel/bazel_0.7.0_amd64.deb, then the .deb artifact will later be downloaded from http://storage.googleapis.com/bazel-apt/pool/jdk1.8/b/bazel/bazel_0.7.0_amd64.deb.

dpkg_src(
    name = "bazel_apt",
    packages_gz_url = "http://storage.googleapis.com/bazel-apt/dists/stable/jdk1.8/binary-amd64/Packages.gz",
    package_prefix = "http://storage.googleapis.com/bazel-apt/",
    sha256 = "0fc4c6988ebf24705cfab0050cb5ad58e5b2aeb0e8cfb8921898a1809042416c",
)

You can now reference this dpkg_src rule when downloading packages in the dpkg_list rule. The dpkg_src rule will output a packages map in file:packages.bzl for you to access the .deb artifacts.

dpkg_list(
    name = "package_bundle",
    packages = [
        "libpython2.7-minimal",
        "python2.7-minimal",
        "libpython2.7-stdlib",
        "zlib1g",
    ],
    sources = [
        "@debian_stretch//file:Packages.json",
    ],
)

Finally, in a BUILD file, you can access the .deb files for rules that might require them. We reference the package map from the previous dpkg_list rule and access the packages.

load("@package_bundle//file:packages.bzl", "packages")

container_image(
    name = "python27",
    base = "//base:base",
    debs = [
        packages["zlib1g"],
        packages["python2.7-minimal"],
        packages["libpython2.7-minimal"],
        packages["libpython2.7-stdlib"],
    ],
    entrypoint = [
        "/usr/bin/python2.7",
    ],
    symlinks = {
        "/usr/bin/python": "/usr/bin/python2.7",
    },
)

Reference

dpkg_src

dpkg_src(name, url, arch, distro, snapshot, packages_gz_url, package_prefix, sha256, dpkg_parser)

A rule that downloads a Packages.gz snapshot file and parses it into a readable format for dpkg_list. It supports snapshots from http://snapshot.debian.org/. (You can find out more about the format and sources available there.) It also supports retrieving Packages.gz file from a given full url.

Either a set of {url, arch, distro, snapshot} or a set of {packages_gz_url, package_prefix} must be set.

Attributes
name

name, required

url

the base url of the package repository

The url that hosts snapshots of Packages.gz files.

arch

the target package architecture

distro

the name of the package distribution

Examples: wheezy, jessie, stretch-backports, etc.

snapshot

the snapshot date of the Packages.gz

Format: YYYYMMDDTHHMMSSZ. You can query a list of possible dates for snapshot.debian.org at http://snapshot.debian.org/archive/debian/?year=2009;month=10

packages_gz_url

the full url for the Packages.gz file

package_prefix

the prefix to prepend to the value of Filename in the Packages.gz file

sha256

the sha256 of the Packages.gz file, required

dpkg_parser

A binary that translates a Packages.gz file into a format readable by dpkg_list, required

dpkg_list

dpkg_list(name, packages, sources)

A rule that downloads .deb packages and makes them available in the WORKSPACE.

For a dpkg_list rule named package_bundle, packages can be used by loading load("@package_bundle//file:packages.bzl", "packages") into your BUILD file, then referencing the package with packages['packagename']

Attributes
name

name, required

packages

a string array of packages to download, required

The names of Debian packages that will be downloaded. You can optionally add =version to require a specific version.

sources

a list of outputs from dpkg_src, required

A list of snapshot sources that will be checked when downloading the package. If a package is present in multiple sources, the first source in the list will be chosen. This means security updates should be first.