bazel-contrib / bazel-contrib/rules_oci
"Unable to acesss jarfile" when following Java Maven Example
- Dominant language
- Starlark
- Stars
- 423
- Forks
- 213
- Avg merge
- 53m
- Merged PRs (30d)
- 1
Description
I have this macro with which I generate a `tar` and an `oci_image`:
```
load("@aspect_bazel_lib//lib:tar.bzl", "tar")
load("@rules_oci//oci:defs.bzl", "oci_image")
def java_image(
name,
jar_name,
**kwargs):
tar_name = name + "_tar"
tar(
name = tar_name,
srcs = [jar_name],
)
oci_image(
name = name,
tars = [":" + tar_name],
base = "@distroless_java21",
entrypoint = [
"java",
"-jar",
"/" + jar_name,
"org.springframework.boot.loader.JarLauncher",
],
**kwargs
)
```
I use the macro like this:
```
load("@container_structure_test//:defs.bzl", "container_structure_test")
load("@rules_oci//oci:defs.bzl", "oci_load")
load("//libs/bzl/springboot:springboot.bzl", "springboot")
load("//libs/bzl/springboot:springboot_image.bzl", "springboot_image")
springboot(
name = "app",
boot_app_class =
resources = ["//apps//app/src/main/resources"],
runtime_deps = [
"//apps//app/src/main/java/com/",
],
)
java_image(
name = "app_image",
jar_name = "app.jar",
)
oci_load(
name = "app_image_load",
# format = "docker",
image = ":app_image",
repo_tags = [
],
)
container_structure_test(
name = "app_image_test",
configs = ["//apps//app:container_structure_test.yaml"],
image = ":app_image",
tags = ["requires-docker"],
)
```
`container_structure_test.yaml` looks like this:
```
schemaVersion: 2.0.0
commandTests:
- name: test
command: java
args: ['-jar', '/app.jar']
expectedOutput: ['Success: 1']
```
When I run `bazel test :app_image_test`, I get an error that says "Unable to access jarfile /app.jar". I followed the [Java Maven Example](https://github.com/bazelbuild/examples/tree/main/java-maven) so I'm a little surprised this isn't working.
Contributor guide
Research direction
Inspect the java_image macro loaded from //libs/bzl/springboot:springboot_image.bzl and the container_structure_test.yaml configuration. First run bazel test :app_image_test, then inspect how app.jar is placed in the OCI image and how the test invokes it. Done means the container structure test can access /app.jar and observes the expected output.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- docker, java
- Domain
- infrastructure
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100