Skip to content

Commit c376355

Browse files
authored
feat: add angular example (#1124)
* 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
1 parent 2ababdf commit c376355

63 files changed

Lines changed: 9679 additions & 106 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.bazelci/presubmit.yml

Lines changed: 2 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ tasks:
6060
build_targets:
6161
- "//..."
6262
test_flags:
63-
- "--test_tag_filters=examples"
63+
- "--test_tag_filters=examples,-no-bazelci-ubuntu"
6464
- "--local_resources=792,1.0,1.0"
6565
# test_args will be passed to the nested bazel process
6666
- "--test_arg=--local_resources=13288,7.0,1.0"
@@ -72,16 +72,6 @@ tasks:
7272
# TODO(gregmagolan): make node_repositories acccept different archives for different platforms
7373
- "//examples:examples_vendored_node"
7474
- "//examples:examples_vendored_node_and_yarn"
75-
# ubuntu1604_angular_bazel_example:
76-
# name: ubuntu1604_angular_bazel_example
77-
# platform: ubuntu1604
78-
# bazel-in-bazel angular_bazel_example fails on ubuntu as the bazelci
79-
# ubuntu docker image is missing shares libs required for the versions
80-
# of chrome and firefox fetched by rules_webtesting. On circleci
81-
# we have the same issue but we can work around it using apt-get.
82-
# on bazelci apt-get fails with permission denied and there is no sudo
83-
# command to switch to root.
84-
# TODO(gregmagolan): figure out how to install the shared libs on bazelci
8575
ubuntu1804:
8676
name: ubuntu1804
8777
platform: ubuntu1804
@@ -155,7 +145,7 @@ tasks:
155145
build_targets:
156146
- "//..."
157147
test_flags:
158-
- "--test_tag_filters=examples"
148+
- "--test_tag_filters=examples,-no-bazelci-ubuntu"
159149
- "--local_resources=792,1.0,1.0"
160150
# test_args will be passed to the nested bazel process
161151
- "--test_arg=--local_resources=13288,7.0,1.0"
@@ -167,16 +157,6 @@ tasks:
167157
# TODO(gregmagolan): make node_repositories acccept different archives for different platforms
168158
- "//examples:examples_vendored_node"
169159
- "//examples:examples_vendored_node_and_yarn"
170-
# ubuntu1804_angular_bazel_example:
171-
# name: ubuntu1804_angular_bazel_example
172-
# platform: ubuntu1804
173-
# bazel-in-bazel angular_bazel_example fails on ubuntu as the bazelci
174-
# ubuntu docker image is missing shares libs required for the versions
175-
# of chrome and firefox fetched by rules_webtesting. On circleci
176-
# we have the same issue but we can work around it using apt-get.
177-
# on bazelci apt-get fails with permission denied and there is no sudo
178-
# command to switch to root.
179-
# TODO(gregmagolan): figure out how to install the shared libs on bazelci
180160
macos:
181161
name: macos
182162
platform: macos
@@ -246,30 +226,6 @@ tasks:
246226
- "--test_arg=--test_tag_filters=-no-bazelci,-no-bazelci-mac,-manual"
247227
test_targets:
248228
- "//..."
249-
macos_angular_bazel_example:
250-
name: macos_angular_bazel_example
251-
platform: macos
252-
# We need to reduce the memory & CPU usage of the top-level
253-
# bazel process for bazel-in-bazel tests to not deplete the
254-
# system memory completely.
255-
# - startup JVM memory reduced
256-
# - top-level bazel process should use as little memory as possible and only 1 core
257-
# - nested bazel process should use a limited number of cores
258-
shell_commands:
259-
- echo 'startup --host_jvm_args=-Xms256m --host_jvm_args=-Xmx1536m' >> .bazelrc
260-
build_targets:
261-
# Split up the build & test as test takes a long time and has very
262-
# little output so running build first makes CI output friendlier.
263-
# The build step can also use up more memory which may be required
264-
# to build the release package with this configuration.
265-
- "//e2e:e2e_angular_bazel_example"
266-
test_flags:
267-
- "--local_resources=792,1.0,1.0"
268-
# test_args will be passed to the nested bazel process
269-
- "--test_arg=--local_resources=14336,4.0,1.0"
270-
- "--test_arg=--test_tag_filters=-no-bazelci,-manual"
271-
test_targets:
272-
- "//e2e:e2e_angular_bazel_example"
273229
macos_cross_compile:
274230
name: macos_cross_compile
275231
platform: macos
@@ -328,19 +284,6 @@ tasks:
328284
- "--test_arg=--local_resources=13288,1.0,1.0"
329285
test_targets:
330286
- "//..."
331-
# windows_angular_bazel_example:
332-
# name: windows_angular_bazel_example
333-
# platform: windows
334-
# bazel-in-bazel angular_bazel_example fails on Windows on bazelci cloning a git repo:
335-
# ```
336-
# ERROR: no such package '@io_bazel_rules_k8s//k8s': Traceback (most recent call last):
337-
# 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
338-
# _clone_or_update(ctx)
339-
# 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
340-
# git_repo(ctx, directory)
341-
# ```
342-
# This is most likely due to a memory issue with this large bazel-in-bazel test.
343-
# TODO(gregmagolan): figure out what is broken with the above
344287
windows_cross_compile:
345288
name: windows_cross_compile
346289
platform: windows

.circleci/config.yml

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -224,33 +224,6 @@ jobs:
224224
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
225225
no_output_timeout: 20m
226226

227-
test_e2e_angular_bazel_example:
228-
<<: *job_defaults
229-
resource_class: xlarge
230-
# We need to reduce the memory & CPU usage of the top-level
231-
# bazel process for this large bazel-in-bazel test to not
232-
# deplete the system memory completely.
233-
# - startup JVM memory reduced
234-
# - top-level bazel process should use as little memory as possible and only 1 core
235-
# - nested bazel process should have its memory & core optimally capped as well
236-
steps:
237-
- *attach_workspace
238-
- *init_environment
239-
- run:
240-
name: Tune top-level bazel JVM memory usage
241-
command: echo 'startup --host_jvm_args=-Xms256m --host_jvm_args=-Xmx1280m' >> .bazelrc
242-
- *init_bazel
243-
- *hide_node_and_yarn_local_binaries
244-
245-
# Split up the build & test as test takes a long time and has very
246-
# little output so running build first makes CI output friendlier.
247-
# The build step can also use up more memory which may be required
248-
# to build the release package with this configuration.
249-
- run: bazel build //e2e:e2e_angular_bazel_example
250-
- run:
251-
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
252-
no_output_timeout: 20m
253-
254227
test_legacy_runfiles:
255228
<<: *job_defaults
256229
steps:
@@ -284,6 +257,3 @@ workflows:
284257
- test_examples:
285258
requires:
286259
- setup
287-
- test_e2e_angular_bazel_example:
288-
requires:
289-
- setup

e2e/BUILD.bazel

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -175,23 +175,6 @@ e2e_integration_test(
175175
},
176176
)
177177

