Skip to content

Commit

Permalink
feat: add angular example (#1124)
Browse files Browse the repository at this point in the history
* feat: add angular example

this is a copy-paste from the angular/angular-bazel-example repo.
The plan is to archive that repo, and/or eventually publish snapshots there from this monorepo
  • Loading branch information
alexeagle authored Sep 12, 2019
1 parent 2ababdf commit c376355
Show file tree
Hide file tree
Showing 63 changed files with 9,679 additions and 106 deletions.
61 changes: 2 additions & 59 deletions .bazelci/presubmit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ tasks:
build_targets:
- "//..."
test_flags:
- "--test_tag_filters=examples"
- "--test_tag_filters=examples,-no-bazelci-ubuntu"
- "--local_resources=792,1.0,1.0"
# test_args will be passed to the nested bazel process
- "--test_arg=--local_resources=13288,7.0,1.0"
Expand All @@ -72,16 +72,6 @@ tasks:
# TODO(gregmagolan): make node_repositories acccept different archives for different platforms
- "//examples:examples_vendored_node"
- "//examples:examples_vendored_node_and_yarn"
# ubuntu1604_angular_bazel_example:
# name: ubuntu1604_angular_bazel_example
# platform: ubuntu1604
# bazel-in-bazel angular_bazel_example fails on ubuntu as the bazelci
# ubuntu docker image is missing shares libs required for the versions
# of chrome and firefox fetched by rules_webtesting. On circleci
# we have the same issue but we can work around it using apt-get.
# on bazelci apt-get fails with permission denied and there is no sudo
# command to switch to root.
# TODO(gregmagolan): figure out how to install the shared libs on bazelci
ubuntu1804:
name: ubuntu1804
platform: ubuntu1804
Expand Down Expand Up @@ -155,7 +145,7 @@ tasks:
build_targets:
- "//..."
test_flags:
- "--test_tag_filters=examples"
- "--test_tag_filters=examples,-no-bazelci-ubuntu"
- "--local_resources=792,1.0,1.0"
# test_args will be passed to the nested bazel process
- "--test_arg=--local_resources=13288,7.0,1.0"
Expand All @@ -167,16 +157,6 @@ tasks:
# TODO(gregmagolan): make node_repositories acccept different archives for different platforms
- "//examples:examples_vendored_node"
- "//examples:examples_vendored_node_and_yarn"
# ubuntu1804_angular_bazel_example:
# name: ubuntu1804_angular_bazel_example
# platform: ubuntu1804
# bazel-in-bazel angular_bazel_example fails on ubuntu as the bazelci
# ubuntu docker image is missing shares libs required for the versions
# of chrome and firefox fetched by rules_webtesting. On circleci
# we have the same issue but we can work around it using apt-get.
# on bazelci apt-get fails with permission denied and there is no sudo
# command to switch to root.
# TODO(gregmagolan): figure out how to install the shared libs on bazelci
macos:
name: macos
platform: macos
Expand Down Expand Up @@ -246,30 +226,6 @@ tasks:
- "--test_arg=--test_tag_filters=-no-bazelci,-no-bazelci-mac,-manual"
test_targets:
- "//..."
macos_angular_bazel_example:
name: macos_angular_bazel_example
platform: macos
# We need to reduce the memory & CPU usage of the top-level
# bazel process for bazel-in-bazel tests to not deplete the
# system memory completely.
# - startup JVM memory reduced
# - top-level bazel process should use as little memory as possible and only 1 core
# - nested bazel process should use a limited number of cores
shell_commands:
- echo 'startup --host_jvm_args=-Xms256m --host_jvm_args=-Xmx1536m' >> .bazelrc
build_targets:
# Split up the build & test as test takes a long time and has very
# little output so running build first makes CI output friendlier.
# The build step can also use up more memory which may be required
# to build the release package with this configuration.
- "//e2e:e2e_angular_bazel_example"
test_flags:
- "--local_resources=792,1.0,1.0"
# test_args will be passed to the nested bazel process
- "--test_arg=--local_resources=14336,4.0,1.0"
- "--test_arg=--test_tag_filters=-no-bazelci,-manual"
test_targets:
- "//e2e:e2e_angular_bazel_example"
macos_cross_compile:
name: macos_cross_compile
platform: macos
Expand Down Expand Up @@ -328,19 +284,6 @@ tasks:
- "--test_arg=--local_resources=13288,1.0,1.0"
test_targets:
- "//..."
# windows_angular_bazel_example:
# name: windows_angular_bazel_example
# platform: windows
# bazel-in-bazel angular_bazel_example fails on Windows on bazelci cloning a git repo:
# ```
# ERROR: no such package '@io_bazel_rules_k8s//k8s': Traceback (most recent call last):
# File "D:/b/ftxm343s/execroot/build_bazel_rules_nodejs/_tmp/3726d3573001cb4068a18af89eb255de/_bazel_b/ktluxf26/external/bazel_tools/tools/build_defs/repo/git.bzl", line 163
# _clone_or_update(ctx)
# File "D:/b/ftxm343s/execroot/build_bazel_rules_nodejs/_tmp/3726d3573001cb4068a18af89eb255de/_bazel_b/ktluxf26/external/bazel_tools/tools/build_defs/repo/git.bzl", line 36, in _clone_or_update
# git_repo(ctx, directory)
# ```
# This is most likely due to a memory issue with this large bazel-in-bazel test.
# TODO(gregmagolan): figure out what is broken with the above
windows_cross_compile:
name: windows_cross_compile
platform: windows
Expand Down
30 changes: 0 additions & 30 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -224,33 +224,6 @@ jobs:
command: bazel test --local_resources=792,1.0,1.0 --test_arg=--local_resources=13288,7.0,1.0 //examples:examples_vendored_node //examples:examples_vendored_node_and_yarn
no_output_timeout: 20m

test_e2e_angular_bazel_example:
<<: *job_defaults
resource_class: xlarge
# We need to reduce the memory & CPU usage of the top-level
# bazel process for this large bazel-in-bazel test to not
# deplete the system memory completely.
# - startup JVM memory reduced
# - top-level bazel process should use as little memory as possible and only 1 core
# - nested bazel process should have its memory & core optimally capped as well
steps:
- *attach_workspace
- *init_environment
- run:
name: Tune top-level bazel JVM memory usage
command: echo 'startup --host_jvm_args=-Xms256m --host_jvm_args=-Xmx1280m' >> .bazelrc
- *init_bazel
- *hide_node_and_yarn_local_binaries

# Split up the build & test as test takes a long time and has very
# little output so running build first makes CI output friendlier.
# The build step can also use up more memory which may be required
# to build the release package with this configuration.
- run: bazel build //e2e:e2e_angular_bazel_example
- run:
command: bazel test --local_resources=792,1.0,1.0 --test_arg=--local_resources=13288,7.0,1.0 --test_arg=--test_tag_filters=-no-circleci,-manual //e2e:e2e_angular_bazel_example
no_output_timeout: 20m

test_legacy_runfiles:
<<: *job_defaults
steps:
Expand Down Expand Up @@ -284,6 +257,3 @@ workflows:
- test_examples:
requires:
- setup
- test_e2e_angular_bazel_example:
requires:
- setup
17 changes: 0 additions & 17 deletions e2e/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -175,23 +175,6 @@ e2e_integration_test(
},
)

