Skip to content

Use distroless container built from HEAD in Dataflow V2 integration tests - #36160

Merged
kennknowles merged 1 commit into
apache:masterfrom
kennknowles:df-examples-v2
Sep 17, 2025
Merged

Use distroless container built from HEAD in Dataflow V2 integration tests#36160
kennknowles merged 1 commit into
apache:masterfrom
kennknowles:df-examples-v2

Conversation

@kennknowles

Copy link
Copy Markdown
Member

Previously, the Dataflow V2 tests rebuilt the distroless container using an overridden base image that was the :latest tag from the live docker repo. Now it should use the version that was built from head, and the V1 and V2 logic are roughly matching.

I did not refactor to make them share code, because I don't yet know exactly which parts of the shared code would be from logical necessity.


Thank you for your contribution! Follow this checklist to help us incorporate your contribution quickly and easily:

  • Mention the appropriate issue in your description (for example: addresses #123), if applicable. This will automatically add a link to the pull request in the issue. If you would like the issue to automatically close on merging the pull request, comment fixes #<ISSUE NUMBER> instead.
  • Update CHANGES.md with noteworthy changes.
  • If this contribution is large, please file an Apache Individual Contributor License Agreement.

See the Contributor Guide for more tips on how to make review process smoother.

To check the build health, please visit https://github.com/apache/beam/blob/master/.test-infra/BUILD_STATUS.md

GitHub Actions Tests Status (on master branch)

Build python source distribution and wheels
Python tests
Java tests
Go tests

See CI.md for more information about GitHub Actions CI or the workflows README to see a list of phrases to trigger workflows.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Summary of Changes

Hello @kennknowles, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request updates the Dataflow V2 integration test configuration to ensure that the distroless container images used for testing are built directly from the current source code (HEAD) rather than relying on potentially outdated :latest tags. This change improves the consistency and reliability of the integration tests by guaranteeing that tests run against the most recent code, aligning the V1 and V2 testing methodologies.

Highlights

  • Distroless Image Definition: Defined new Gradle properties dockerJavaDistrolessImageContainer and dockerJavaDistrolessImageName to specifically manage the distroless Java SDK container image within the build system.
  • Pipeline Options Refactoring: Refactored Dataflow V2 pipeline options by introducing runnerV2CommonPipelineOptions and then deriving runnerV2PipelineOptions and runnerV2DistrolessPipelineOptions for clearer and more explicit configuration of container images.
  • Streamlined Distroless Build Process: Replaced the previous buildAndPushDistrolessContainerImage task with a new buildAndPushDistrolessDockerJavaContainer task. This new task correctly builds the distroless image from HEAD, ensuring tests use the latest code.
  • Updated Integration Test Task: The examplesJavaRunnerV2IntegrationTestDistroless task was updated and re-positioned to depend on the new buildAndPushDistrolessDockerJavaContainer task and now correctly utilizes the runnerV2DistrolessPipelineOptions.
  • New Pre-Commit Task: Introduced a new examplesJavaDistrolessRunnerV2PreCommit task specifically for running pre-commit tests with the distroless container, enhancing the testing suite.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in issue comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@kennknowles
kennknowles force-pushed the df-examples-v2 branch 5 times, most recently from a90f08f to 8b7db44 Compare September 15, 2025 17:37
@github-actions

Copy link
Copy Markdown
Contributor

Checks are failing. Will not request review until checks are succeeding. If you'd like to override that behavior, comment assign set of reviewers

@kennknowles
kennknowles force-pushed the df-examples-v2 branch 3 times, most recently from fe243f3 to 4a1186a Compare September 15, 2025 18:40
@kennknowles

Copy link
Copy Markdown
Member Author

R: @Abacn

@kennknowles

Copy link
Copy Markdown
Member Author

CC @sjvanrossum

@github-actions

Copy link
Copy Markdown
Contributor

Stopping reviewer notifications for this pull request: review requested by someone other than the bot, ceding control. If you'd like to restart, comment assign set of reviewers

@kennknowles

Copy link
Copy Markdown
Member Author

Now that it is actually using the built container, the workflow may be too short of a timeout

@kennknowles

Copy link
Copy Markdown
Member Author

Actually it has a 180 minute timeout but seems to be canceled after 16 minutes repeatedly. I don't know why.

@kennknowles

Copy link
Copy Markdown
Member Author

When approved, I will resolve the trivial conflict in the json file, or just drop that trigger file commit, then merge without waiting for the very-long very-flaky tests to rerun.

Comment on lines +304 to 320
def buildAndPushDockerJavaContainer = tasks.register("buildAndPushDockerJavaContainer") {
def javaVer = getSupportedJavaVersion(project.findProperty('testJavaVersion') as String)

tasks.register('buildAndPushDistrolessContainerImage', Task.class) {
// Only Java 17 and 21 are supported.
// See https://github.com/GoogleContainerTools/distroless/tree/main/java#image-contents.
def allowed = ["java17", "java21"]
dependsOn ":sdks:java:container:${javaVer}:docker"
def defaultDockerImageName = containerImageName(
name: "${project.docker_image_default_repo_prefix}${javaVer}_sdk",
root: "apache",
tag: project.sdk_version)
doLast {
def javaVer = getSupportedJavaVersion(project.findProperty('testJavaVersion') as String)
if (!allowed.contains(javaVer)) {
throw new GradleException("testJavaVersion must be one of ${allowed}, got: ${javaVer}")
}
if (!project.hasProperty('dockerTag')) {
throw new GradleException("dockerTag is missing but required")
}
def repository = "us.gcr.io/apache-beam-testing/${System.getenv('USER')}"
def tag = project.findProperty('dockerTag')
def imageURL = "${repository}/beam_${javaVer}_sdk_distroless:${tag}"
exec {
executable 'docker'
workingDir rootDir
args = [
'buildx',
'build',
'-t',
imageURL,
'-f',
'sdks/java/container/distroless/Dockerfile',
"--build-arg=BEAM_BASE=gcr.io/apache-beam-testing/beam-sdk/beam_${javaVer}_sdk",
"--build-arg=DISTROLESS_BASE=gcr.io/distroless/${javaVer}-debian12",
'.'
]
commandLine "docker", "tag", "${defaultDockerImageName}", "${dockerJavaImageName}"
}
exec {
executable 'docker'
args = ['push', imageURL]
commandLine "gcloud", "docker", "--", "push", "${dockerJavaImageName}"
}
}
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

:sdks:java:container:${javaVer}:dockerPush should handle this if gcloud auth configure-docker ... was executed before Gradle, right?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I believe this command is the one that does the copying, resolving according to this logic:

def dockerImageRoot = project.findProperty('dockerImageRoot') ?: "us.gcr.io/${gcpProject.replaceAll(':', '/')}/java-postcommit-it"

So it will push a copy of the image from :sdks:java:container:...:dockerPush to the java-postcommit-it repository or the dockerImageRoot that has been overridden by GHA.

Or anyhow that's my understanding of this logic. I could be wrong, or the logic could also be excessive.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Ah, I think some amount of this is to enable command line usage by someone who wants everything to run in a different GCP project. But I do think most or all of this logic should probably/eventually be owned by the :sdks:harness module. It may take some effort to figure out how much is necessary versus how much was just someone not realizing that the SDK harness is a thing that can and should exist fully independent of the :runners:google-cloud-dataflow-java project, and not require custom logic here to be utilized.

@Abacn Abacn Sep 17, 2025

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

There are at least 3 ways to push containers in different gradle scripts: :docker -Ppush-containers; :dockerPush and invoke docker push in a custom task. It could be a separate task to clean up all of them.

Current build.gradle invokes docker push directly at least it does not add more mess so lgtm

Comment on lines 349 to 338

// Push docker images to a container registry for use within tests.
// NB: Tasks which consume docker images from the registry should depend on this
// task directly ('dependsOn buildAndPushDockerJavaContainer'). This ensures the correct
// task ordering such that the registry doesn't get cleaned up prior to task completion.
def buildAndPushDockerJavaContainer = tasks.register("buildAndPushDockerJavaContainer") {
def buildAndPushDistrolessDockerJavaContainer = tasks.register("buildAndPushDistrolessDockerJavaContainer") {
def javaVer = getSupportedJavaVersion(project.findProperty('testJavaVersion') as String)

dependsOn ":sdks:java:container:${javaVer}:docker"
dependsOn ":sdks:java:container:distroless:${javaVer}:docker"
def defaultDockerImageName = containerImageName(
name: "${project.docker_image_default_repo_prefix}${javaVer}_sdk",
root: "apache",
tag: project.sdk_version)
name: "${project.docker_image_default_repo_prefix}${javaVer}_sdk_distroless",
root: "apache",
tag: project.sdk_version)
doLast {
exec {
commandLine "docker", "tag", "${defaultDockerImageName}", "${dockerJavaImageName}"
commandLine "docker", "tag", "${defaultDockerImageName}", "${dockerJavaDistrolessImageName}"
}
exec {
commandLine "gcloud", "docker", "--", "push", "${dockerJavaImageName}"
commandLine "gcloud", "docker", "--", "push", "${dockerJavaDistrolessImageName}"
}
}
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Same here for :sdks:java:container:distroless:${javaVer}:dockerPush.

@kennknowles
kennknowles merged commit f3222ed into apache:master Sep 17, 2025
16 checks passed
@kennknowles
kennknowles deleted the df-examples-v2 branch September 17, 2025 17:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants