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

Fix for packages sharing the same dependencies #32

Merged
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
11 changes: 11 additions & 0 deletions WORKSPACE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,14 @@ deb_index(
load("@apt_security//:packages.bzl", "apt_security_packages")

apt_security_packages()

# bazel run @shared_dependencies//:lock
deb_index(
name = "shared_dependencies",
lock = "//examples/shared_dependencies:bullseye.lock.json",
manifest = "//examples/shared_dependencies:bullseye.yaml",
)

load("@shared_dependencies//:packages.bzl", "shared_dependencies_packages")

shared_dependencies_packages()
7 changes: 1 addition & 6 deletions apt/private/package_resolution.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def _resolve_package(state, name, version, arch):
package = state.index.package(name = name, version = version, arch = arch)
return package

def _resolve_all(state, name, version, arch, in_lock, include_transitive):
def _resolve_all(state, name, version, arch, include_transitive):
root_package = None
already_recursed = {}
unmet_dependencies = []
Expand All @@ -109,11 +109,6 @@ def _resolve_all(state, name, version, arch, in_lock, include_transitive):
# Set the root package
root_package = package

# PERF: If the lockfile has this package already, it means we did the transitive closure
# resolution already.
if in_lock(package["Package"], package["Version"]):
continue

key = "%s~~%s" % (package["Package"], package["Version"])

# If we encountered package before in the transitive closure, skip it
Expand Down
1 change: 0 additions & 1 deletion apt/private/resolve.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ def _deb_resolve_impl(rctx):
version = constraint["version"],
arch = arch,
include_transitive = rctx.attr.resolve_transitive,
in_lock = lambda name, version: lockf.has_package(name, version, arch),
)

if not package:
Expand Down
110 changes: 110 additions & 0 deletions examples/shared_dependencies/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
load("@aspect_bazel_lib//lib:tar.bzl", "tar")
load("@container_structure_test//:defs.bzl", "container_structure_test")
load("@rules_distroless//apt:defs.bzl", "dpkg_status")
load("@rules_distroless//distroless:defs.bzl", "group", "passwd")
load("@rules_oci//oci:defs.bzl", "oci_image", "oci_tarball")

passwd(
name = "passwd",
entries = [
{
"uid": 0,
"gid": 0,
"home": "/root",
"shell": "/bin/bash",
"username": "r00t",
},
{
"uid": 100,
"gid": 65534,
"home": "/home/_apt",
"shell": "/usr/sbin/nologin",
"username": "_apt",
},
],
)

group(
name = "group",
entries = [
{
"name": "root",
"gid": 0,
},
{
"name": "_apt",
"gid": 65534,
},
],
)

tar(
name = "sh",
mtree = [
# needed as dpkg assumes sh is installed in a typical debian installation.
"./bin/sh type=link link=/bin/bash",
],
)

PACKAGES = [
"@shared_dependencies//tzdata",
"@shared_dependencies//bash",
"@shared_dependencies//coreutils",
"@shared_dependencies//nginx-core",
]

# Creates /var/lib/dpkg/status with installed package information.
dpkg_status(
name = "dpkg_status",
controls = select({
"@platforms//cpu:arm64": [
"%s/arm64:control" % package
for package in PACKAGES
],
"@platforms//cpu:x86_64": [
"%s/amd64:control" % package
for package in PACKAGES
],
}),
)

oci_image(
name = "apt",
architecture = select({
"@platforms//cpu:arm64": "arm64",
"@platforms//cpu:x86_64": "amd64",
}),
os = "linux",
tars = [
":sh",
":passwd",
":group",
":dpkg_status",
] + select({
"@platforms//cpu:arm64": [
"%s/arm64" % package
for package in PACKAGES
],
"@platforms//cpu:x86_64": [
"%s/amd64" % package
for package in PACKAGES
],
}),
)

oci_tarball(
name = "tarball",
image = ":apt",
repo_tags = [
"distroless/test:latest",
],
)

container_structure_test(
name = "test",
configs = select({
"@platforms//cpu:arm64": ["test_linux_arm64.yaml"],
"@platforms//cpu:x86_64": ["test_linux_amd64.yaml"],
}),
image = ":apt",
)
Loading
Loading