e2e_integration_test(
name = "e2e_angular_bazel_example",
size = "enormous",
timeout = "eternal",
# to reduce the chance of depleting all available system memory locally
# and on CI, limit the Bazel JVM memory usage for the nested bazel process
bazelrc_append = "startup --host_jvm_args=-Xms256m --host_jvm_args=-Xmx2g",
npm_packages = {
"//packages/karma:npm_package": "@bazel/karma",
"//packages/protractor:npm_package": "@bazel/protractor",
"//packages/typescript:npm_package": "@bazel/typescript",
},
# TODO(gregmagolan): why is this tagged manual?
tags = ["manual"],
workspace_files = "@e2e_angular_bazel_example//:bazel_integration_test_files",
)

load(":index.bzl", "ALL_E2E")

# Ensure that all e2e directories have a test target
Expand Down
30 changes: 30 additions & 0 deletions examples/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,36 @@

load(":test.bzl", "example_integration_test")

example_integration_test(
name = "examples_angular",
npm_packages = {
"//packages/karma:npm_package": "@bazel/karma",
"//packages/protractor:npm_package": "@bazel/protractor",
"//packages/typescript:npm_package": "@bazel/typescript",
},
tags = [
# bazel-in-bazel angular_bazel_example fails on ubuntu as the bazelci
# ubuntu docker image is missing shares libs required for the versions
# of chrome and firefox fetched by rules_webtesting. On circleci
# we have the same issue but we can work around it using apt-get.
# on bazelci apt-get fails with permission denied and there is no sudo
# command to switch to root.
# TODO(gregmagolan): figure out how to install the shared libs on bazelci
"no-bazelci-ubuntu",
# bazel-in-bazel angular_bazel_example fails on Windows on bazelci cloning a git repo:
# ```
# ERROR: no such package '@io_bazel_rules_k8s//k8s': Traceback (most recent call last):
# File "D:/b/ftxm343s/execroot/build_bazel_rules_nodejs/_tmp/3726d3573001cb4068a18af89eb255de/_bazel_b/ktluxf26/external/bazel_tools/tools/build_defs/repo/git.bzl", line 163
# _clone_or_update(ctx)
# File "D:/b/ftxm343s/execroot/build_bazel_rules_nodejs/_tmp/3726d3573001cb4068a18af89eb255de/_bazel_b/ktluxf26/external/bazel_tools/tools/build_defs/repo/git.bzl", line 36, in _clone_or_update
# git_repo(ctx, directory)
# ```
# This is most likely due to a memory issue with this large bazel-in-bazel test.
# TODO(gregmagolan): figure out what is broken with the above
"no-bazelci-windows",
],
)

