Skip to content
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

Create Python SDK Distroless variant #33160

Merged
merged 3 commits into from
Nov 20, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
2 changes: 1 addition & 1 deletion .github/trigger_files/beam_PostCommit_Python.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"comment": "Modify this file in a trivial way to cause this test suite to run.",
"modification": 4
"modification": 5
}

46 changes: 46 additions & 0 deletions sdks/python/container/Dockerfile-distroless
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
###############################################################################
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
###############################################################################

ARG BASE
FROM ${BASE} AS base
ARG TARGETARCH
LABEL Author="Apache Beam <[email protected]>"

RUN if [ -z "${TARGETARCH}" ]; then echo "fatal: TARGETARCH not set; run as docker buildx build or use --build-arg=TARGETARCH=amd64|arm64" >&2; exit 1; fi

FROM gcr.io/distroless/python3-debian12:latest-${TARGETARCH} AS distroless

# Contains header files needed by the Python interpreter.
COPY --from=base /usr/local/include /usr/local/include

# Contains the Python interpreter executables.
COPY --from=base /usr/local/bin /usr/local/bin

# Contains the Python library dependencies.
COPY --from=base /usr/local/lib /usr/local/lib

# Python standard library modules.
COPY --from=base /usr/lib/python* /usr/lib/.

# Contains the boot entrypoint and related files such as licenses.
COPY --from=base /opt /opt
damondouglas marked this conversation as resolved.
Show resolved Hide resolved

ENV PATH "$PATH:/usr/local/bin"

# Despite the ENTRYPOINT set in base image, need to reset since deriving the layer derives from a different image.
ENTRYPOINT ["/opt/apache/beam/boot"]
damondouglas marked this conversation as resolved.
Show resolved Hide resolved
44 changes: 44 additions & 0 deletions sdks/python/test-suites/dataflow/common.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,50 @@ task validatesContainer() {
}
}

tasks.register('validatesDistrolessContainer', Task.class) {
dependsOn 'initializeForDataflowJob'
def repository = "us.gcr.io/apache-beam-testing/${System.getenv('USER')}"
def tag = java.time.Instant.now().getEpochSecond()
def imageURL = "${repository}/beam_python${pythonVersion}_sdk_distroless:${tag}"
doLast {
exec {
executable 'docker'
workingDir rootDir
args = [
'buildx',
'build',
'-t',
imageURL,
'-f',
'sdks/python/container/Dockerfile-distroless',
"--build-arg=BASE=gcr.io/apache-beam-testing/beam-sdk/beam_python${pythonVersion}_sdk",
"."
]
}
exec {
executable 'docker'
args = ['push', imageURL]
}
exec {
def testTarget = "apache_beam/examples/wordcount_it_test.py::WordCountIT::test_wordcount_it"
def argMap = [
"output" : "gs://temp-storage-for-end-to-end-tests/py-it-cloud/output",
Copy link
Contributor

Choose a reason for hiding this comment

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

ideally the temp location and project to run the test should be configurable. However I checked in Java SDK's gradle files it is the case, but not for python SDK's gradle files, so it is fine for now

"project" : "apache-beam-testing",
"region" : "us-central1",
"runner" : "TestDataflowRunner",
"sdk_container_image": "${imageURL}",
"sdk_location" : "container",
"staging_location" : "gs://temp-storage-for-end-to-end-tests/staging-it",
"temp_location" : "gs://temp-storage-for-end-to-end-tests/temp-it",
]
def cmdArgs = mapToArgString(argMap)
workingDir = "${rootDir}/sdks/python"
executable 'sh'
args '-c', ". ${envdir}/bin/activate && pytest ${testTarget} --test-pipeline-options=\"${cmdArgs}\""
}
}
}

task validatesContainerARM() {
def pyversion = "${project.ext.pythonVersion.replace('.', '')}"
dependsOn 'initializeForDataflowJob'
Expand Down
Loading