Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions .bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@ test --test_env=WORKSPACE_DIR
test --test_env=PATH
test --test_env=JAVA_HOME

# Used by //pipeline:generate-openapi genrule which needs PATH/JAVA_HOME to find mvn.
# Applied only when explicitly passed: bazel build --config=openapi //pipeline:generate-openapi
# Needed for local Maven/npm genrules (pipeline_jars, generate-openapi)
build --action_env=PATH
build --action_env=JAVA_HOME
build --action_env=HOME

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is this required? previously it was not needed right and as part of this also we are not introducing new stuffs


# Named config used by CI: bazel build --config=openapi //pipeline:generate-openapi
build:openapi --action_env=PATH
build:openapi --action_env=JAVA_HOME
6 changes: 6 additions & 0 deletions BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
load("@rules_shell//shell:sh_binary.bzl", "sh_binary")

sh_binary(
name = "docker-compose",
srcs = ["docker.sh"],

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe it is for running the whole stack right? can we call it sumething else? maybe docker-compose instead of just docker.

)
15 changes: 15 additions & 0 deletions MODULE.bazel
Original file line number Diff line number Diff line change
@@ -1,2 +1,17 @@
bazel_dep(name = "rules_java", version = "9.9.0")
bazel_dep(name = "rules_shell", version = "0.6.1")
bazel_dep(name = "rules_oci", version = "2.3.5")
bazel_dep(name = "rules_pkg", version = "1.0.1")
bazel_dep(name = "aspect_bazel_lib", version = "2.22.5")

oci = use_extension("@rules_oci//oci:extensions.bzl", "oci")
oci.pull(
name = "eclipse_temurin_jdk17",
image = "index.docker.io/library/eclipse-temurin",
tag = "17-jdk",
platforms = [
"linux/amd64",
"linux/arm64/v8",
],
)
use_repo(oci, "eclipse_temurin_jdk17", "eclipse_temurin_jdk17_linux_amd64", "eclipse_temurin_jdk17_linux_arm64_v8")

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks like this instruction is being repeated again here for bazel. cant we use existing dockerfiles and docker-compose files to have single source of truth?

223 changes: 223 additions & 0 deletions MODULE.bazel.lock

Large diffs are not rendered by default.

40 changes: 40 additions & 0 deletions docker.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/usr/bin/env bash
set -euo pipefail
cd "$BUILD_WORKSPACE_DIRECTORY"

case "${1:-}" in
up)
docker compose --env-file .env.local up -d
;;
down)
docker compose down
;;
fresh)
MONITORING_STACK_DIR="${MONITORING_STACK_DIR:-./monitoring}" \
docker compose \
-f docker-compose.yml \
-f monitoring/docker-compose-monitoring.yml \
-f monitoring/docker-compose-monitoring-integration.yml \
down -v
;;
up-monitoring)
MONITORING_STACK_DIR="${MONITORING_STACK_DIR:-./monitoring}" \
docker compose --env-file .env.local \
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
-f docker-compose.yml \
-f monitoring/docker-compose-monitoring.yml \
-f monitoring/docker-compose-monitoring-integration.yml \
up -d
;;
down-monitoring)
MONITORING_STACK_DIR="${MONITORING_STACK_DIR:-./monitoring}" \
docker compose \
-f docker-compose.yml \
-f monitoring/docker-compose-monitoring.yml \
-f monitoring/docker-compose-monitoring-integration.yml \
down
;;
*)
echo "Usage: bazel run //:docker-compose -- {up|down|fresh|up-monitoring|down-monitoring}"
exit 1
;;
esac
54 changes: 53 additions & 1 deletion pipeline/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
load("@rules_shell//shell:sh_test.bzl", "sh_test")
load("@rules_shell//shell:sh_binary.bzl", "sh_binary")
load("@rules_pkg//pkg:mappings.bzl", "pkg_files", "strip_prefix")
load("@rules_pkg//pkg:tar.bzl", "pkg_tar")
load("@rules_oci//oci:defs.bzl", "oci_image", "oci_load")

# Inputs Bazel tracks for cache invalidation — if none of these change,
# both targets below are skipped entirely (cache hit).
_SRCS = glob(
["src/**", "pom.xml", "checkstyle.xml", "maven-settings.xml"],
exclude = ["target/**"],
) + ["//apis/protobuf:protobuf_files"]
) + ["//apis/protobuf:protobuf_files", ".mvn/wrapper/maven-wrapper.properties"]

# TODO: Rename to run only unit tests (mvn test) once integration tests are separated
# (rename SecurityConfigTest.java -> SecurityConfigIT.java + add Failsafe plugin to pom.xml).
Expand Down Expand Up @@ -44,3 +47,52 @@ genrule(
local = True,
tags = ["manual"],
)

# Builds the app and OTEL agent JARs via Maven.
# Used as inputs to the OCI image build below.
genrule(
name = "pipeline_jars",
srcs = _SRCS + ["mvnw"],
Comment thread
Baibhab23 marked this conversation as resolved.
Resolved
outs = ["app.jar", "otel-agent.jar"],
cmd = """
(cd pipeline && ./mvnw clean package -DskipTests -Pmonitoring --batch-mode -q -Dbuild.dir=target/bazel-jars)
cp pipeline/target/bazel-jars/pipeline-0.0.1-SNAPSHOT.jar $(RULEDIR)/app.jar
cp pipeline/target/bazel-jars/agents/opentelemetry-javaagent.jar $(RULEDIR)/otel-agent.jar
""",
local = True,
tags = ["manual"],
)

pkg_files(
name = "app_files",
srcs = [":app.jar", ":otel-agent.jar"],
strip_prefix = strip_prefix.from_pkg(),
prefix = "/app",
)

pkg_tar(
name = "app_layer",
srcs = [":app_files"],
)

oci_image(
name = "pipeline_image",
base = "@eclipse_temurin_jdk17",
tars = [":app_layer"],
entrypoint = [
"java",
"-javaagent:/app/otel-agent.jar",
"-jar",
"/app/app.jar",
],
workdir = "/app",
)
Comment on lines +78 to +89

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Feels like we are repeating the build instructions again in bazel file as we already have these instructions in the Dockerfile.. is it not possible to reuse the dockerfile itself?


# Builds and loads the image into the local container daemon.
# Run with: bazel run //pipeline:pipeline_load
oci_load(
name = "pipeline_load",
image = ":pipeline_image",
repo_tags = ["pipeline-app:latest"],
)

2 changes: 2 additions & 0 deletions pipeline/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
<properties>
<java.version>17</java.version>
<protobuf.version>4.29.3</protobuf.version>
<build.dir>target</build.dir>
</properties>
<dependencies>
<dependency>
Expand Down Expand Up @@ -177,6 +178,7 @@
</dependencies>

<build>
<directory>${project.basedir}/${build.dir}</directory>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
Expand Down
2 changes: 1 addition & 1 deletion pipeline/run_generate_openapi.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
set -euo pipefail

cd "./pipeline/"
./mvnw --batch-mode -s maven-settings.xml verify -P integration-test -DskipTests
./mvnw --batch-mode -s maven-settings.xml verify -P integration-test -DskipTests -Dbuild.dir=target/bazel-openapi
Loading