From 77c63bdc2d7a5747093829b2bdc2ffa2d24ac2a5 Mon Sep 17 00:00:00 2001 From: James Munnelly Date: Mon, 10 Sep 2018 20:29:47 +0100 Subject: [PATCH] Add root Bazel build files Signed-off-by: James Munnelly --- .bazelrc | 2 + .gitignore | 2 + BUILD.bazel | 21 ++++++ WORKSPACE | 124 +++++++++++++++++++++++++++++++++ hack/BUILD.bazel | 44 ++++++++++++ hack/bin/BUILD.bazel | 52 ++++++++++++++ hack/boilerplate/BUILD.bazel | 15 ++++ hack/print-workspace-status.sh | 28 ++++++++ 8 files changed, 288 insertions(+) create mode 100644 .bazelrc create mode 100644 BUILD.bazel create mode 100644 WORKSPACE create mode 100644 hack/BUILD.bazel create mode 100644 hack/bin/BUILD.bazel create mode 100644 hack/boilerplate/BUILD.bazel create mode 100755 hack/print-workspace-status.sh diff --git a/.bazelrc b/.bazelrc new file mode 100644 index 00000000000..eaf07ee58e1 --- /dev/null +++ b/.bazelrc @@ -0,0 +1,2 @@ +# Include git version info +build --workspace_status_command hack/print-workspace-status.sh diff --git a/.gitignore b/.gitignore index c7c0fe07ad2..edf6b3486b4 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,5 @@ /controller /ingress-shim /hack/build/dockerfiles/cert-manager-*_*_* +.vscode +bazel-* diff --git a/BUILD.bazel b/BUILD.bazel new file mode 100644 index 00000000000..733472fbda4 --- /dev/null +++ b/BUILD.bazel @@ -0,0 +1,21 @@ +filegroup( + name = "package-srcs", + srcs = glob( + ["**"], + exclude = [ + "bazel-*/**", + ".git/**", + ], + ), + visibility = ["//visibility:private"], +) + +filegroup( + name = "all-srcs", + srcs = [ + ":package-srcs", + "//hack:all-srcs", + ], + tags = ["automanaged"], + visibility = ["//visibility:public"], +) diff --git a/WORKSPACE b/WORKSPACE new file mode 100644 index 00000000000..77d855210cd --- /dev/null +++ b/WORKSPACE @@ -0,0 +1,124 @@ +load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") +load("@bazel_tools//tools/build_defs/repo:git.bzl", "new_git_repository") + +## Load rules_go and dependencies +http_archive( + name = "io_bazel_rules_go", + urls = ["https://github.com/bazelbuild/rules_go/releases/download/0.15.3/rules_go-0.15.3.tar.gz"], + sha256 = "97cf62bdef33519412167fd1e4b0810a318a7c234f5f8dc4f53e2da86241c492", +) +load( + "@io_bazel_rules_go//go:def.bzl", + "go_rules_dependencies", + "go_register_toolchains", +) +go_rules_dependencies() + +go_register_toolchains( + go_version = "1.10.4", +) + +## Load gazelle and dependencies +http_archive( + name = "bazel_gazelle", + url = "https://github.com/bazelbuild/bazel-gazelle/releases/download/0.14.0/bazel-gazelle-0.14.0.tar.gz", + sha256 = "c0a5739d12c6d05b6c1ad56f2200cb0b57c5a70e03ebd2f7b87ce88cabf09c7b", +) +load( + "@bazel_gazelle//:deps.bzl", + "gazelle_dependencies", +) +gazelle_dependencies() + +## Load kubernetes repo-infra for tools like kazel +git_repository( + name = "io_kubernetes_build", + commit = "84d52408a061e87d45aebf5a0867246bdf66d180", + remote = "https://github.com/kubernetes/repo-infra.git", +) + +## Load rules_docker and depdencies, for working with docker images +git_repository( + name = "io_bazel_rules_docker", + remote = "https://github.com/bazelbuild/rules_docker.git", + tag = "v0.5.1", +) +load( + "@io_bazel_rules_docker//container:container.bzl", + "container_pull", + container_repositories = "repositories", +) +container_repositories() +load( + "@io_bazel_rules_docker//go:image.bzl", + _go_image_repos = "repositories", +) +_go_image_repos() + +## Pull some standard base images +container_pull( + name = "alpine", + registry = "gcr.io", + repository = "jetstack-build-infra/alpine", + tag = "3.7-v20180822-0201cfb11", +) + +## Fetch helm for use in template generation and testing +new_http_archive( + name = "helm_darwin", + sha256 = "7c4e6bfbc211d6b984ffb4fa490ce9ac112cc4b9b8d859ece27045b8514c1ed1", + urls = ["https://storage.googleapis.com/kubernetes-helm/helm-v2.10.0-darwin-amd64.tar.gz"], + build_file_content = +""" +filegroup( + name = "file", + srcs = [ + "darwin-amd64/helm", + ], + visibility = ["//visibility:public"], +) +""", +) +new_http_archive( + name = "helm_linux", + sha256 = "0fa2ed4983b1e4a3f90f776d08b88b0c73fd83f305b5b634175cb15e61342ffe", + urls = ["https://storage.googleapis.com/kubernetes-helm/helm-v2.10.0-linux-amd64.tar.gz"], + build_file_content = +""" +filegroup( + name = "file", + srcs = [ + "linux-amd64/helm", + ], + visibility = ["//visibility:public"], +) +""", +) + +## Install buildozer, for mass-editing BUILD files +http_file( + name = "buildozer_darwin", + executable = 1, + sha256 = "294357ff92e7bb36c62f964ecb90e935312671f5a41a7a9f2d77d8d0d4bd217d", + urls = ["https://github.com/bazelbuild/buildtools/releases/download/0.15.0/buildozer.osx"], +) +http_file( + name = "buildozer_linux", + executable = 1, + sha256 = "be07a37307759c68696c989058b3446390dd6e8aa6fdca6f44f04ae3c37212c5", + urls = ["https://github.com/bazelbuild/buildtools/releases/download/0.15.0/buildozer"], +) + +## Install dep for dependency management +http_file( + name = "dep_darwin", + executable = 1, + sha256 = "1a7bdb0d6c31ecba8b3fd213a1170adf707657123e89dff234871af9e0498be2", + urls = ["https://github.com/golang/dep/releases/download/v0.5.0/dep-darwin-amd64"], +) +http_file( + name = "dep_linux", + executable = 1, + sha256 = "287b08291e14f1fae8ba44374b26a2b12eb941af3497ed0ca649253e21ba2f83", + urls = ["https://github.com/golang/dep/releases/download/v0.5.0/dep-linux-amd64"], +) diff --git a/hack/BUILD.bazel b/hack/BUILD.bazel new file mode 100644 index 00000000000..e8e1081275e --- /dev/null +++ b/hack/BUILD.bazel @@ -0,0 +1,44 @@ +package(default_visibility = ["//visibility:public"]) + +py_test( + name = "verify-boilerplate", + main = "verify_boilerplate.py", + srcs = ["verify_boilerplate.py"], + data = ["//:all-srcs"], + tags = ["lint"], +) + +sh_test( + name = "verify-errexit", + srcs = ["verify-errexit.sh"], + data = [ + "//:all-srcs", + ], + tags = ["lint"], +) + +sh_test( + name = "verify-links", + srcs = ["verify-links.sh"], + data = [ + "//:all-srcs", + ], + tags = ["lint"], +) + +filegroup( + name = "package-srcs", + srcs = glob(["**"]), + tags = ["automanaged"], + visibility = ["//visibility:private"], +) + +filegroup( + name = "all-srcs", + srcs = [ + ":package-srcs", + "//hack/boilerplate:all-srcs", + ], + tags = ["automanaged"], + visibility = ["//visibility:public"], +) diff --git a/hack/bin/BUILD.bazel b/hack/bin/BUILD.bazel new file mode 100644 index 00000000000..def61596688 --- /dev/null +++ b/hack/bin/BUILD.bazel @@ -0,0 +1,52 @@ +genrule( + name = "fetch_helm", + srcs = select({ + ":darwin": ["@helm_darwin//:file"], + ":k8": ["@helm_linux//:file"], + }), + outs = ["helm"], + cmd = "cp $(SRCS) $@", + visibility = ["//visibility:public"], +) + +genrule( + name = "fetch_buildozer", + srcs = select({ + ":darwin": ["@buildozer_darwin//file"], + ":k8": ["@buildozer_linux//file"], + }), + outs = ["buildozer"], + cmd = "cp $(SRCS) $@", + visibility = ["//visibility:public"], +) + +genrule( + name = "fetch_kazel", + srcs = ["@io_kubernetes_build//kazel"], + outs = ["kazel"], + cmd = "cp $(SRCS) $@", + visibility = ["//visibility:public"], +) + +genrule( + name = "fetch_dep", + srcs = select({ + ":darwin": ["@dep_darwin//file"], + ":k8": ["@dep_linux//file"], + }), + outs = ["dep"], + cmd = "cp $(SRCS) $@", + visibility = ["//visibility:public"], +) + +config_setting( + name = "k8", + values = {"host_cpu": "k8"}, + visibility = ["//visibility:private"], +) + +config_setting( + name = "darwin", + values = {"host_cpu": "darwin"}, + visibility = ["//visibility:private"], +) diff --git a/hack/boilerplate/BUILD.bazel b/hack/boilerplate/BUILD.bazel new file mode 100644 index 00000000000..95a981ad877 --- /dev/null +++ b/hack/boilerplate/BUILD.bazel @@ -0,0 +1,15 @@ +exports_files(["boilerplate.go.txt"]) + +filegroup( + name = "package-srcs", + srcs = glob(["**"]), + tags = ["automanaged"], + visibility = ["//visibility:private"], +) + +filegroup( + name = "all-srcs", + srcs = [":package-srcs"], + tags = ["automanaged"], + visibility = ["//visibility:public"], +) diff --git a/hack/print-workspace-status.sh b/hack/print-workspace-status.sh new file mode 100755 index 00000000000..f240fc2d69c --- /dev/null +++ b/hack/print-workspace-status.sh @@ -0,0 +1,28 @@ +#!/bin/bash + +# Copyright 2018 The Jetstack cert-manager contributors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# The only argument this script should ever be called with is '--verify-only' + +set -o errexit +set -o nounset +set -o pipefail + +SCRIPT_ROOT=$(dirname ${BASH_SOURCE})/../.. + +# TODO: properly configure this file +cat <