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

feat: migrate to bzlmod #1640

Merged
merged 10 commits into from
Sep 13, 2024
Merged
Show file tree
Hide file tree
Changes from 9 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
2 changes: 1 addition & 1 deletion .bazelversion
Original file line number Diff line number Diff line change
@@ -1 +1 @@
6.3.2
7.2.0
4 changes: 2 additions & 2 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ jobs:

ci-images:
name: CI image tests
runs-on: ubuntu-20.04 # most compatible with debian 11
runs-on: distroless-ci-large-ubuntu-20.04 # most compatible with debian 11
steps:
- uses: actions/checkout@v4
- name: Mount bazel caches
Expand All @@ -76,7 +76,7 @@ jobs:
- name: Fetch
run: |
for i in $(seq 20); do
bazel --bazelrc=$GITHUB_WORKSPACE/.github/workflows/ci.bazelrc query $(bazel query 'attr(tags, "amd64", ...)') && break
bazel --bazelrc=$GITHUB_WORKSPACE/.github/workflows/ci.bazelrc cquery 'attr(tags, "amd64", ...)' && break
sleep 10;
done

Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/image-check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ jobs:
- name: Fetch
run: |
for i in $(seq 10); do
bazel --bazelrc=$GITHUB_WORKSPACE/.github/workflows/ci.bazelrc cquery 'kind(merge_providers, deps(kind(oci_image, ...)))' --output=label --config=release && break || sleep 20;
bazel --bazelrc=$GITHUB_WORKSPACE/.github/workflows/ci.bazelrc cquery 'attr(tags, "amd64", ...)' && break
sleep 10;
done

