Skip to content

[Gradle] Clean up DataflowRunner's Java distroless container image build tasks #34999

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

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

sjvanrossum
Copy link
Contributor

@sjvanrossum sjvanrossum commented May 19, 2025

Parts of this build file appear to be duplicated and/or outdated.

The container image build script in this build file:

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"]
  doLast {
    def javaVer = project.findProperty('testJavaVersion')
    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/Dockerfile-distroless',
              "--build-arg=BEAM_BASE=gcr.io/apache-beam-testing/beam-sdk/beam_${javaVer}_sdk",
              "--build-arg=DISTROLESS_BASE=gcr.io/distroless/${javaVer}-debian12",
              '.'
      ]
    }
    exec {
      executable 'docker'
      args = ['push', imageURL]
    }
  }
}

Compared to the build file in sdks/java/container/distroless:

docker {
    name containerImageName(
            name: "${base_name}_distroless",
            root: root,
            tag: tag)
    tags containerImageTags()
    dockerfile project.file("../Dockerfile")
    files "./build/"
    buildArgs([
            'BEAM_BASE': base,
            'DISTROLESS_BASE': "gcr.io/distroless/java${imageJavaVersion}-debian12"
    ])
    buildx project.useBuildx()
    platform(*project.containerPlatforms())
    load project.useBuildx() && !pushContainers
    push pushContainers
}

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.

@sjvanrossum sjvanrossum changed the title Fix version gating for buildAndPushDistrolessContainerImage [Gradle] Fix version gating for buildAndPushDistrolessContainerImage May 19, 2025
@sjvanrossum sjvanrossum force-pushed the gradle-fix-missing-dep branch from 510d29d to dda4c02 Compare May 19, 2025 14:31
Copy link
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

@sjvanrossum sjvanrossum marked this pull request as draft May 19, 2025 15:48
@sjvanrossum sjvanrossum force-pushed the gradle-fix-missing-dep branch from 9fac2e1 to 7555d60 Compare May 19, 2025 18:44
@sjvanrossum sjvanrossum changed the title [Gradle] Fix version gating for buildAndPushDistrolessContainerImage [Gradle] Clean up DataflowRunner's Java distroless container image build tasks May 20, 2025
@sjvanrossum
Copy link
Contributor Author

Run Java PreCommit

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.

1 participant