From ad2eba1d62ef2fffb8e0ee0fb7da8bc20790b3c8 Mon Sep 17 00:00:00 2001 From: Fabian Wiles Date: Sat, 21 Dec 2019 17:16:31 +1300 Subject: [PATCH] feat(examples): upgrade rules_docker to 0.14.1 Also drop the patches we needed for older versions --- .circleci/bazel.rc | 4 ++++ examples/BUILD.bazel | 12 ++++++++--- examples/angular/WORKSPACE | 20 ++++++++++--------- examples/angular/rules_docker.patch | 13 ------------ examples/angular/src/BUILD.bazel | 6 +----- examples/nestjs/WORKSPACE | 7 +++---- examples/nestjs/rules_docker.patch | 13 ------------ examples/nestjs/src/BUILD.bazel | 8 +------- .../bazel_integration_test/test_runner.js | 1 + 9 files changed, 30 insertions(+), 54 deletions(-) delete mode 100644 examples/angular/rules_docker.patch delete mode 100644 examples/nestjs/rules_docker.patch diff --git a/.circleci/bazel.rc b/.circleci/bazel.rc index ea3fb904dc..a2c3a1779b 100644 --- a/.circleci/bazel.rc +++ b/.circleci/bazel.rc @@ -19,3 +19,7 @@ build --local_cpu_resources=8 # Our integration tests rely on accessing public registries which can fail # Let's give all failing tests a second try to mostly paper over flakiness test --flaky_test_attempts=2 + +# Expose the SSH_AUTH_SOCK variable to integration tests that need to run git_repository repository rules +# This is needed by the CircleCI git-over-ssh environment +test --test_env=SSH_AUTH_SOCK diff --git a/examples/BUILD.bazel b/examples/BUILD.bazel index 3b798945c3..035f1b5a3a 100644 --- a/examples/BUILD.bazel +++ b/examples/BUILD.bazel @@ -153,9 +153,15 @@ example_integration_test( "@rayman1104", "@siberex", ], - # Breaks on Windows with `rules_docker requires a python interpreter installed. Please set - # BAZEL_PYTHON, or put it on your path.` - tags = ["fix-windows"], + # Fails on transitive dep of rules_docker + # error running 'git init C:/users/b/_bazel_b/3oe2yqkh/external/rules_cc' while working with @rules_cc: + # java.io.IOException: ERROR: src/main/native/windows/process.cc(199): CreateProcessW("git" init C:/users/b/_bazel_b/3oe2yqkh/external/rules_cc): The system cannot find the file specified + # + # NB: even after working around that by fetching rules_cc with an http_archive we get a follow-on failure + # ERROR: Analysis of target '//src:docker' failed; build aborted: no such package '@nodejs_image_base//image': Pull command failed: java.io.IOException: ERROR: src/main/native/windows/process.cc(199): CreateProcessW("C:\users\b\_bazel_b\vanuqgg3\external\go_puller_linux\file\downloaded" -directory C:/users/b/_bazel_b/vanuqgg3/external/nodejs_image_base/image -os linux -os-version "" -os-features "" -architecture amd64 -variant "" -features "" -name gcr.io/google-appengine/debian9@sha256:c05b781371f75d1bd7a199bc83de177173cc80c98dbfb6c1ef7075757addece4): %1 is not a valid Win32 application. + # (error: 193) (C:/users/b/_bazel_b/vanuqgg3/external/go_puller_linux/file/downloaded -directory + # C:/users/b/_bazel_b/vanuqgg3/external/nodejs_image_base/image -os linux -os-version -os-features -architecture amd64 -variant -features -name gcr.io/google-appengine/debian9@sha256:c05b781371f75d1bd7a199bc83de177173cc80c98dbfb6c1ef7075757addece4) + tags = ["no-bazelci-windows"], ) example_integration_test( diff --git a/examples/angular/WORKSPACE b/examples/angular/WORKSPACE index cb44326479..1010bcd1c3 100644 --- a/examples/angular/WORKSPACE +++ b/examples/angular/WORKSPACE @@ -11,7 +11,6 @@ workspace( ) # 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 @@ -99,10 +98,9 @@ http_archive( http_archive( name = "io_bazel_rules_docker", - patches = ["//:rules_docker.patch"], - sha256 = "7d453450e1eb70e238eea6b31f4115607ec1200e91afea01c25f9804f37e39c8", - strip_prefix = "rules_docker-0.10.0", - urls = ["https://github.com/bazelbuild/rules_docker/archive/v0.10.0.tar.gz"], + sha256 = "dc97fccceacd4c6be14e800b2a00693d5e8d07f69ee187babfd04a80a9f8e250", + strip_prefix = "rules_docker-0.14.1", + urls = ["https://github.com/bazelbuild/rules_docker/releases/download/v0.14.1/rules_docker-v0.14.1.tar.gz"], ) load("@io_bazel_rules_docker//repositories:repositories.bzl", container_repositories = "repositories") @@ -117,17 +115,21 @@ nodejs_image_repos() # Kubernetes setup, for deployment to Google Cloud # #################################################### -git_repository( +http_archive( name = "io_bazel_rules_k8s", - commit = "36ae5b534cc51ab0815c9bc723760469a9f7175c", - remote = "https://github.com/bazelbuild/rules_k8s.git", - shallow_since = "1545317854 -0500", + sha256 = "cc75cf0d86312e1327d226e980efd3599704e01099b58b3c2fc4efe5e321fcd9", + strip_prefix = "rules_k8s-0.3.1", + urls = ["https://github.com/bazelbuild/rules_k8s/releases/download/v0.3.1/rules_k8s-v0.3.1.tar.gz"], ) load("@io_bazel_rules_k8s//k8s:k8s.bzl", "k8s_defaults", "k8s_repositories") k8s_repositories() +load("@io_bazel_rules_k8s//k8s:k8s_go_deps.bzl", k8s_go_deps = "deps") + +k8s_go_deps() + k8s_defaults( # This creates a rule called "k8s_deploy" that we can call later name = "k8s_deploy", diff --git a/examples/angular/rules_docker.patch b/examples/angular/rules_docker.patch deleted file mode 100644 index 275edb8246..0000000000 --- a/examples/angular/rules_docker.patch +++ /dev/null @@ -1,13 +0,0 @@ -diff --git nodejs/image.bzl nodejs/image.bzl -index a01ea3e..617aa06 100644 ---- nodejs/image.bzl -+++ nodejs/image.bzl -@@ -17,7 +17,7 @@ The signature of this rule is compatible with nodejs_binary. - """ - - load("@bazel_skylib//lib:dicts.bzl", "dicts") --load("@build_bazel_rules_nodejs//:defs.bzl", "nodejs_binary") -+load("@build_bazel_rules_nodejs//:index.bzl", "nodejs_binary") - load( - "//container:container.bzl", - "container_pull", \ No newline at end of file diff --git a/examples/angular/src/BUILD.bazel b/examples/angular/src/BUILD.bazel index b3b69d960b..3bec7619ec 100644 --- a/examples/angular/src/BUILD.bazel +++ b/examples/angular/src/BUILD.bazel @@ -223,13 +223,10 @@ history_server( nodejs_image( name = "nodejs_image", - data = [":prodapp"], - entry_point = "@npm//:node_modules/history-server/modules/cli.js", - node_modules = "@npm//:node_modules", + binary = ":prodserver", # Actions created by this rule are I/O-bound, # so there is no benefit to running them remotely tags = ["local"], - templated_args = ["src/prodapp"], ) container_image( @@ -238,7 +235,6 @@ container_image( # Actions created by this rule are I/O-bound, # so there is no benefit to running them remotely tags = ["local"], - workdir = "/app/src/nodejs_image.binary.runfiles/examples_angular", ) ts_library( diff --git a/examples/nestjs/WORKSPACE b/examples/nestjs/WORKSPACE index 5dfcf5a2d8..e4c4e0d7a4 100644 --- a/examples/nestjs/WORKSPACE +++ b/examples/nestjs/WORKSPACE @@ -39,10 +39,9 @@ install_bazel_dependencies() http_archive( name = "io_bazel_rules_docker", - patches = ["//:rules_docker.patch"], - sha256 = "7d453450e1eb70e238eea6b31f4115607ec1200e91afea01c25f9804f37e39c8", - strip_prefix = "rules_docker-0.10.0", - urls = ["https://github.com/bazelbuild/rules_docker/archive/v0.10.0.tar.gz"], + sha256 = "dc97fccceacd4c6be14e800b2a00693d5e8d07f69ee187babfd04a80a9f8e250", + strip_prefix = "rules_docker-0.14.1", + urls = ["https://github.com/bazelbuild/rules_docker/releases/download/v0.14.1/rules_docker-v0.14.1.tar.gz"], ) load( diff --git a/examples/nestjs/rules_docker.patch b/examples/nestjs/rules_docker.patch deleted file mode 100644 index 275edb8246..0000000000 --- a/examples/nestjs/rules_docker.patch +++ /dev/null @@ -1,13 +0,0 @@ -diff --git nodejs/image.bzl nodejs/image.bzl -index a01ea3e..617aa06 100644 ---- nodejs/image.bzl -+++ nodejs/image.bzl -@@ -17,7 +17,7 @@ The signature of this rule is compatible with nodejs_binary. - """ - - load("@bazel_skylib//lib:dicts.bzl", "dicts") --load("@build_bazel_rules_nodejs//:defs.bzl", "nodejs_binary") -+load("@build_bazel_rules_nodejs//:index.bzl", "nodejs_binary") - load( - "//container:container.bzl", - "container_pull", \ No newline at end of file diff --git a/examples/nestjs/src/BUILD.bazel b/examples/nestjs/src/BUILD.bazel index e1aaa73f4c..816d1e4293 100644 --- a/examples/nestjs/src/BUILD.bazel +++ b/examples/nestjs/src/BUILD.bazel @@ -73,11 +73,5 @@ jasmine_node_test( # bazel build --platforms=@build_bazel_rules_nodejs//toolchains/node:linux_amd64 //src:docker nodejs_image( name = "docker", - data = [ - ":app", - ], - entry_point = ":main.ts", - # TODO: switch to fine grained deps -- see bazelbuild/rules_docker#1000 - # and add test for docker image - node_modules = "@npm//:node_modules", + binary = ":server", ) diff --git a/internal/bazel_integration_test/test_runner.js b/internal/bazel_integration_test/test_runner.js index c222db768c..03f1e52e0c 100644 --- a/internal/bazel_integration_test/test_runner.js +++ b/internal/bazel_integration_test/test_runner.js @@ -368,6 +368,7 @@ for (const bazelCommand of config.bazelCommands) { delete env[key]; } env['PWD'] = workspaceRoot; + env['HOME'] = require('os').homedir(); log_verbose(JSON.stringify(env, null, 2)); log(`running 'bazel ${bazelArgs.join(' ')}' in ${workspaceRoot}`); spawnedProcess = spawnSync(bazelBinary, bazelArgs, {env, cwd: workspaceRoot, stdio: 'inherit'});