Skip to content

Commit

Permalink
Update build.py
Browse files Browse the repository at this point in the history
  • Loading branch information
nusantara-self authored Feb 12, 2025
1 parent f7b3e7a commit c28a2b5
Showing 1 changed file with 27 additions and 7 deletions.
34 changes: 27 additions & 7 deletions build.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,27 @@
from dockerhub import Dockerhub
from harbor import Harbor

def docker_login(registry_string):
if '@' in registry_string:
creds, host = registry_string.split('@', 1)
if ':' in creds:
username, password = creds.split(':', 1)
else:
username = creds
password = None
cmd = ["docker", "login", host, "-u", username]
if password:
cmd.extend(["-p", password])
print(f"Logging in to {host} as {username}")
result = subprocess.run(cmd, capture_output=False, text=True)
if result.returncode != 0:
raise Exception("Docker login failed")
else:
print(f"Successfully logged in to {host}")
return host
else:
return registry_string


def list_flavor(path):
if isdir(path):
Expand Down Expand Up @@ -161,12 +182,11 @@ def main():
args = parser.parse_args()
args.docker_client = docker.from_env()
args.registry = []

for registry_string in args.registry_dockerhub:
registry = Dockerhub(args.docker_client, registry_string)
registry.login()
args.registry.append(registry)


for reg in args.registry_dockerhub:
host = docker_login(reg)
args.registry.append(host)

for registry_string in args.registry_harbor:
registry = Harbor(args.docker_client, registry_string)
registry.login()
Expand All @@ -182,4 +202,4 @@ def main():


if __name__ == '__main__':
main()
main()

0 comments on commit c28a2b5

Please sign in to comment.