github.com/apache/beam/sdks/v2@v2.48.2/python/container/common.gradle (about)

     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 :: Python ${pythonVersionSuffix} Container"
    22  
    23  configurations {
    24    sdkSourceTarball
    25    sdkHarnessLauncher
    26  }
    27  
    28  dependencies {
    29    sdkSourceTarball project(path: ":sdks:python", configuration: "distTarBall")
    30    sdkHarnessLauncher project(path: ":sdks:python:container", configuration: "sdkHarnessLauncher")
    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} " + "${pipExtraOptions}"
    43      }
    44    }
    45  }
    46  
    47  def copyDockerfileDependencies = tasks.register("copyDockerfileDependencies", Copy) {
    48    from configurations.sdkSourceTarball
    49    from file("base_image_requirements.txt")
    50    into "build/target"
    51    if(configurations.sdkSourceTarball.isEmpty()) {
    52        throw new StopExecutionException();
    53    }
    54  }
    55  
    56  def copyLicenseScripts = tasks.register("copyLicenseScripts", Copy){
    57    from ("../license_scripts")
    58    into "build/target/license_scripts"
    59  }
    60  
    61  def copyLauncherDependencies = tasks.register("copyLauncherDependencies", Copy) {
    62    from configurations.sdkHarnessLauncher
    63    into "build/target/launcher"
    64    if(configurations.sdkHarnessLauncher.isEmpty()) {
    65        throw new StopExecutionException();
    66    }
    67  }
    68  
    69  docker {
    70    name containerImageName(
    71            name: project.docker_image_default_repo_prefix + "python${project.ext.pythonVersion}_sdk",
    72            root: project.rootProject.hasProperty(["docker-repository-root"]) ?
    73                    project.rootProject["docker-repository-root"] :
    74                    project.docker_image_default_repo_root,
    75            tag: project.rootProject.hasProperty(["docker-tag"]) ?
    76                    project.rootProject["docker-tag"] : project.sdk_version)
    77    // tags used by dockerTag task
    78    tags containerImageTags()
    79    files "../Dockerfile", "./build"
    80    buildArgs(['py_version': "${project.ext.pythonVersion}",
    81               'pull_licenses': project.rootProject.hasProperty(["docker-pull-licenses"]) ||
    82                       project.rootProject.hasProperty(["isRelease"])])
    83    buildx project.containerPlatforms() != [project.nativeArchitecture()]
    84    platform(*project.containerPlatforms())
    85  }
    86  
    87  dockerPrepare.dependsOn copyLauncherDependencies
    88  dockerPrepare.dependsOn copyDockerfileDependencies
    89  dockerPrepare.dependsOn copyLicenseScripts
    90  
    91  if (project.rootProject.hasProperty(["docker-pull-licenses"])) {
    92    def copyGolangLicenses = tasks.register("copyGolangLicenses", Copy) {
    93      from "${project(':release:go-licenses:py').buildDir}/output"
    94      into "build/target/go-licenses"
    95      dependsOn ':release:go-licenses:py:createLicenses'
    96    }
    97    dockerPrepare.dependsOn copyGolangLicenses
    98  } else {
    99    def skipPullLicenses = tasks.register("skipPullLicenses", Exec) {
   100      executable "sh"
   101      // Touch a dummy file to ensure the directory exists.
   102      args "-c", "mkdir -p build/target/go-licenses && touch build/target/go-licenses/skip"
   103    }
   104    dockerPrepare.dependsOn skipPullLicenses
   105  }