src/cmd-remote-build-container: move some code to main()
Makes a little more sense to have some of this meat in
the main() function.
@@ -51,7 +51,21 @@ def search(repo, tag):
return False
def main():
- parse_args()
+ args = parse_args()
+
+ if environ.get('CONTAINER_HOST') is None or environ.get('CONTAINER_SSHKEY') is None:
+ sys.exit('You must have CONTAINER_HOST and CONTAINER_SSHKEY environment variables setup')
+
+ if not args.tag:
+ # If a tag wasn't passed then use the git
+ # short commit hash
+ commit = run_cmd(f"git ls-remote {args.git_url} {args.git_ref}")[0:6].decode("utf-8")
+ tag = f"{args.arch}-{commit}"
+ else:
+ tag = args.tag
+ build(args.label, args.git_url, args.git_ref, args.repo, tag)
+ if args.push_to_registry:
+ push(args.repo, tag, args.force)
def parse_args():
parser = argparse.ArgumentParser(
@@ -96,21 +110,8 @@ Examples:
'--tag', required=False,
help='Force image tag. The default is arch-commit')
- args = parser.parse_args()
+ return parser.parse_args()
- if environ.get('CONTAINER_HOST') is None or environ.get('CONTAINER_SSHKEY') is None:
- sys.exit('You must have CONTAINER_HOST and CONTAINER_SSHKEY environment variables setup')
-
- if not args.tag:
- # If a tag wasn't passed then use the git
- # short commit hash
- commit = run_cmd(f"git ls-remote {args.git_url} {args.git_ref}")[0:6].decode("utf-8")
- tag = f"{args.arch}-{commit}"
- else:
- tag = args.tag
- build(args.label, args.git_url, args.git_ref, args.repo, tag)
- if args.push_to_registry:
- push(args.repo, tag, args.force)
if __name__ == '__main__':
sys.exit(main())