- name: Build all images
Expand Down
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
private/pkg/test/oci_image/*
2 changes: 1 addition & 1 deletion BUILD
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
load("//private/oci:defs.bzl", "sign_and_push_all")
load("//:checksums.bzl", "ARCHITECTURES", "BASE_ARCHITECTURES")
load("//base:distro.bzl", "DISTROS")
load("//private/oci:defs.bzl", "sign_and_push_all")

package(default_visibility = ["//visibility:public"])

Expand Down
51 changes: 51 additions & 0 deletions MODULE.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
"distroless"

module(name = "distroless")

bazel_dep(name = "bazel_skylib", version = "1.7.1")
bazel_dep(name = "aspect_bazel_lib", version = "2.7.9")
bazel_dep(name = "platforms", version = "0.0.10")
bazel_dep(name = "rules_go", version = "0.47.0")
bazel_dep(name = "gazelle", version = "0.38.0")
bazel_dep(name = "rules_pkg", version = "1.0.1")
bazel_dep(name = "rules_rust", version = "0.49.1")
bazel_dep(name = "container_structure_test", version = "1.16.0")
bazel_dep(name = "rules_oci", version = "1.7.5")
bazel_dep(name = "rules_distroless", version = "0.3.7")

### GO ####
go_deps = use_extension("@gazelle//:extensions.bzl", "go_deps")
go_deps.module(
path = "github.com/spdx/tools-golang",
sum = "h1:9B623Cfs+mclYK6dsae7gLSwuIBHvlgmEup87qpqsAQ=",
version = "v0.3.1-0.20230104082527-d6f58551be3f",
)
use_repo(go_deps, "com_github_spdx_tools_golang")

### JETTY ###
http_archive = use_repo_rule("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

http_archive(
name = "jetty",
add_prefix = "output",
build_file = "//java:BUILD.jetty",
sha256 = "b04b4cd45f3bf3c09a26bdf7f4e8d1a67e1a0f224ef4539534a0719b2c701088",
strip_prefix = "jetty-distribution-9.4.53.v20231009/",
urls = ["https://repo1.maven.org/maven2/org/eclipse/jetty/jetty-distribution/9.4.53.v20231009/jetty-distribution-9.4.53.v20231009.tar.gz"],
)

### BUSYBOX ###
busybox = use_extension("//private/extensions:busybox.bzl", "busybox")
busybox.archive()
use_repo(busybox, "busybox_amd64", "busybox_arm", "busybox_arm64", "busybox_ppc64le", "busybox_s390x")

### JAVA ###
include("//private/repos:java.MODULE.bazel")

### NODE ###
node = use_extension("//private/extensions:node.bzl", "node")
node.archive()
use_repo(node, "nodejs18_amd64", "nodejs18_arm", "nodejs18_arm64", "nodejs18_ppc64le", "nodejs18_s390x", "nodejs20_amd64", "nodejs20_arm", "nodejs20_arm64", "nodejs20_ppc64le", "nodejs20_s390x", "nodejs22_amd64", "nodejs22_arm", "nodejs22_arm64", "nodejs22_ppc64le", "nodejs22_s390x")

### DEBIAN ###
include("//private/repos/deb:deb.MODULE.bazel")
19,015 changes: 19,015 additions & 0 deletions MODULE.bazel.lock

Large diffs are not rendered by default.

147 changes: 0 additions & 147 deletions WORKSPACE
Original file line number Diff line number Diff line change
@@ -1,150 +1,3 @@
workspace(name = "distroless")

load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

# rules_distroless setup
http_archive(
name = "rules_distroless",
sha256 = "4e5973bb00d15e5344b71b8d759a2369401d193d2e1f5d4a56f66347fcfd5c89",
strip_prefix = "rules_distroless-0.3.2",
url = "https://github.com/GoogleContainerTools/rules_distroless/releases/download/v0.3.2/rules_distroless-v0.3.2.tar.gz",
)

load("@rules_distroless//distroless:dependencies.bzl", "distroless_dependencies")

distroless_dependencies()

load("@rules_distroless//distroless:toolchains.bzl", "distroless_register_toolchains")

distroless_register_toolchains()

# rules_oci setup
http_archive(
name = "rules_oci",
sha256 = "56d5499025d67a6b86b2e6ebae5232c72104ae682b5a21287770bd3bf0661abf",
strip_prefix = "rules_oci-1.7.5",
url = "https://github.com/bazel-contrib/rules_oci/releases/download/v1.7.5/rules_oci-v1.7.5.tar.gz",
)

load("@rules_oci//oci:dependencies.bzl", "rules_oci_dependencies")

rules_oci_dependencies()

load("@rules_oci//oci:repositories.bzl", "LATEST_CRANE_VERSION", "LATEST_ZOT_VERSION", "oci_register_toolchains")

oci_register_toolchains(
name = "oci",
crane_version = LATEST_CRANE_VERSION,
zot_version = LATEST_ZOT_VERSION,
)

load("@rules_oci//cosign:repositories.bzl", "cosign_register_toolchains")

cosign_register_toolchains(name = "oci_cosign")

# setup container_structure_test
http_archive(
name = "container_structure_test",
sha256 = "2da13da4c4fec9d4627d4084b122be0f4d118bd02dfa52857ff118fde88e4faa",
strip_prefix = "container-structure-test-1.16.0",
urls = ["https://github.com/GoogleContainerTools/container-structure-test/archive/v1.16.0.zip"],
)

load("@container_structure_test//:repositories.bzl", "container_structure_test_register_toolchain")

container_structure_test_register_toolchain(name = "cst")

# platforms
http_archive(
name = "platforms",
sha256 = "5308fc1d8865406a49427ba24a9ab53087f17f5266a7aabbfc28823f3916e1ca",
urls = [
"https://mirror.bazel.build/github.com/bazelbuild/platforms/releases/download/0.0.6/platforms-0.0.6.tar.gz",
"https://github.com/bazelbuild/platforms/releases/download/0.0.6/platforms-0.0.6.tar.gz",
],
)

# rules_go setup
# NOTE: cannot upgrade past v0.35.0 until https://github.com/bazelbuild/rules_go/issues/3531 is resolved.
http_archive(
name = "io_bazel_rules_go",
sha256 = "099a9fb96a376ccbbb7d291ed4ecbdfd42f6bc822ab77ae6f1b5cb9e914e94fa",
urls = [
"https://mirror.bazel.build/github.com/bazelbuild/rules_go/releases/download/v0.35.0/rules_go-v0.35.0.zip",
"https://github.com/bazelbuild/rules_go/releases/download/v0.35.0/rules_go-v0.35.0.zip",
],
)

load("@io_bazel_rules_go//go:deps.bzl", "go_register_toolchains", "go_rules_dependencies")

go_rules_dependencies()

go_register_toolchains(version = "1.19.1")

http_archive(
name = "bazel_gazelle",
sha256 = "29218f8e0cebe583643cbf93cae6f971be8a2484cdcfa1e45057658df8d54002",
urls = [
"https://mirror.bazel.build/github.com/bazelbuild/bazel-gazelle/releases/download/v0.32.0/bazel-gazelle-v0.32.0.tar.gz",
"https://github.com/bazelbuild/bazel-gazelle/releases/download/v0.32.0/bazel-gazelle-v0.32.0.tar.gz",
],
)

load("@bazel_gazelle//:deps.bzl", "gazelle_dependencies", "go_repository")

gazelle_dependencies()

go_repository(
name = "com_github_spdx_tools_golang",
importpath = "github.com/spdx/tools-golang",
sum = "h1:9B623Cfs+mclYK6dsae7gLSwuIBHvlgmEup87qpqsAQ=",
version = "v0.3.1-0.20230104082527-d6f58551be3f",
)

# Custom archives
load("//private/repos/deb:repositories.bzl", debian_repositories = "repositories")

debian_repositories()

load("//private/repos/deb:packages.bzl", debian_packages = "packages")

debian_packages()

load(":busybox_archives.bzl", busybox_repositories = "repositories")

busybox_repositories()

load(":node_archives.bzl", node_repositories = "repositories")

node_repositories()

load(":java_archives.bzl", java_repositories = "repositories")

java_repositories()

# rules_pkg setup
http_archive(
name = "rules_pkg",
sha256 = "8f9ee2dc10c1ae514ee599a8b42ed99fa262b757058f65ad3c384289ff70c4b8",
urls = [
"https://mirror.bazel.build/github.com/bazelbuild/rules_pkg/releases/download/0.9.1/rules_pkg-0.9.1.tar.gz",
"https://github.com/bazelbuild/rules_pkg/releases/download/0.9.1/rules_pkg-0.9.1.tar.gz",
],
)

load("@rules_pkg//:deps.bzl", "rules_pkg_dependencies")

rules_pkg_dependencies()

# rules_rust setup
http_archive(
name = "rules_rust",
sha256 = "9d04e658878d23f4b00163a72da3db03ddb451273eb347df7d7c50838d698f49",
urls = ["https://github.com/bazelbuild/rules_rust/releases/download/0.26.0/rules_rust-v0.26.0.tar.gz"],
)

load("@rules_rust//rust:repositories.bzl", "rust_register_toolchains", "rust_repositories")

rust_repositories(edition = "2021")

rust_register_toolchains()
2 changes: 1 addition & 1 deletion base/base.bzl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"defines a function to replicate the container images for different distributions"

load("@container_structure_test//:defs.bzl", "container_structure_test")
load("@io_bazel_rules_go//go:def.bzl", "go_binary")
load("@rules_go//go:def.bzl", "go_binary")
load("@rules_oci//oci:defs.bzl", "oci_image", "oci_image_index")
load("@rules_pkg//:pkg.bzl", "pkg_tar")
load("//:checksums.bzl", "ARCHITECTURES", "VARIANTS")
Expand Down
2 changes: 1 addition & 1 deletion examples/nonroot/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# reference only. Note that repo maintainers can freely change any part of the
# repository code at any time.
load("@container_structure_test//:defs.bzl", "container_structure_test")
load("@io_bazel_rules_go//go:def.bzl", "go_binary")
load("@rules_go//go:def.bzl", "go_binary")
load("@rules_distroless//distroless:defs.bzl", "home", "passwd")
load("@rules_oci//oci:defs.bzl", "oci_image")
load("@rules_pkg//:pkg.bzl", "pkg_tar")
Expand Down
2 changes: 1 addition & 1 deletion java/BUILD
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
load("@container_structure_test//:defs.bzl", "container_structure_test")
load("@java_versions//:versions.bzl", "JAVA_RELEASE_VERSIONS")
load("@rules_oci//oci:defs.bzl", "oci_image", "oci_image_index")
load("@rules_pkg//:pkg.bzl", "pkg_tar")
load("//:java_archives.bzl", "JAVA_RELEASE_VERSIONS")
load("//base:distro.bzl", "DISTROS")
load("//java:jre_ver.bzl", "jre_ver")
load("//private/oci:defs.bzl", "java_image")
Expand Down
69 changes: 0 additions & 69 deletions java_archives.bzl

This file was deleted.

File renamed without changes.
31 changes: 28 additions & 3 deletions busybox_archives.bzl → private/extensions/busybox.bzl
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
"repositories for busybox"
"busybox"

load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive", "http_file")
load("//experimental/busybox:commands.bzl", "BUSYBOX_ARCHIVE_BUILD")

def repositories():
"For the debug image"
def _busybox_impl(module_ctx):
mod = module_ctx.modules[0]

if len(module_ctx.modules) > 1:
fail("busybox.archive should be called only once")
if not mod.is_root:
fail("busybox.archive should be called from root module only.")

# To update amd64 busybox binary (#1014)
# Get the latest commit hash from dist-amd64 branch of docker-library repo. You can also view it
Expand Down Expand Up @@ -55,3 +60,23 @@ def repositories():
urls = ["https://github.com/docker-library/busybox/raw/aa059e43d48801abcb012dfa965a432fa12c385d/latest/musl/busybox.tar.xz"],
build_file_content = BUSYBOX_ARCHIVE_BUILD,
)

return module_ctx.extension_metadata(
root_module_direct_deps = [
"busybox_amd64",
"busybox_arm",
"busybox_arm64",
"busybox_s390x",
"busybox_ppc64le",
],
root_module_direct_dev_deps = [],
)

_archive = tag_class(attrs = {})

busybox = module_extension(
implementation = _busybox_impl,
tag_classes = {
"archive": _archive,
},
)
Loading
Loading