Skip to content

Commit

Permalink
Add bazel BUILD and WORKSPACE files
Browse files Browse the repository at this point in the history
  • Loading branch information
Artyom Lukianov committed Feb 17, 2019
1 parent f5b58e7 commit 9e9e366
Show file tree
Hide file tree
Showing 122 changed files with 4,182 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,4 @@ tools/vms-generator/vms-generator
.coverprofile
coverage.html
manifests/**/*.tmp
bazel-*
159 changes: 159 additions & 0 deletions BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
load("@bazel_gazelle//:def.bzl", "gazelle")

gazelle(
name = "gazelle",
prefix = "kubevirt.io",
)

genrule(
name = "get-version",
srcs = [],
outs = [".version"],
cmd = "grep ^STABLE_BUILD_SCM_REVISION bazel-out/stable-status.txt | cut -d' ' -f2 >$@",
stamp = 1,
visibility = ["//visibility:public"],
)

genrule(
name = "libvirt-shared-libs",
srcs = ["@libvirt_libs//file"],
outs = [
"libvirt.so.0.5000.0",
"libvirt-lxc.so.0.5000.0",
"libvirt-qemu.so.0.5000.0",
],
cmd = "\n".join([
"rpm2archive $(location @libvirt_libs//file)",
"tar -xzf $(location @libvirt_libs//file).tgz",
"cp -R usr/lib64/*.so.0.5000.0 $(@D)",
]),
)

cc_library(
name = "libvirt-libs",
srcs = [
":libvirt-shared-libs",
],
visibility = ["//visibility:public"],
)

genrule(
name = "libvirt-devel-headers",
srcs = ["@libvirt_devel//file"],
outs = [
"libvirt/libvirt-admin.h",
"libvirt/libvirt-common.h",
"libvirt/libvirt-domain.h",
"libvirt/libvirt-domain-snapshot.h",
"libvirt/libvirt-event.h",
"libvirt/libvirt.h",
"libvirt/libvirt-host.h",
"libvirt/libvirt-interface.h",
"libvirt/libvirt-lxc.h",
"libvirt/libvirt-network.h",
"libvirt/libvirt-nodedev.h",
"libvirt/libvirt-nwfilter.h",
"libvirt/libvirt-qemu.h",
"libvirt/libvirt-secret.h",
"libvirt/libvirt-storage.h",
"libvirt/libvirt-stream.h",
"libvirt/virterror.h",
],
cmd = "\n".join([
"rpm2archive $(location @libvirt_devel//file)",
"tar -xzf $(location @libvirt_devel//file).tgz",
"cp -R usr/include/libvirt $(@D)",
]),
)

cc_library(
name = "libvirt-headers",
hdrs = [
":libvirt-devel-headers",
],
visibility = ["//visibility:public"],
)

load("@io_bazel_rules_docker//contrib:passwd.bzl", "passwd_entry", "passwd_file")
load("@bazel_tools//tools/build_defs/pkg:pkg.bzl", "pkg_tar")

passwd_entry(
name = "nonroot-user",
home = "/home/nonroot-user",
shell = "/bin/bash",
uid = 1001,
gid = 1001,
username = "nonroot-user",
)

passwd_file(
name = "passwd",
entries = [
":nonroot-user",
],
)

pkg_tar(
name = "passwd-tar",
srcs = [":passwd"],
mode = "0644",
package_dir = "etc",
visibility = ["//visibility:public"],
)

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

container_image(
name = "passwd-image",
base = "@fedora//image",
tars = [":passwd-tar"],
user = "1001",
visibility = ["//visibility:public"],
)

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

config_setting(
name = "release",
values = {"define": "release=true"},
)

container_bundle(
name = "build-images",
images = {
# cmd images
"$(container_prefix)/container-disk-v1alpha:$(container_tag)": "//cmd/container-disk-v1alpha:container-disk-v1alpha-image",
"$(container_prefix)/example-hook-sidecar:$(container_tag)": "//cmd/example-hook-sidecar:example-hook-sidecar-image",
"$(container_prefix)/subresource-access-test:$(container_tag)": "//cmd/subresource-access-test:subresource-access-test-image",
"$(container_prefix)/virt-controller:$(container_tag)": "//cmd/virt-controller:virt-controller-image",
"$(container_prefix)/virt-launcher:$(container_tag)": "//cmd/virt-launcher:virt-launcher-image",
"$(container_prefix)/virt-handler:$(container_tag)": "//cmd/virt-handler:virt-handler-image",
"$(container_prefix)/virt-api:$(container_tag)": "//cmd/virt-api:virt-api-image",
"$(container_prefix)/virt-operator:$(container_tag)": "//cmd/virt-operator:virt-operator-image",
# container-disk images
"$(container_prefix)/alpine-container-disk-demo:$(container_tag)": "//cmd/container-disk-v1alpha:alpine-container-disk-image",
"$(container_prefix)/cirros-container-disk-demo:$(container_tag)": "//cmd/container-disk-v1alpha:cirros-container-disk-image",
"$(container_prefix)/fedora-cloud-container-disk-demo:$(container_tag)": "//cmd/container-disk-v1alpha:fedora-cloud-container-disk-image",
"$(container_prefix)/virtio-container-disk:$(container_tag)": "//cmd/container-disk-v1alpha:virtio-container-disk-image",
# testing images
"$(container_prefix)/disks-images-provider:$(container_tag)": "//images/disks-images-provider:disks-images-provider-image",
"$(container_prefix)/cdi-http-import-server:$(container_tag)": "//images/cdi-http-import-server:cdi-http-import-server-image",
"$(container_prefix)/vm-killer:$(container_tag)": "//images/vm-killer:vm-killer-image",
"$(container_prefix)/winrmcli:$(container_tag)": "//images/winrmcli:winrmcli-image",
},
)