178-
e2e_integration_test(
179-
name = "e2e_angular_bazel_example",
180-
size = "enormous",
181-
timeout = "eternal",
182-
# to reduce the chance of depleting all available system memory locally
183-
# and on CI, limit the Bazel JVM memory usage for the nested bazel process
184-
bazelrc_append = "startup --host_jvm_args=-Xms256m --host_jvm_args=-Xmx2g",
185-
npm_packages = {
186-
"//packages/karma:npm_package": "@bazel/karma",
187-
"//packages/protractor:npm_package": "@bazel/protractor",
188-
"//packages/typescript:npm_package": "@bazel/typescript",
189-
},
190-
# TODO(gregmagolan): why is this tagged manual?
191-
tags = ["manual"],
192-
workspace_files = "@e2e_angular_bazel_example//:bazel_integration_test_files",
193-
)
194-
195178
load(":index.bzl", "ALL_E2E")
196179

197180
# Ensure that all e2e directories have a test target

examples/BUILD.bazel

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,36 @@
1414

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

17+
example_integration_test(
18+
name = "examples_angular",
19+
npm_packages = {
20+
"//packages/karma:npm_package": "@bazel/karma",
21+
"//packages/protractor:npm_package": "@bazel/protractor",
22+
"//packages/typescript:npm_package": "@bazel/typescript",
23+
},
24+
tags = [
25+
# bazel-in-bazel angular_bazel_example fails on ubuntu as the bazelci
26+
# ubuntu docker image is missing shares libs required for the versions
27+
# of chrome and firefox fetched by rules_webtesting. On circleci
28+
# we have the same issue but we can work around it using apt-get.
29+
# on bazelci apt-get fails with permission denied and there is no sudo
30+
# command to switch to root.
31+
# TODO(gregmagolan): figure out how to install the shared libs on bazelci
32+
"no-bazelci-ubuntu",
33+
# bazel-in-bazel angular_bazel_example fails on Windows on bazelci cloning a git repo:
34+
# ```
35+
# ERROR: no such package '@io_bazel_rules_k8s//k8s': Traceback (most recent call last):
36+
# 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
37+
# _clone_or_update(ctx)
38+
# 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
39+
# git_repo(ctx, directory)
40+
# ```
41+
# This is most likely due to a memory issue with this large bazel-in-bazel test.
42+
# TODO(gregmagolan): figure out what is broken with the above
43+
"no-bazelci-windows",
44+
],
45+
)
46+
1747
example_integration_test(
1848
name = "examples_app",
1949
npm_packages = {

examples/angular/.bazelrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import %workspace%/../../common.bazelrc

examples/angular/BUILD.bazel

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
load("@k8s_deploy//:defaults.bzl", "k8s_deploy")
2+
3+
package(default_visibility = ["//:__subpackages__"])
4+
5+
# ts_library and ng_module use the `//:tsconfig.json` target
6+
# by default. This alias allows omitting explicit tsconfig
7+
# attribute.
8+
alias(
9+
name = "tsconfig.json",
10+
actual = "//src:tsconfig.json",
11+
)
12+
13+
k8s_deploy(
14+
name = "deploy",
15+
images = {
16+
"gcr.io/internal-200822/src:nodejs_image": "//src:image",
17+
},
18+
template = ":deployment.yaml",
19+
)
20+
21+
# For testing from the root workspace of this repository with bazel_integration_test.
22+
filegroup(
23+
name = "all_files",
24+
srcs = glob(
25+
include = ["**/*"],
26+
exclude = [
27+
"bazel-out/**/*",
28+
"dist/**/*",
29+
"node_modules/**/*",
30+
],
31+
) + [
32+
"//e2e:all_files",
33+
"//src:all_files",
34+
"//tools:all_files",
35+
],
36+
visibility = ["//visibility:public"],
37+
)

examples/angular/WORKSPACE

Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
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

Comments
 (0)