You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@beam.apache.org by "ASF GitHub Bot (Jira)" <ji...@apache.org> on 2020/04/01 21:00:02 UTC

[jira] [Work logged] (BEAM-9136) Add LICENSES and NOTICES to docker images

     [ https://issues.apache.org/jira/browse/BEAM-9136?focusedWorklogId=414287&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-414287 ]

ASF GitHub Bot logged work on BEAM-9136:
----------------------------------------

                Author: ASF GitHub Bot
            Created on: 01/Apr/20 20:59
            Start Date: 01/Apr/20 20:59
    Worklog Time Spent: 10m 
      Work Description: Hannah-Jiang commented on pull request #11067: [BEAM-9136]Add licenses for dependencies for Python
URL: https://github.com/apache/beam/pull/11067#discussion_r401905887
 
 

 ##########
 File path: sdks/python/container/license_scripts/pull_licenses_py.py
 ##########
 @@ -0,0 +1,143 @@
+#
+# 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.
+#
+
+"""
+A script to pull licenses for Python.
+The script is executed within Docker.
+"""
+import json
+import os
+import shutil
+import subprocess
+import sys
+import tempfile
+import traceback
+import yaml
+
+from future.moves.urllib.request import urlopen
+from tenacity import retry
+from tenacity import stop_after_attempt
+from tenacity import wait_exponential
+
+LICENSE_DIR = '/opt/apache/beam/third_party_licenses'
+
+
+def run_bash_command(command):
+  return subprocess.check_output(command.split()).decode('utf-8')
+
+
+def run_pip_licenses():
+  command = 'pip-licenses --with-license-file --format=json'
+  dependencies = run_bash_command(command)
+  return json.loads(dependencies)
+
+
+@retry(stop=stop_after_attempt(3))
+def copy_license_files(dep):
+  source_license_file = dep['LicenseFile']
+  if source_license_file.lower() == 'unknown':
+    return False
+  name = dep['Name'].lower()
+  dest_dir = '/'.join([LICENSE_DIR, name])
+  try:
+    os.mkdir(dest_dir)
+    shutil.copy(source_license_file, dest_dir + '/LICENSE')
+    print(
+        'Successfully pulled license for {dep} with pip-licenses.'.format(
+            dep=name))
+    return True
+  except Exception as e:
+    print(
+        'Failed to copy from {source} to {dest}'.format(
+            source=source_license_file, dest=dest_dir + '/LICENSE'))
+    traceback.print_exc()
+
+
+@retry(wait=wait_exponential(multiplier=1, min=30, max=180))
+def pull_from_url(dep, configs):
+  '''
+  :param dep: name of a dependency
+  :param configs: a dict from dep_urls_py.yaml
+  :return: boolean
+
+  It downloads files form urls to a temp directory first in order to avoid
+  to deal with any temp files. It helps keep clean final directory.
+  '''
+  if dep in configs:
+    config = configs[dep]
+    dest_dir = '/'.join([LICENSE_DIR, dep])
+    cur_temp_dir = tempfile.mkdtemp()
+
+    try:
+      if config['license'] == 'skip':
+        print('Skip pulling license for ', dep)
+      else:
+        url_read = urlopen(config['license'])
+        with open(cur_temp_dir + '/LICENSE', 'wb') as temp_write:
+          shutil.copyfileobj(url_read, temp_write, length=1 << 20)
+        print(
+            'Successfully pulled license for {dep} from {url}.'.format(
+                dep=dep, url=config['license']))
+
+      # notice is optional.
+      if 'notice' in config:
+        url_read = urlopen(config['notice'])
+        with open(cur_temp_dir + '/NOTICE', 'wb') as temp_write:
+          shutil.copyfileobj(url_read, temp_write, length=1 << 20)
+
+      shutil.copytree(cur_temp_dir, dest_dir)
+      shutil.rmtree(cur_temp_dir)
+      return True
+    except Exception as e:
+      shutil.rmtree(cur_temp_dir)
 
 Review comment:
   If we want to put this to finally, we need to move the `return True` at L106 to the finally too, then retry will not be triggered.
 
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Issue Time Tracking
-------------------

    Worklog Id:     (was: 414287)
    Time Spent: 15h 20m  (was: 15h 10m)

> Add LICENSES and NOTICES to docker images
> -----------------------------------------
>
>                 Key: BEAM-9136
>                 URL: https://issues.apache.org/jira/browse/BEAM-9136
>             Project: Beam
>          Issue Type: Task
>          Components: build-system
>            Reporter: Hannah Jiang
>            Assignee: Hannah Jiang
>            Priority: Major
>          Time Spent: 15h 20m
>  Remaining Estimate: 0h
>
> Scan dependencies and add licenses and notices of the dependencies to SDK docker images.



--
This message was sent by Atlassian Jira
(v8.3.4#803005)