Skip to content

Commit

Permalink
Replace container creation with docker run script.
Browse files Browse the repository at this point in the history
Instead of pulling containers with bazel, simply mount the tar file on a vanilla image. This is much cleaner than the deprecated rules_docker.

Fixes #91.
  • Loading branch information
jarondl committed Feb 15, 2024
1 parent 0406c74 commit 2995b3e
Show file tree
Hide file tree
Showing 10 changed files with 2,588 additions and 179 deletions.
4 changes: 2 additions & 2 deletions MODULE.bazel
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module(
name = "rpmpack",
version = "0.6.0",
name = "rpmpack",
version = "0.6.0",
)

bazel_dep(name = "rules_go", version = "0.46.0")
Expand Down
13 changes: 11 additions & 2 deletions cmd/rpmsample/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
load("@rules_go//go:def.bzl", "go_binary", "go_library")
load("@rules_go//go:def.bzl", "go_binary", "go_cross_binary", "go_library")

go_library(
name = "rpmsample_lib",
Expand All @@ -9,7 +9,16 @@ go_library(
)

go_binary(
name = "rpmsample",
name = "rpmsample_bin",
embed = [":rpmsample_lib"],
visibility = ["//visibility:public"],
)

# This was the easiest way to get rid of libc mismatch errors.
# We run the tests on docker with older version of libc.
go_cross_binary(
name = "rpmsample",
platform = "@rules_go//go/toolchain:linux_amd64",
target = ":rpmsample_bin",
visibility = ["//visibility:public"],
)
1 change: 1 addition & 0 deletions example_bazel/.bazelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
common --enable_bzlmod
2 changes: 1 addition & 1 deletion example_bazel/.bazelversion
Original file line number Diff line number Diff line change
@@ -1 +1 @@
7.0.2
6.5.0
105 changes: 55 additions & 50 deletions example_bazel/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@
# For running basic build/run/test you can also use the regular go tools,
# this is currently added to assist in external testing.

load("@io_bazel_rules_docker//container:container.bzl", "container_image")
load("@rules_pkg//pkg:tar.bzl", "pkg_tar")
load("@rpmpack//:def.bzl", "pkg_tar2rpm")
load("@rules_pkg//pkg:tar.bzl", "pkg_tar")
load("//:testing.bzl", "docker_diff")

CENTOS_IMAGE = "centos@sha256:365fc7f33107869dfcf2b3ba220ce0aa42e16d3f8e8b3c21d72af1ee622f0cf0"

FEDORA_IMAGE = "fedora@sha256:3f3fc6a4714e44fae9147bc2b9542ac627491c13c4a3375e5066bdddc7710c9e"

pkg_tar(
name = "rpmtest-tar",
srcs = [":content1.txt"],
Expand Down Expand Up @@ -89,125 +92,121 @@ pkg_tar2rpm(
version = "1.2",
)

container_image(
name = "centos_with_rpm",
testonly = True,
base = "@centos//image",
directory = "/root/",
files = [
pkg_tar(
name = "rpms",
srcs = [
":rpmtest.rpm",
":rpmtest_bothdirs",
":rpmtest_with_prefixes",
":rpmtest_withonlyonedir",
":rpmtest_withoutbothdirs",
":rpmtest_withtime",
],
legacy_run_behavior = False,
)

docker_diff(
name = "centos_V",
base = ":centos_with_rpm",
cmd = "echo ===marker=== && rpm -i /root/rpmtest.rpm && rpm -Vv rpmtest",
golden = """
......... /var
......... /var/lib
......... /var/lib/rpmpack
......... /var/lib/rpmpack/content1.txt""",
image = CENTOS_IMAGE,
tar = ":rpms",
)

docker_diff(
name = "centos_ls",
base = ":centos_with_rpm",
cmd = "echo ===marker=== && rpm -i /root/rpmtest.rpm && ls -l /var/lib/rpmpack",
golden = """
total 4
-rw-r--r-- 1 root root 22 Jan 1 2000 content1.txt""",
image = CENTOS_IMAGE,
tar = ":rpms",
)

docker_diff(
name = "centos_preinst",
base = ":centos_with_rpm",
cmd = "echo ===marker=== && rpm -i /root/rpmtest.rpm && cat /tmp/preinst.txt",
golden = "This is preinst",
image = CENTOS_IMAGE,
tar = ":rpms",
)

docker_diff(
name = "centos_epoch",
base = ":centos_with_rpm",
cmd = "echo ===marker=== && rpm -i /root/rpmtest.rpm && rpm -q rpmtest --queryformat '%{EPOCH}\n'",
golden = "42",
image = CENTOS_IMAGE,
tar = ":rpms",
)

container_image(
name = "centos_with_rpmsample_executable",
testonly = True,
base = "@centos//image",
directory = "/root/",
files = ["@com_github_google_rpmpack//cmd/rpmsample"],
legacy_run_behavior = False,
pkg_tar(
name = "rpmsample_tar",
srcs = [
"@rpmpack//cmd/rpmsample",
],
)

docker_diff(
name = "centos_rpmsample_signed",
base = ":centos_with_rpmsample_executable",
cmd = "echo ===marker=== && /root/rpmsample -sign > /root/rpmsample.rpm && rpm --nosignature -i /root/rpmsample.rpm && rpm --nosignature -q rpmsample --queryformat '%{SIGPGP}\n'",
# "74686973206973206e6f742061207369676e6174757265" is "this is not a signature" in hex.
golden = "74686973206973206e6f742061207369676e6174757265",
image = CENTOS_IMAGE,
tar = ":rpmsample_tar",
)

docker_diff(
name = "centos_rpmsample_ghost_provides",
base = ":centos_with_rpmsample_executable",
cmd = "echo ===marker=== && /root/rpmsample > /root/rpmsample.rpm && rpm -i /root/rpmsample.rpm && rpm -q --whatprovides /var/lib/rpmpack/sample4_ghost.txt",
golden = "rpmsample-0.1-A.noarch",
image = CENTOS_IMAGE,
tar = ":rpmsample_tar",
)

docker_diff(
name = "centos_rpmsample_ghost_not_on_fs",
base = ":centos_with_rpmsample_executable",
cmd = "echo ===marker=== && /root/rpmsample > /root/rpmsample.rpm && rpm -i /root/rpmsample.rpm && ls /var/lib/rpmpack",
golden = """
sample.txt
sample2.txt
sample3_link.txt
""",
image = CENTOS_IMAGE,
tar = ":rpmsample_tar",
)

docker_diff(
name = "centos_rpmsample_directory_doesnotexist",
base = ":centos_with_rpmsample_executable",
cmd = "echo ===marker=== && /root/rpmsample > /root/rpmsample.rpm && rpm -i /root/rpmsample.rpm && cat /var/lib/thisdoesnotexist/sample.txt",
golden = """
testsample
""",
)

container_image(
name = "fedora_with_rpm",
testonly = True,
base = "@fedora//image",
directory = "/root/",
files = [":rpmtest.rpm"],
legacy_run_behavior = False,
image = CENTOS_IMAGE,
tar = ":rpmsample_tar",
)

docker_diff(
name = "fedora_V",
base = ":fedora_with_rpm",
cmd = "echo ===marker=== && rpm -i /root/rpmtest.rpm && rpm -Vv rpmtest",
golden = """
......... /var
......... /var/lib
......... /var/lib/rpmpack
......... /var/lib/rpmpack/content1.txt""",
image = FEDORA_IMAGE,
tar = ":rpms",
)

docker_diff(
name = "fedora_epoch",
base = ":fedora_with_rpm",
base = "fedora_with_rpm",
cmd = "echo ===marker=== && rpm -i /root/rpmtest.rpm && rpm -q rpmtest --queryformat '%{EPOCH}\n'",
golden = "42",
image = FEDORA_IMAGE,
tar = ":rpms",
)

pkg_tar(
Expand All @@ -224,55 +223,57 @@ pkg_tar2rpm(
version = "1.2",
)

container_image(
name = "centos_with_metarpm",
testonly = True,
base = "@centos//image",
directory = "/root/",
files = [":rpmmetatest.rpm"],
legacy_run_behavior = False,
pkg_tar(
name = "rpmmeta",
srcs = [
":rpmmetatest.rpm",
],
)

docker_diff(
name = "centos_meta_deps",
base = ":centos_with_metarpm",
cmd = "echo ===marker=== && rpm -i /root/rpmmetatest.rpm && rpm -qpR /root/rpmmetatest.rpm",
golden = "bash",
image = CENTOS_IMAGE,
tar = ":rpmmeta",
)

docker_diff(
name = "centos_with_prefixes_meta",
base = ":centos_with_rpm",
cmd = "echo ===marker=== && rpm -i /root/rpmtest_with_prefixes.rpm && rpm -q rpmtest_with_prefixes --queryformat '%{PREFIXES}\n'",
golden = "/var/lib",
image = CENTOS_IMAGE,
tar = ":rpms",
)

docker_diff(
name = "centos_with_prefixes_ls",
base = ":centos_with_rpm",
cmd = "echo ===marker=== && rpm -i --prefix=/opt /root/rpmtest_with_prefixes.rpm && rpm -Vv rpmtest_with_prefixes",
golden = """
......... /opt/rpmpack
......... /opt/rpmpack/content1.txt""",
image = CENTOS_IMAGE,
tar = ":rpms",
)

docker_diff(
name = "centos_empty_timestamp",
base = ":centos_with_rpm",
cmd = "echo ===marker=== && rpm -i /root/rpmtest.rpm && rpm -q rpmtest --queryformat '%{BUILDTIME}\n'",
golden = "(none)",
image = CENTOS_IMAGE,
tar = ":rpms",
)

docker_diff(
name = "centos_with_timestamp",
base = ":centos_with_rpm",
cmd = "echo ===marker=== && rpm -i /root/rpmtest_withtime.rpm && rpm -q rpmtest_withtime --queryformat '%{BUILDTIME}\n'",
golden = "17",
image = CENTOS_IMAGE,
tar = ":rpms",
)

docker_diff(
name = "centos_bothdirs",
base = ":centos_with_rpm",
cmd = "echo ===marker=== && rpm -i --force /root/rpmtest_bothdirs.rpm && rpm -Vv rpmtest_bothdirs",
golden = """
......... /doesnot
Expand All @@ -283,24 +284,28 @@ docker_diff(
......... /var/lib
......... /var/lib/rpmpack
......... /var/lib/rpmpack/content1.txt""",
image = CENTOS_IMAGE,
tar = ":rpms",
)

docker_diff(
name = "centos_withoutbothdirs",
base = ":centos_with_rpm",
cmd = "echo ===marker=== && rpm -i /root/rpmtest_withoutbothdirs.rpm && rpm -Vv rpmtest_withoutbothdirs",
golden = """
......... /doesnot/exist/rpmpack/content1.txt
......... /var/lib/rpmpack/content1.txt""",
image = CENTOS_IMAGE,
tar = ":rpms",
)

docker_diff(
name = "centos_withonlyonedir",
base = ":centos_with_rpm",
cmd = "echo ===marker=== && rpm -i /root/rpmtest_withonlyonedir.rpm && rpm -Vv rpmtest_withonlyonedir",
golden = """
......... /doesnot/exist
......... /doesnot/exist/rpmpack
......... /doesnot/exist/rpmpack/content1.txt
......... /var/lib/rpmpack/content1.txt""",
image = CENTOS_IMAGE,
tar = ":rpms",
)
12 changes: 6 additions & 6 deletions example_bazel/MODULE.bazel
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@

module(name = "rpmpack_example_bazel", version = "0.6.0")
module(
name = "rpmpack_example_bazel",
version = "0.6.0",
)

bazel_dep(name = "rpmpack", version = "0.6.0")

local_path_override(
module_name = "rpmpack",
path = "../",
module_name = "rpmpack",
path = "../",
)

bazel_dep(name = "rules_pkg", version = "0.10.0")

Loading

0 comments on commit 2995b3e

Please sign in to comment.