load("@io_bazel_rules_docker//contrib:push-all.bzl", "docker_push")

docker_push(
name = "push-images",
bundle = ":build-images",
)
142 changes: 142 additions & 0 deletions WORKSPACE
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
load(
"@bazel_tools//tools/build_defs/repo:http.bzl",
"http_archive",
"http_file",
)

# Additional bazel rules
http_archive(
name = "io_bazel_rules_go",
url = "https://github.com/bazelbuild/rules_go/releases/download/0.16.5/rules_go-0.16.5.tar.gz",
sha256 = "7be7dc01f1e0afdba6c8eb2b43d2fa01c743be1b9273ab1eaf6c233df078d705",
)

http_archive(
name = "bazel_gazelle",
urls = ["https://github.com/bazelbuild/bazel-gazelle/releases/download/0.16.0/bazel-gazelle-0.16.0.tar.gz"],
sha256 = "7949fc6cc17b5b191103e97481cf8889217263acf52e00b560683413af204fcb",
)

load(
"@bazel_tools//tools/build_defs/repo:git.bzl",
"git_repository",
)

git_repository(
name = "io_bazel_rules_docker",
remote = "https://github.com/bazelbuild/rules_docker.git",
tag = "v0.5.1",
)

# Libvirt dependencies
http_file(
name = "libvirt_libs",
urls = [
"https://libvirt.org/sources/libvirt-libs-5.0.0-1.fc28.x86_64.rpm",
],
sha256 = "95d317fd645fb52745d642578263a9bcb0d796beadf00aeadebc0d692f5529ba",
)

http_file(
name = "libvirt_devel",
urls = [
"https://libvirt.org/sources/libvirt-devel-5.0.0-1.fc28.x86_64.rpm",
],
sha256 = "6573a047d777ed00f6858c2e75c780053b1f898ae1c3f7415e991c94c5ccdd70",
)

# Disk images
http_file(
name = "alpine_image",
urls = [
"http://dl-cdn.alpinelinux.org/alpine/v3.7/releases/x86_64/alpine-virt-3.7.0-x86_64.iso",
],
sha256 = "5a4b2588afd32e7024dd61d9558b77b03a4f3189cb4c9fc05e9e944fb780acdd",
)

http_file(
name = "cirros_image",
urls = [
"https://download.cirros-cloud.net/0.4.0/cirros-0.4.0-x86_64-disk.img",
],
sha256 = "a8dd75ecffd4cdd96072d60c2237b448e0c8b2bc94d57f10fdbc8c481d9005b8",
)

http_file(
name = "fedora_image",
urls = [
"https://download.fedoraproject.org/pub/fedora/linux/releases/29/Cloud/x86_64/images/Fedora-Cloud-Base-29-1.2.x86_64.qcow2",
],
sha256 = "a30549d620bf6bf41d30a9a58626e59dfa70bb011fd7d50f6c4511ad2e479a39",
)

http_file(
name = "virtio_win_image",
urls = [
"https://fedorapeople.org/groups/virt/virtio-win/direct-downloads/stable-virtio/virtio-win.iso",
],
sha256 = "43c969f99b02ec6467ecb1f6d93689327a248cfa8de9c4b34d65b6b41e7bc556",
)

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

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

# Winrmcli dependencies
go_repository(
name = "com_github_masterzen_winrmcli",
commit = "c85a68ee8b6e3ac95af2a5fd62d2f41c9e9c5f32",
importpath = "github.com/masterzen/winrm-cli",
)

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

# Pull base image fedora28
container_pull(
name = "fedora",
registry = "index.docker.io",
repository = "library/fedora",
digest = "sha256:57d86e03971841e79585379f8346289ceb5a3e8ee06933fbd5064b4f004659d1",
#tag = "28",
)

# Pull base image libvirt
container_pull(
name = "libvirt",
registry = "index.docker.io",
repository = "alukiano/libvirt",
digest = "sha256:23cb9e64909fb9519d1b256ceefc546deb3eb81ccbe7e83c3ef461a7cd2b3da9",
#tag = "4.9.0",
)

# Pull base image cdi-http-import-server
container_pull(
name = "cdi-http-import-server-base",
registry = "index.docker.io",
repository = "kubevirt/cdi-http-import-server-base",
digest = "sha256:7cf1dd568d853884e558f714a24566682c091ff783495cccac0349e82c8a874f",
#tag = "28",
)

load(
"@io_bazel_rules_docker//go:image.bzl",
_go_image_repos = "repositories",
)
_go_image_repos()
Loading

0 comments on commit 9e9e366

Please sign in to comment.