Skip to content

Commit

Permalink
Merge pull request #17 from jarondl/new_bazel
Browse files Browse the repository at this point in the history
Move bazel tests to a separate dir, update README with instructions.
  • Loading branch information
jarondl authored Sep 19, 2019
2 parents 6257bdc + 2c3ad8c commit ddaf72a
Show file tree
Hide file tree
Showing 13 changed files with 259 additions and 138 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@

/bazel-*
/example_bazel/bazel-*
7 changes: 5 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,8 @@ jobs:
- curl -L -o "bazel-installer" https://github.com/bazelbuild/bazel/releases/download/0.29.0/bazel-0.29.0-installer-linux-x86_64.sh
- bash bazel-installer --user
script:
- ~/bin/bazel build --curses=no //...
- ~/bin/bazel test --test_output=all --curses=no //...
- ~/bin/bazel build --curses=no //:all
- ~/bin/bazel test --test_output=all --curses=no //:all
- cd example_bazel
- ~/bin/bazel build --curses=no //:all
- ~/bin/bazel test --test_output=all --curses=no //:all
66 changes: 0 additions & 66 deletions BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,8 @@
# 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("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test")
load("@bazel_tools//tools/build_defs/pkg:pkg.bzl", "pkg_tar")
load("@bazel_gazelle//:def.bzl", "gazelle")
load("//:def.bzl", "pkg_tar2rpm")

# gazelle:prefix github.com/google/rpmpack
gazelle(name = "gazelle")
Expand Down Expand Up @@ -41,66 +38,3 @@ go_test(
embed = [":go_default_library"],
deps = ["@com_github_google_go_cmp//cmp:go_default_library"],
)

pkg_tar(
name = "rpmtest-tar",
srcs = ["//:testdata/content1.txt"],
mode = "0644",
ownername = "root.root",
package_dir = "var/lib/rpmpack",
)

pkg_tar2rpm(
name = "rpmtest",
data = ":rpmtest-tar",
pkg_name = "rpmtest",
release = "3.4",
version = "1.2",
prein = "echo \"This is preinst\" > /tmp/preinst.txt",
)

container_image(
name = "centos_with_rpm",
testonly = True,
base = "@centos//image",
directory = "/root/",
files = [":rpmtest.rpm"],
legacy_run_behavior = False,
)

container_image(
name = "centos_V",
testonly = True,
base = ":centos_with_rpm",
cmd = "echo ===marker=== && rpm -i /root/rpmtest.rpm && rpm -Vv rpmtest",
legacy_run_behavior = False,
)

container_image(
name = "centos_ls",
testonly = True,
base = ":centos_with_rpm",
cmd = "echo ===marker=== && rpm -i /root/rpmtest.rpm && ls -l /var/lib/rpmpack",
legacy_run_behavior = False,
)

container_image(
name = "centos_preinst",
testonly = True,
base = ":centos_with_rpm",
cmd = "echo ===marker=== && rpm -i /root/rpmtest.rpm && cat /tmp/preinst.txt",
legacy_run_behavior = False,
)

sh_test(
name = "docker_tests",
srcs = ["docker_tests.sh"],
data = [
":centos_V",
":centos_ls",
":centos_preinst",
":testdata/golden_V.txt",
":testdata/golden_ls.txt",
":testdata/golden_preinst.txt",
],
)
78 changes: 76 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ $ go get -u github.com/google/rpmpack/...

This will make the `tar2rpm` tool available in `${GOPATH}/bin`, which by default means `~/go/bin`.

## Usage
## Usage of the binary (tar2rpm)

`tar2rpm` takes a `tar` file (from `stdin` or a specified filename), and outputs an `rpm`.

