Skip to content

Commit

Permalink
feat: implement structure_test
Browse files Browse the repository at this point in the history
  • Loading branch information
thesayyn committed Nov 22, 2022
1 parent 6f006e9 commit 1ab00e6
Show file tree
Hide file tree
Showing 19 changed files with 595 additions and 119 deletions.
3 changes: 0 additions & 3 deletions .bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,3 @@ build --incompatible_strict_action_env
# (Note that we use .bazelrc.user so the file appears next to .bazelrc in directory listing,
# rather than user.bazelrc as suggested in the Bazel docs)
try-import %workspace%/.bazelrc.user


build --incompatible_strict_action_env
7 changes: 7 additions & 0 deletions .github/workflows/ci.bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,10 @@ build --repository_cache=~/.cache/bazel-repo
test --test_output=errors
# Allows tests to run bazelisk-in-bazel, since this is the cache folder used
test --test_env=XDG_CACHE_HOME

# Allow DOCKER_HOST to leak into test actions
test --test_env=DOCKER_HOST

# try to import platform specific overrides
try-import %workspace%/.github/workflows/darwin.bazelrc

9 changes: 8 additions & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,19 @@ jobs:
~/.cache/bazel-repo
key: bazel-cache-${{ hashFiles('**/BUILD.bazel', '**/*.bzl', 'WORKSPACE') }}
restore-keys: bazel-cache-
- name: install podman
if: ${{ matrix.os == 'macos-latest' }}
run: |
brew install podman
podman machine init
podman machine start
echo "DOCKER_HOST=unix:///Users/runner/.local/share/containers/podman/machine/podman-machine-default/podman.sock" >> $GITHUB_ENV
- name: bazel test //...
env:
# Bazelisk will download bazel to here, ensure it is cached between runs.
XDG_CACHE_HOME: ~/.cache/bazel-repo
run: bazel --bazelrc=.github/workflows/ci.bazelrc --bazelrc=.bazelrc test //...
- name: bazel build //example:image && docker load
- name: bazel build //example/... & run with a container runtime
if: ${{ matrix.os != 'macos-latest' }}
env:
# Bazelisk will download bazel to here, ensure it is cached between runs.
Expand Down
39 changes: 7 additions & 32 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ load("//oci:repositories.bzl", "LATEST_CRANE_VERSION", "LATEST_ZOT_VERSION", "oc
oci_register_toolchains(
name = "oci",
crane_version = LATEST_CRANE_VERSION,
zot_version = LATEST_ZOT_VERSION
zot_version = LATEST_ZOT_VERSION,
)

# For running our own unit tests
Expand Down Expand Up @@ -47,43 +47,18 @@ load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
# JS
http_archive(
name = "aspect_rules_js",
sha256 = "e8576a74a7e80b873179514cf1ad48b62b18ae024e74200ecd40ae6dc00c515a",
strip_prefix = "rules_js-0.3.0",
url = "https://github.com/aspect-build/rules_js/archive/v0.3.0.tar.gz",
sha256 = "dda5fee3926e62c483660b35b25d1577d23f88f11a2775e3555b57289f4edb12",
strip_prefix = "rules_js-1.6.9",
url = "https://github.com/aspect-build/rules_js/archive/refs/tags/v1.6.9.tar.gz",
)

load("@aspect_rules_js//js:repositories.bzl", "rules_js_dependencies")

rules_js_dependencies()

load("@rules_nodejs//nodejs:repositories.bzl", "nodejs_register_toolchains")
load("@rules_nodejs//nodejs:repositories.bzl", "DEFAULT_NODE_VERSION", "nodejs_register_toolchains")

nodejs_register_toolchains(
name = "node16",
node_version = "16.9.0",
)

load("@aspect_rules_js//js:npm_import.bzl", "npm_import")

npm_import(
integrity = "sha512-ULr0LDaEqQrMFGyQ3bhJkLsbtrQ8QibAseGZeaSUiT/6zb9IvIkomWHJIvgvwad+hinRAgsI51JcWk2yvwyL+w==",
package = "acorn",
version = "8.4.0",
deps = [],
)

# PYTHON
http_archive(
name = "rules_python",
sha256 = "cd6730ed53a002c56ce4e2f396ba3b3be262fd7cb68339f0377a45e8227fe332",
url = "https://github.com/bazelbuild/rules_python/releases/download/0.5.0/rules_python-0.5.0.tar.gz",
)

load("@rules_python//python:pip.bzl", "pip_install")

# Create a central external repo, @my_deps, that contains Bazel targets for all the
# third-party packages specified in the requirements.txt file.
pip_install(
name = "my_deps",
requirements = "//example/py:requirements.txt",
name = "nodejs",
node_version = DEFAULT_NODE_VERSION,
)
39 changes: 19 additions & 20 deletions example/js/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,37 +1,27 @@
load("//oci:container.bzl", "container")
load("//oci:defs.bzl", "oci_tarball")
load("//language:runfiles.bzl", "expand_runfiles")
load("@rules_pkg//:pkg.bzl", "pkg_tar")
load("@aspect_rules_js//js:nodejs_binary.bzl", "nodejs_binary")
load("//oci:defs.bzl", "oci_tarball", "structure_test")
load("@aspect_rules_js//js:defs.bzl", "js_binary")
load(":js_image_layer.bzl", "js_image_layer")

nodejs_binary(
name = "bin",
data = ["@npm_acorn-8.4.0"],
js_binary(
name = "main",
entry_point = "main.js",
)

expand_runfiles(
name = "runfiles",
binary = ":bin",
)

pkg_tar(
name = "entrypoint",
srcs = [
":runfiles",
],
strip_prefix = ".",
js_image_layer(
name = "layers",
binary = ":main",
)

container(
name = "image",
# TODO(thesayyn): remove this and use the ocifier command once https://github.com/google/go-containerregistry/pull/1293 lands.
# Context: debian:latest is docker specific image therefore rejected by vendor neutral registries like zot
base = "thesayyn/debian:oci",
cmd = ["/example/js/_bin_launcher.sh"],
cmd = ["/example/js/main.sh"],
entrypoint = ["bash"],
layers = [
":entrypoint",
":layers/app.tar",
],
)

Expand All @@ -40,3 +30,12 @@ oci_tarball(
image = ":image",
repotags = ["example/js:latest"],
)

structure_test(
name = "test",
config = ["test.yaml"],
image = ":image",
target_compatible_with = [
"@platforms//os:linux",
],
)
Loading

0 comments on commit 1ab00e6

Please sign in to comment.