You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@yunikorn.apache.org by GitBox <gi...@apache.org> on 2022/06/17 19:24:48 UTC

[GitHub] [yunikorn-release] craigcondit commented on a diff in pull request #95: [YUNIKORN-1215] multi architecture build

craigcondit commented on code in PR #95:
URL: https://github.com/apache/yunikorn-release/pull/95#discussion_r900447615


##########
tools/build-image.py:
##########
@@ -0,0 +1,276 @@
+# 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.
+
+import getopt
+import getpass
+import json
+import os
+import shutil
+import subprocess
+
+import sys
+
+# Supported host architectures for executables and docker images
+# Mapped to the correct settings in the Makefile
+architecture = {"x86_64": "amd64",
+                "aarch64": "arm64v8"}
+# Make targets for the shim repo to generate the images
+targets = {"adm_image": "admission",
+           "sched_image": "scheduler",
+           "plugin_image": "scheduler-plugin"}
+# registry setting passed to Makefile to allow testing of the script
+repository = "apache"
+# authentication info for docker hub
+docker_user = ""
+docker_pass = ""
+docker_token = ""
+
+
+# fail the execution
+def fail(message):
+    print(message)
+    sys.exit(1)
+
+
+# get the command from the path
+def get_cmd(name):
+    cmd = shutil.which(name)
+    if not cmd:
+        fail("command not found on the path: '%s'" % name)
+    return cmd
+
+
+# load the config, based on the build-release.py code.
+def load_config():
+    tools_dir = os.path.dirname(os.path.realpath(__file__))
+    # load configs
+    config_file = os.path.join(tools_dir, "release-configs.json")
+    with open(config_file) as configs:
+        try:
+            data = json.load(configs)
+        except json.JSONDecodeError:
+            fail("load config: unexpected json decode failure")
+
+    if "release" not in data:
+        fail("load config: release data not found")
+    release_meta = data["release"]
+    if "version" not in release_meta:
+        fail("load config: version data not found in release")
+    version = release_meta["version"]
+    release_package_name = "apache-yunikorn-{0}-src".format(version)
+    if "repositories" not in data:
+        fail("load config: repository list not found")
+    repo_list = data["repositories"]
+
+    staging_dir = os.path.join(os.path.dirname(tools_dir), "staging")
+    release_base = os.path.join(staging_dir, release_package_name)
+
+    print("release meta info:")
+    print(" - version:        %s" % version)
+    print(" - base directory: %s" % release_base)
+    print(" - package name:   %s" % release_package_name)
+
+    if not os.path.exists(release_base):
+        fail("Staged release dir does not exist:\n\t%s" % release_base)
+    return version, repo_list, release_base
+
+
+# Cleanup image tag
+def remove_tag(image_name):
+    splits = image_name.split(":")
+    if len(splits) != 2:
+        fail("Image name is not in the required format")
+    cmd = get_cmd("curl")
+    curl = [cmd, "-X", "DELETE", "-H", "Authorization: JWT " + docker_token]
+    curl.extend(["https://hub.docker.com/v2/repositories/" + splits[0] + "/tags/" + splits[1] + "/"])
+    retcode = subprocess.call(curl)
+    if retcode:
+        fail("docker tag cleanup failed")
+
+
+# Push an image or manifest
+def push_image(cmd, image_name):
+    push = [cmd, "push", image_name]
+    retcode = subprocess.call(push, stdout=subprocess.DEVNULL)
+    if retcode:
+        fail("docker push failed")
+
+
+# get token for rest
+# 2FA is not supported by this code (yet) but can be added
+def get_token():
+    cmd = get_cmd("curl")
+    curl = [cmd, "-X", "POST", "-H", "Content-Type: application/json"]
+    curl.extend(["-d", '{"username": "' + docker_user + '", "password": "' + docker_pass + '"}'])
+    curl.extend(["https://hub.docker.com/v2/users/login/"])
+    p = subprocess.run(curl, capture_output=True)
+    try:
+        data = json.loads(p.stdout)
+    except json.JSONDecodeError:
+        fail("login failed: unexpected json decode failure: %s" %p.stdout)
+    if "detail" in data:
+        fail("authentication failed: %s" % data["detail"])
+    if "token" not in data:
+        fail("login failed: unexpected json content: %s" % data)
+    global docker_token
+    docker_token = data["token"]
+
+
+# get user and password on startup
+def get_auth():
+    global docker_user
+    docker_user = input("Enter docker hub username: ")
+    global docker_pass
+    docker_pass = getpass.getpass(prompt="Docker hub password: ", stream=None)
+    if docker_pass == "" | docker_user == "":

Review Comment:
   This fails on python3: `TypeError: unsupported operand type(s) for |: 'str' and 'str'`. Adding parenthesis around each subexpression works:
   
   ```
   if (docker_pass == "") | (docker_user == ""):
   ```



##########
tools/build-image.py:
##########
@@ -0,0 +1,276 @@
+# Licensed to the Apache Software Foundation (ASF) under one

Review Comment:
   Minor nit: python scripts should start with:
   
   ```
   #!/usr/bin/env python3
   ```



-- 
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.

To unsubscribe, e-mail: dev-unsubscribe@yunikorn.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@yunikorn.apache.org
For additional commands, e-mail: dev-help@yunikorn.apache.org