Expand All @@ -35,6 +35,80 @@ Options:
the package version
```

## Usage of the library (rpmpack)

API documentation for `rpmpack` can be found in [![GoDoc](https://godoc.org/github.com/google/rpmpack?status.svg)](https://godoc.org/github.com/google/rpmpack).

```go
import "github.com/google/rpmpack"
...
r, err := rpmpack.NewRPM(rpmpack.RPMMetadata{Name: "example", Version: "3"})
if err != nil {
...
}
r.AddFile(rpmpack.RPMFile{
Name: "/usr/local/hello",
Body: []byte("content of the file"),
})
if err := r.Write(w); err != nil {
...
}
```

## Usage in the bazel build system (pkg_tar2rpm)

There is a working example inside [example_bazel](example_bazel/)

In `WORKSPACE`
```
load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository")
git_repository(
name = "rpmpack",
remote = "https://github.com/google/rpmpack.git",
branch = "master",
)
# The following will load the requirements to build rpmpack
http_archive(
name = "io_bazel_rules_go",
sha256 = "ae8c36ff6e565f674c7a3692d6a9ea1096e4c1ade497272c2108a810fb39acd2",
urls = ["https://github.com/bazelbuild/rules_go/releases/download/0.19.4/rules_go-0.19.4.tar.gz"],
)
http_archive(
name = "bazel_gazelle",
sha256 = "7fc87f4170011201b1690326e8c16c5d802836e3a0d617d8f75c3af2b23180c4",
urls = ["https://github.com/bazelbuild/bazel-gazelle/releases/download/0.18.2/bazel-gazelle-0.18.2.tar.gz"],
)
load("@com_github_google_rpmpack//:deps.bzl", "rpmpack_dependencies")
rpmpack_dependencies()
```

In `BUILD` or `BUILD.bazel`
```
load("@bazel_tools//tools/build_defs/pkg:pkg.bzl", "pkg_tar")
load("@com_github_google_rpmpack//:def.bzl", "pkg_tar2rpm")
pkg_tar(
name = "rpmtest-tar",
srcs = [":content1.txt"],
mode = "0644",
ownername = "root.root",
package_dir = "var/lib/rpmpack",
)
pkg_tar2rpm(
name = "rpmtest",
data = ":rpmtest-tar",
pkg_name = "rpmtest",
release = "3.4",
version = "1.2",
prein = "echo \"This is preinst\" > /tmp/preinst.txt",
)
```


## Features

- You put files into the rpm, so that rpm/yum will install them on a host.
Expand All @@ -52,7 +126,7 @@ Options:
- May easily wreak havoc on rpm based systems. It is surprisingly easy to cause
rpm to segfault on corrupt rpm files.
- Many features are missing.
- All of the artifactes are stored in memory, sometimes more than once.
- All of the artifacts are stored in memory, sometimes more than once.
- Less backwards compatible than `rpmbuild`.

## Philosophy
Expand Down
67 changes: 2 additions & 65 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -14,69 +14,6 @@ http_archive(
urls = ["https://github.com/bazelbuild/bazel-gazelle/releases/download/0.18.2/bazel-gazelle-0.18.2.tar.gz"],
)

http_archive(
name = "io_bazel_rules_docker",
sha256 = "e513c0ac6534810eb7a14bf025a0f159726753f97f74ab7863c650d26e01d677",
strip_prefix = "rules_docker-0.9.0",
urls = ["https://github.com/bazelbuild/rules_docker/archive/v0.9.0.tar.gz"],
)

load(
"@io_bazel_rules_docker//repositories:repositories.bzl",
container_repositories = "repositories",
)

container_repositories()

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

go_rules_dependencies()

go_register_toolchains()

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

gazelle_dependencies()

load(
"@io_bazel_rules_docker//repositories:deps.bzl",
container_deps = "deps",
)
load("//:deps.bzl", "rpmpack_dependencies")

container_deps()

load(
"@io_bazel_rules_docker//container:container.bzl",
"container_pull",
)

go_repository(
name = "com_github_pkg_errors",
importpath = "github.com/pkg/errors",
tag = "v0.8.1",
)

go_repository(
name = "com_github_google_go_cmp",
importpath = "github.com/google/go-cmp",
tag = "v0.2.0",
)

go_repository(
name = "com_github_cavaliercoder_go_cpio",
commit = "925f9528c45e",
importpath = "github.com/cavaliercoder/go-cpio",
)

go_repository(
name = "com_github_ulikunitz_xz",
importpath = "github.com/ulikunitz/xz",
tag = "v0.5.6",
)

container_pull(
name = "centos",
digest = "sha256:365fc7f33107869dfcf2b3ba220ce0aa42e16d3f8e8b3c21d72af1ee622f0cf0",
registry = "index.docker.io",
repository = "library/centos",
)
rpmpack_dependencies()
33 changes: 33 additions & 0 deletions deps.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
load("@io_bazel_rules_go//go:deps.bzl", "go_rules_dependencies", "go_register_toolchains")
load("@bazel_gazelle//:deps.bzl", "gazelle_dependencies", "go_repository")


def rpmpack_dependencies():
go_rules_dependencies()
go_register_toolchains()
gazelle_dependencies()


go_repository(
name = "com_github_pkg_errors",
importpath = "github.com/pkg/errors",
tag = "v0.8.1",
)

go_repository(
name = "com_github_google_go_cmp",
importpath = "github.com/google/go-cmp",
tag = "v0.2.0",
)

go_repository(
name = "com_github_cavaliercoder_go_cpio",
commit = "925f9528c45e",
importpath = "github.com/cavaliercoder/go-cpio",
)

go_repository(
name = "com_github_ulikunitz_xz",
importpath = "github.com/ulikunitz/xz",
tag = "v0.5.6",
)
70 changes: 70 additions & 0 deletions example_bazel/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# A build file for rpmpack.
# 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("@bazel_tools//tools/build_defs/pkg:pkg.bzl", "pkg_tar")
load("@com_github_google_rpmpack//:def.bzl", "pkg_tar2rpm")

pkg_tar(
name = "rpmtest-tar",
srcs = [":content1.txt"],
mode = "0644",
ownername = "root.root",
package_dir = "var/lib/rpmpack",
)

pkg_tar2rpm(
name = "rpmtest",
data = ":rpmtest-tar",
pkg_name = "rpmtest",
prein = "echo \"This is preinst\" > /tmp/preinst.txt",
release = "3.4",
version = "1.2",
)

container_image(
name = "centos_with_rpm",
testonly = True,
base = "@centos//image",
directory = "/root/",
files = [":rpmtest.rpm"],
legacy_run_behavior = False,
)

container_image(
name = "centos_V",
testonly = True,
base = ":centos_with_rpm",
cmd = "echo ===marker=== && rpm -i /root/rpmtest.rpm && rpm -Vv rpmtest",
legacy_run_behavior = False,
)

container_image(
name = "centos_ls",
testonly = True,
base = ":centos_with_rpm",
cmd = "echo ===marker=== && rpm -i /root/rpmtest.rpm && ls -l /var/lib/rpmpack",
legacy_run_behavior = False,
)

container_image(
name = "centos_preinst",
testonly = True,
base = ":centos_with_rpm",
cmd = "echo ===marker=== && rpm -i /root/rpmtest.rpm && cat /tmp/preinst.txt",
legacy_run_behavior = False,
)

sh_test(
name = "docker_tests",
srcs = ["docker_tests.sh"],
data = [
":centos_V",
":centos_ls",
":centos_preinst",
":golden_V.txt",
":golden_ls.txt",
":golden_preinst.txt",
],
)
Loading

0 comments on commit ddaf72a

Please sign in to comment.