|
| 1 | +# The WORKSPACE file tells Bazel that this directory is a "workspace", which is like a project root. |
| 2 | +# The content of this file specifies all the external dependencies Bazel needs to perform a build. |
| 3 | + |
| 4 | +#################################### |
| 5 | +# ESModule imports (and TypeScript imports) can be absolute starting with the workspace name. |
| 6 | +# The name of the workspace should match the npm package where we publish, so that these |
| 7 | +# imports also make sense when referencing the published package. |
| 8 | +workspace( |
| 9 | + name = "angular_bazel_example", |
| 10 | + managed_directories = {"@npm": ["node_modules"]}, |
| 11 | +) |
| 12 | + |
| 13 | +# These rules are built-into Bazel but we need to load them first to download more rules |
| 14 | +load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository") |
| 15 | +load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") |
| 16 | + |
| 17 | +# Fetch rules_nodejs so we can install our npm dependencies |
| 18 | +http_archive( |
| 19 | + name = "build_bazel_rules_nodejs", |
| 20 | + sha256 = "0d9660cf0894f1fe1e9840818553e0080fbce0851169812d77a70bdb9981c946", |
| 21 | + urls = ["https://github.com/bazelbuild/rules_nodejs/releases/download/0.37.0/rules_nodejs-0.37.0.tar.gz"], |
| 22 | +) |
| 23 | + |
| 24 | +# Fetch sass rules for compiling sass files |
| 25 | +http_archive( |
| 26 | + name = "io_bazel_rules_sass", |
| 27 | + sha256 = "4f05239080175a3f4efa8982d2b7775892d656bb47e8cf56914d5f9441fb5ea6", |
| 28 | + strip_prefix = "rules_sass-86ca977cf2a8ed481859f83a286e164d07335116", |
| 29 | + url = "https://github.com/bazelbuild/rules_sass/archive/86ca977cf2a8ed481859f83a286e164d07335116.zip", |
| 30 | +) |
| 31 | + |
| 32 | +# Check the bazel version and download npm dependencies |
| 33 | +load("@build_bazel_rules_nodejs//:defs.bzl", "check_bazel_version", "yarn_install") |
| 34 | + |
| 35 | +# Bazel version must be at least the following version because: |
| 36 | +# - 0.27.0 Adds managed directories support |
| 37 | +check_bazel_version( |
| 38 | + message = """ |
| 39 | +You no longer need to install Bazel on your machine. |
| 40 | +Angular has a dependency on the @bazel/bazel package which supplies it. |
| 41 | +Try running `yarn bazel` instead. |
| 42 | + (If you did run that, check that you've got a fresh `yarn install`) |
| 43 | +
|
| 44 | +""", |
| 45 | + minimum_bazel_version = "0.27.0", |
| 46 | +) |
| 47 | + |
| 48 | +# Setup the Node.js toolchain & install our npm dependencies into @npm |
| 49 | +yarn_install( |
| 50 | + name = "npm", |
| 51 | + package_json = "//:package.json", |
| 52 | + yarn_lock = "//:yarn.lock", |
| 53 | +) |
| 54 | + |
| 55 | +# Install all bazel dependencies of our npm packages |
| 56 | +load("@npm//:install_bazel_dependencies.bzl", "install_bazel_dependencies") |
| 57 | + |
| 58 | +install_bazel_dependencies() |
| 59 | + |
| 60 | +# Load npm_bazel_protractor dependencies |
| 61 | +load("@npm_bazel_protractor//:package.bzl", "npm_bazel_protractor_dependencies") |
| 62 | + |
| 63 | +npm_bazel_protractor_dependencies() |
| 64 | + |
| 65 | +# Load npm_bazel_karma dependencies |
| 66 | +load("@npm_bazel_karma//:package.bzl", "rules_karma_dependencies") |
| 67 | + |
| 68 | +rules_karma_dependencies() |
| 69 | + |
| 70 | +# Setup the rules_webtesting toolchain |
| 71 | +load("@io_bazel_rules_webtesting//web:repositories.bzl", "web_test_repositories") |
| 72 | + |
| 73 | +web_test_repositories() |
| 74 | + |
| 75 | +# Temporary work-around for https://github.com/angular/angular/issues/28681 |
| 76 | +# TODO(gregmagolan): go back to @io_bazel_rules_webtesting browser_repositories |
| 77 | +load("@npm_bazel_karma//:browser_repositories.bzl", "browser_repositories") |
| 78 | + |
| 79 | +browser_repositories() |
| 80 | + |
| 81 | +# Setup the rules_typescript tooolchain |
| 82 | +load("@npm_bazel_typescript//:defs.bzl", "ts_setup_workspace") |
| 83 | + |
| 84 | +ts_setup_workspace() |
| 85 | + |
| 86 | +# Setup the rules_sass toolchain |
| 87 | +load("@io_bazel_rules_sass//sass:sass_repositories.bzl", "sass_repositories") |
| 88 | + |
| 89 | +sass_repositories() |
| 90 | + |
| 91 | +################################ |
| 92 | +# Support for Remote Execution # |
| 93 | +################################ |
| 94 | + |
| 95 | +http_archive( |
| 96 | + name = "bazel_toolchains", |
| 97 | + sha256 = "88e818f9f03628eef609c8429c210ecf265ffe46c2af095f36c7ef8b1855fef5", |
| 98 | + strip_prefix = "bazel-toolchains-92dd8a7", |
| 99 | + urls = [ |
| 100 | + "https://github.com/bazelbuild/bazel-toolchains/archive/92dd8a7.zip", |
| 101 | + ], |
| 102 | +) |
| 103 | + |
| 104 | +#################################################### |
| 105 | +# Support creating Docker images for our node apps # |
| 106 | +#################################################### |
| 107 | + |
| 108 | +http_archive( |
| 109 | + name = "io_bazel_rules_docker", |
| 110 | + sha256 = "aed1c249d4ec8f703edddf35cbe9dfaca0b5f5ea6e4cd9e83e99f3b0d1136c3d", |
| 111 | + strip_prefix = "rules_docker-0.7.0", |
| 112 | + urls = ["https://github.com/bazelbuild/rules_docker/archive/v0.7.0.tar.gz"], |
| 113 | +) |
| 114 | + |
| 115 | +load("@io_bazel_rules_docker//nodejs:image.bzl", nodejs_image_repos = "repositories") |
| 116 | + |
| 117 | +nodejs_image_repos() |
| 118 | + |
| 119 | +#################################################### |
| 120 | +# Kubernetes setup, for deployment to Google Cloud # |
| 121 | +#################################################### |
| 122 | + |
| 123 | +git_repository( |
| 124 | + name = "io_bazel_rules_k8s", |
| 125 | + commit = "36ae5b534cc51ab0815c9bc723760469a9f7175c", |
| 126 | + remote = "https://github.com/bazelbuild/rules_k8s.git", |
| 127 | + shallow_since = "1545317854 -0500", |
| 128 | +) |
| 129 | + |
| 130 | +load("@io_bazel_rules_k8s//k8s:k8s.bzl", "k8s_defaults", "k8s_repositories") |
| 131 | + |
| 132 | +k8s_repositories() |
| 133 | + |
| 134 | +k8s_defaults( |
| 135 | + # This creates a rule called "k8s_deploy" that we can call later |
| 136 | + name = "k8s_deploy", |
| 137 | + # This is the name of the cluster as it appears in: |
| 138 | + # kubectl config view --minify -o=jsonpath='{.contexts[0].context.cluster}' |
| 139 | + cluster = "_".join([ |
| 140 | + "gke", |
| 141 | + "internal-200822", |
| 142 | + "us-west1-a", |
| 143 | + "angular-bazel-example", |
| 144 | + ]), |
| 145 | + kind = "deployment", |
| 146 | +) |
0 commit comments