example_integration_test(
name = "examples_app",
npm_packages = {
Expand Down
1 change: 1 addition & 0 deletions examples/angular/.bazelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import %workspace%/../../common.bazelrc
37 changes: 37 additions & 0 deletions examples/angular/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
load("@k8s_deploy//:defaults.bzl", "k8s_deploy")

package(default_visibility = ["//:__subpackages__"])

# ts_library and ng_module use the `//:tsconfig.json` target
# by default. This alias allows omitting explicit tsconfig
# attribute.
alias(
name = "tsconfig.json",
actual = "//src:tsconfig.json",
)

k8s_deploy(
name = "deploy",
images = {
"gcr.io/internal-200822/src:nodejs_image": "//src:image",
},
template = ":deployment.yaml",
)

# For testing from the root workspace of this repository with bazel_integration_test.
filegroup(
name = "all_files",
srcs = glob(
include = ["**/*"],
exclude = [
"bazel-out/**/*",
"dist/**/*",
"node_modules/**/*",
],
) + [
"//e2e:all_files",
"//src:all_files",
"//tools:all_files",
],
visibility = ["//visibility:public"],
)
146 changes: 146 additions & 0 deletions examples/angular/WORKSPACE
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
# The WORKSPACE file tells Bazel that this directory is a "workspace", which is like a project root.
# The content of this file specifies all the external dependencies Bazel needs to perform a build.

####################################
# ESModule imports (and TypeScript imports) can be absolute starting with the workspace name.
# The name of the workspace should match the npm package where we publish, so that these
# imports also make sense when referencing the published package.
workspace(
name = "angular_bazel_example",
managed_directories = {"@npm": ["node_modules"]},
)

# These rules are built-into Bazel but we need to load them first to download more rules
load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository")
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

# Fetch rules_nodejs so we can install our npm dependencies
http_archive(
name = "build_bazel_rules_nodejs",
sha256 = "0d9660cf0894f1fe1e9840818553e0080fbce0851169812d77a70bdb9981c946",
urls = ["https://github.com/bazelbuild/rules_nodejs/releases/download/0.37.0/rules_nodejs-0.37.0.tar.gz"],
)

# Fetch sass rules for compiling sass files
http_archive(
name = "io_bazel_rules_sass",
sha256 = "4f05239080175a3f4efa8982d2b7775892d656bb47e8cf56914d5f9441fb5ea6",
strip_prefix = "rules_sass-86ca977cf2a8ed481859f83a286e164d07335116",
url = "https://github.com/bazelbuild/rules_sass/archive/86ca977cf2a8ed481859f83a286e164d07335116.zip",
)

# Check the bazel version and download npm dependencies
load("@build_bazel_rules_nodejs//:defs.bzl", "check_bazel_version", "yarn_install")

# Bazel version must be at least the following version because:
# - 0.27.0 Adds managed directories support
check_bazel_version(
message = """
You no longer need to install Bazel on your machine.
Angular has a dependency on the @bazel/bazel package which supplies it.
Try running `yarn bazel` instead.
(If you did run that, check that you've got a fresh `yarn install`)
""",
minimum_bazel_version = "0.27.0",
)

# Setup the Node.js toolchain & install our npm dependencies into @npm
yarn_install(
name = "npm",
package_json = "//:package.json",
yarn_lock = "//:yarn.lock",
)

# Install all bazel dependencies of our npm packages
load("@npm//:install_bazel_dependencies.bzl", "install_bazel_dependencies")

install_bazel_dependencies()

# Load npm_bazel_protractor dependencies
load("@npm_bazel_protractor//:package.bzl", "npm_bazel_protractor_dependencies")

npm_bazel_protractor_dependencies()

# Load npm_bazel_karma dependencies
load("@npm_bazel_karma//:package.bzl", "rules_karma_dependencies")

rules_karma_dependencies()

# Setup the rules_webtesting toolchain
load("@io_bazel_rules_webtesting//web:repositories.bzl", "web_test_repositories")

web_test_repositories()

# Temporary work-around for https://github.com/angular/angular/issues/28681
# TODO(gregmagolan): go back to @io_bazel_rules_webtesting browser_repositories
load("@npm_bazel_karma//:browser_repositories.bzl", "browser_repositories")

browser_repositories()

# Setup the rules_typescript tooolchain
load("@npm_bazel_typescript//:defs.bzl", "ts_setup_workspace")

ts_setup_workspace()

# Setup the rules_sass toolchain
load("@io_bazel_rules_sass//sass:sass_repositories.bzl", "sass_repositories")

sass_repositories()

################################
# Support for Remote Execution #
################################

http_archive(
name = "bazel_toolchains",
sha256 = "88e818f9f03628eef609c8429c210ecf265ffe46c2af095f36c7ef8b1855fef5",
strip_prefix = "bazel-toolchains-92dd8a7",
urls = [
"https://github.com/bazelbuild/bazel-toolchains/archive/92dd8a7.zip",
],
)

####################################################
# Support creating Docker images for our node apps #
####################################################

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

load("@io_bazel_rules_docker//nodejs:image.bzl", nodejs_image_repos = "repositories")

nodejs_image_repos()

####################################################
# Kubernetes setup, for deployment to Google Cloud #
####################################################

git_repository(
name = "io_bazel_rules_k8s",
commit = "36ae5b534cc51ab0815c9bc723760469a9f7175c",
remote = "https://github.com/bazelbuild/rules_k8s.git",
shallow_since = "1545317854 -0500",
)

load("@io_bazel_rules_k8s//k8s:k8s.bzl", "k8s_defaults", "k8s_repositories")

k8s_repositories()

k8s_defaults(
# This creates a rule called "k8s_deploy" that we can call later
name = "k8s_deploy",
# This is the name of the cluster as it appears in:
# kubectl config view --minify -o=jsonpath='{.contexts[0].context.cluster}'
cluster = "_".join([
"gke",
"internal-200822",
"us-west1-a",
"angular-bazel-example",
]),
kind = "deployment",
)
Loading

0 comments on commit c376355

Please sign in to comment.