Skip to content

Commit

Permalink
feat: Add registry docker-login command
Browse files Browse the repository at this point in the history
  • Loading branch information
Dr0p42 committed Sep 19, 2023
1 parent 07e262c commit 69f439e
Showing 1 changed file with 24 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from rich.console import Console
from rich.table import Table
from typer.core import TyperGroup
import os

from naas_python.domains.registry.RegistrySchema import (
IRegistryDomain,
Expand Down Expand Up @@ -47,6 +48,7 @@ def __init__(self, domain: IRegistryDomain):
self.app.command()(self.get)
self.app.command()(self.delete)
self.app.command()(self.get_credentials)
self.app.command()(self.docker_login)

def _list_preview(self, data: List[dict], headers: list):
if not isinstance(data, list):
Expand Down Expand Up @@ -215,3 +217,25 @@ def get_credentials(
self.console.print(
Panel.fit(f"Registry credentials saved to '{name}-credentials.txt'")
)

def docker_login(
self,
name: str = typer.Option(
..., "--name", "-n", help="Docker login for registry"
),
):
"""Execute Docker login for the specified registry"""
registry = self.domain.get_registry_by_name(name=name)

uri = registry.registry.uri
response = self.domain.get_credentials(name=name)
username = response.credentials.username
password = response.credentials.password


exec_code = os.system(f"echo '{password}' | docker login --username '{username}' --password-stdin '{uri}'")
if exec_code == 0:
self.console.print(
Panel.fit(f"You can now push containers to '{uri}'")
)

0 comments on commit 69f439e

Please sign in to comment.