Repository navigation
Updated Bazel configuration and add Docker support #277
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
e674934
97c5c84
413bd02
3abbc2c
cb77b1d
f5aa80c
d89acfa
e08a139
3a0b6de
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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"], | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
| ) | ||
| 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") | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? |
||
Large diffs are not rendered by default.
| 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 \ | ||
|
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 | ||
| 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). | ||
|
|
@@ -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"], | ||
|
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
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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"], | ||
| ) | ||
|
|
||
There was a problem hiding this comment.
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