|
| 1 | +/* |
| 2 | + * Licensed to the Apache Software Foundation (ASF) under one |
| 3 | + * or more contributor license agreements. See the NOTICE file |
| 4 | + * distributed with this work for additional information |
| 5 | + * regarding copyright ownership. The ASF licenses this file |
| 6 | + * to you under the Apache License, Version 2.0 (the |
| 7 | + * License); you may not use this file except in compliance |
| 8 | + * with the License. You may obtain a copy of the License at |
| 9 | + * |
| 10 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | + * |
| 12 | + * Unless required by applicable law or agreed to in writing, software |
| 13 | + * distributed under the License is distributed on an AS IS BASIS, |
| 14 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | + * See the License for the specific language governing permissions and |
| 16 | + * limitations under the License. |
| 17 | + */ |
| 18 | + |
| 19 | +def pythonVersionSuffix = project.ext.pythonVersion.replace('.', '') |
| 20 | + |
| 21 | +description = "Apache Beam :: SDKs :: Python :: Container :: ML :: Python ${pythonVersionSuffix} Container" |
| 22 | + |
| 23 | +configurations { |
| 24 | + sdkSourceTarball |
| 25 | + pythonHarnessLauncher |
| 26 | +} |
| 27 | + |
| 28 | +dependencies { |
| 29 | + sdkSourceTarball project(path: ":sdks:python", configuration: "distTarBall") |
| 30 | + pythonHarnessLauncher project(path: ":sdks:python:container", configuration: "pythonHarnessLauncher") |
| 31 | +} |
| 32 | + |
| 33 | +def generatePythonRequirements = tasks.register("generatePythonRequirements") { |
| 34 | + dependsOn ':sdks:python:sdist' |
| 35 | + def pipExtraOptions = project.hasProperty("testRCDependencies") ? "--pre" : "" |
| 36 | + def runScriptsPath = "${rootDir}/sdks/python/container/run_generate_requirements.sh" |
| 37 | + doLast { |
| 38 | + exec { |
| 39 | + executable 'sh' |
| 40 | + args '-c', "cd ${rootDir} && ${runScriptsPath} " + |
| 41 | + "${project.ext.pythonVersion} " + |
| 42 | + "${files(configurations.sdkSourceTarball.files).singleFile} " + |
| 43 | + "base_image_requirements.txt " + |
| 44 | + "[gcp,dataframe,test] " + |
| 45 | + "${pipExtraOptions}" |
| 46 | + } |
| 47 | + // Generate versions for ML dependencies |
| 48 | + exec { |
| 49 | + executable 'sh' |
| 50 | + args '-c', "cd ${rootDir} && ${runScriptsPath} " + |
| 51 | + "${project.ext.pythonVersion} " + |
| 52 | + "${files(configurations.sdkSourceTarball.files).singleFile} " + |
| 53 | + "ml_image_requirements.txt " + |
| 54 | + "[gcp,dataframe,test,tensorflow,torch,transformers] " + |
| 55 | + "${pipExtraOptions}" |
| 56 | + } |
| 57 | + } |
| 58 | +} |
| 59 | + |
| 60 | +def copyDockerfileDependencies = tasks.register("copyDockerfileDependencies", Copy) { |
| 61 | + from configurations.sdkSourceTarball |
| 62 | + from file("base_image_requirements.txt") |
| 63 | + into "build/target" |
| 64 | + if(configurations.sdkSourceTarball.isEmpty()) { |
| 65 | + throw new StopExecutionException(); |
| 66 | + } |
| 67 | +} |
| 68 | + |
| 69 | +def copyLicenseScripts = tasks.register("copyLicenseScripts", Copy){ |
| 70 | + from ("../license_scripts") |
| 71 | + into "build/target/license_scripts" |
| 72 | +} |
| 73 | + |
| 74 | +def copyLauncherDependencies = tasks.register("copyLauncherDependencies", Copy) { |
| 75 | + from configurations.pythonHarnessLauncher |
| 76 | + into "build/target/launcher" |
| 77 | + |
| 78 | + // Avoid seemingly gradle bug stated in https://github.com/apache/beam/issues/29220 |
| 79 | + mustRunAfter "copyLicenses" |
| 80 | + |
| 81 | + if(configurations.pythonHarnessLauncher.isEmpty()) { |
| 82 | + throw new StopExecutionException(); |
| 83 | + } |
| 84 | +} |
| 85 | + |
| 86 | +def pushContainers = project.rootProject.hasProperty(["isRelease"]) || project.rootProject.hasProperty("push-containers") |
| 87 | + |
| 88 | +docker { |
| 89 | + name containerImageName( |
| 90 | + name: project.docker_image_default_repo_prefix + "python${project.ext.pythonVersion}_sdk_ml", |
| 91 | + root: project.rootProject.hasProperty(["docker-repository-root"]) ? |
| 92 | + project.rootProject["docker-repository-root"] : |
| 93 | + project.docker_image_default_repo_root, |
| 94 | + tag: project.rootProject.hasProperty(["docker-tag"]) ? |
| 95 | + project.rootProject["docker-tag"] : project.sdk_version) |
| 96 | + // tags used by dockerTag task |
| 97 | + tags containerImageTags() |
| 98 | + files "../../Dockerfile", "./build" |
| 99 | + buildArgs(['py_version': "${project.ext.pythonVersion}", |
| 100 | + 'pull_licenses': project.rootProject.hasProperty(["docker-pull-licenses"]) || |
| 101 | + project.rootProject.hasProperty(["isRelease"])]) |
| 102 | + buildx project.useBuildx() |
| 103 | + platform(*project.containerPlatforms()) |
| 104 | + load project.useBuildx() && !pushContainers |
| 105 | + push pushContainers |
| 106 | +} |
| 107 | + |
| 108 | +dockerPrepare.dependsOn copyLauncherDependencies |
| 109 | +dockerPrepare.dependsOn copyDockerfileDependencies |
| 110 | +dockerPrepare.dependsOn copyLicenseScripts |
| 111 | + |
| 112 | +if (project.rootProject.hasProperty("docker-pull-licenses")) { |
| 113 | + def copyGolangLicenses = tasks.register("copyGolangLicenses", Copy) { |
| 114 | + from "${project(':release:go-licenses:py').buildDir}/output" |
| 115 | + into "build/target/go-licenses" |
| 116 | + dependsOn ':release:go-licenses:py:createLicenses' |
| 117 | + } |
| 118 | + dockerPrepare.dependsOn copyGolangLicenses |
| 119 | +} else { |
| 120 | + def skipPullLicenses = tasks.register("skipPullLicenses", Exec) { |
| 121 | + executable "sh" |
| 122 | + // Touch a dummy file to ensure the directory exists. |
| 123 | + args "-c", "mkdir -p build/target/go-licenses && touch build/target/go-licenses/skip" |
| 124 | + } |
| 125 | + dockerPrepare.dependsOn skipPullLicenses |
| 126 | +} |
0 commit comments