|
| 1 | +#!/usr/bin/env python3 |
| 2 | + |
| 3 | +import click |
| 4 | +import os |
| 5 | + |
| 6 | +from pygments.lexer import default |
| 7 | + |
| 8 | +from .registry import GlociRegistry |
| 9 | + |
| 10 | + |
| 11 | +@click.group() |
| 12 | +def cli(): |
| 13 | + pass |
| 14 | + |
| 15 | + |
| 16 | +@cli.command() |
| 17 | +@click.option( |
| 18 | + "--container", |
| 19 | + required=True, |
| 20 | + type=click.Path(), |
| 21 | + help="Container Name", |
| 22 | +) |
| 23 | +@click.option( |
| 24 | + "--version", |
| 25 | + required=True, |
| 26 | + type=click.Path(), |
| 27 | + help="Version of image", |
| 28 | +) |
| 29 | +@click.option( |
| 30 | + "--arch", |
| 31 | + required=True, |
| 32 | + type=click.Path(), |
| 33 | + help="Target Image CPU Architecture", |
| 34 | +) |
| 35 | +@click.option( |
| 36 | + "--cname", required=True, type=click.Path(), help="Canonical Name of Image" |
| 37 | +) |
| 38 | +@click.option("--dir", "directory", required=True, help="path to the build artifacts") |
| 39 | +@click.option( |
| 40 | + "--cosign_file", |
| 41 | + required=False, |
| 42 | + help="A file where the pushed manifests digests is written to. The content can be used by an external tool (e.g. cosign) to sign the manifests contents", |
| 43 | +) |
| 44 | +@click.option( |
| 45 | + "--manifest_file", |
| 46 | + default="manifests/manifest.json", |
| 47 | + help="A file where the index entry for the pushed manifest is written to.", |
| 48 | +) |
| 49 | +@click.option( |
| 50 | + "--insecure", |
| 51 | + default=False, |
| 52 | + help="Use HTTP to communicate with the registry", |
| 53 | +) |
| 54 | +def push_manifest( |
| 55 | + container, version, arch, cname, directory, cosign_file, manifest_file, insecure |
| 56 | +): |
| 57 | + """push artifacts from a dir to a registry, get the index-entry for the manifest in return""" |
| 58 | + container_name = f"{container}:{version}" |
| 59 | + registry = GlociRegistry( |
| 60 | + container_name=container_name, |
| 61 | + token=os.getenv("GLOCI_REGISTRY_TOKEN"), |
| 62 | + insecure=insecure, |
| 63 | + ) |
| 64 | + digest = registry.push_from_dir(arch, version, cname, directory, manifest_file) |
| 65 | + if cosign_file: |
| 66 | + print(digest, file=open(cosign_file, "w")) |
| 67 | + |
| 68 | + |
| 69 | +@cli.command() |
| 70 | +@click.option( |
| 71 | + "--container", |
| 72 | + "container", |
| 73 | + required=True, |
| 74 | + type=click.Path(), |
| 75 | + help="Container Name", |
| 76 | +) |
| 77 | +@click.option( |
| 78 | + "--version", |
| 79 | + "version", |
| 80 | + required=True, |
| 81 | + type=click.Path(), |
| 82 | + help="Version of image", |
| 83 | +) |
| 84 | +@click.option( |
| 85 | + "--manifest_folder", |
| 86 | + default="manifests", |
| 87 | + help="A folder where the index entries are read from.", |
| 88 | +) |
| 89 | +@click.option( |
| 90 | + "--insecure", |
| 91 | + default=False, |
| 92 | + help="Use HTTP to communicate with the registry", |
| 93 | +) |
| 94 | +def update_index(container, version, manifest_folder, insecure): |
| 95 | + """push a index entry from a list of files to an index""" |
| 96 | + container_name = f"{container}:{version}" |
| 97 | + registry = GlociRegistry( |
| 98 | + container_name=container_name, |
| 99 | + token=os.getenv("GLOCI_REGISTRY_TOKEN"), |
| 100 | + insecure=insecure, |
| 101 | + ) |
| 102 | + registry.update_index(manifest_folder) |
| 103 | + |
| 104 | + |
| 105 | +def main(): |
| 106 | + """Entry point for the glcli command.""" |
| 107 | + cli() |
| 108 | + |
| 109 | + |
| 110 | +if __name__ == "__main__": |
| 111 | + cli() |
0 commit comments