async def push_docker_images( request: PublishDockerImageRequest, docker: DockerBinary, options: DockerOptions ) -> PublishProcesses: tags = tuple( chain.from_iterable( cast(BuiltDockerImage, image).tags for pkg in request.packages for image in pkg.artifacts ) ) if request.field_set.skip_push.value: return PublishProcesses( [ PublishPackages( names=tags, description=f"(by `{request.field_set.skip_push.alias}` on {request.field_set.address})", ), ] ) env = await Get(Environment, EnvironmentRequest(options.env_vars)) processes = zip(tags, docker.push_image(tags, env)) return PublishProcesses( [ PublishPackages( names=(tag,), process=InteractiveProcess.from_process(process), ) for tag, process in processes ] )
async def push_docker_images( request: PublishDockerImageRequest, docker: DockerBinary, options: DockerOptions ) -> PublishProcesses: tags = tuple( chain.from_iterable( cast(BuiltDockerImage, image).tags for pkg in request.packages for image in pkg.artifacts ) ) if request.field_set.skip_push.value: return PublishProcesses( [ PublishPackages( names=tags, description=f"(by `{request.field_set.skip_push.alias}` on {request.field_set.address})", ), ] ) process = docker.push_image(tags) return PublishProcesses( [ PublishPackages( names=tags, process=InteractiveProcess.from_process(process) if process else None, ), ] )
async def push_docker_images(request: PublishDockerImageRequest, docker: DockerBinary, options: DockerOptions) -> PublishProcesses: tags = tuple( chain.from_iterable( cast(BuiltDockerImage, image).tags for pkg in request.packages for image in pkg.artifacts)) if request.field_set.skip_push.value: return PublishProcesses([ PublishPackages( names=tags, description= f"(by `{request.field_set.skip_push.alias}` on {request.field_set.address})", ), ]) env = await Get(Environment, EnvironmentRequest(options.env_vars)) skip_push = defaultdict(set) jobs: list[PublishPackages] = [] refs: list[str] = [] processes: list[Get] = [] for tag in tags: for registry in options.registries().registries.values(): if tag.startswith(registry.address) and registry.skip_push: skip_push[registry.alias].add(tag) break else: refs.append(tag) processes.append( Get(InteractiveProcess, InteractiveProcessRequest(docker.push_image(tag, env)))) interactive_processes = await MultiGet(processes) for ref, process in zip(refs, interactive_processes): jobs.append(PublishPackages( names=(ref, ), process=process, )) if skip_push: for name, skip_tags in skip_push.items(): jobs.append( PublishPackages( names=tuple(skip_tags), description=f"(by `skip_push` on registry @{name})", ), ) return PublishProcesses(jobs)
async def mock_publish(request: MockPublishRequest) -> PublishProcesses: if not request.field_set.repositories.value: return PublishProcesses() return PublishProcesses( PublishPackages( names=tuple(artifact.relpath for pkg in request.packages for artifact in pkg.artifacts if artifact.relpath), process=None if repo == "skip" else InteractiveProcess(["echo", repo]), description="(requested)" if repo == "skip" else repo, ) for repo in request.field_set.repositories.value)
async def twine_upload(request: PublishToPyPiRequest, twine_subsystem: TwineSubsystem) -> PublishProcesses: dists = tuple(artifact.relpath for pkg in request.packages for artifact in pkg.artifacts if artifact.relpath) if twine_subsystem.skip or not dists: return PublishProcesses() # Too verbose to provide feedback as to why some packages were skipped? skip = None if request.field_set.skip_twine.value: skip = f"(by `{request.field_set.skip_twine.alias}` on {request.field_set.address})" elif not request.field_set.repositories.value: # I'd rather have used the opt_out mechanism on the field set, but that gives no hint as to # why the target was not applicable.. skip = f"(no `{request.field_set.repositories.alias}` specified for {request.field_set.address})" if skip: return PublishProcesses([ PublishPackages( names=dists, description=skip, ), ]) twine_pex, packages_digest, config_files = await MultiGet( Get( VenvPex, PexRequest( output_filename="twine.pex", internal_only=True, requirements=twine_subsystem.pex_requirements(), interpreter_constraints=twine_subsystem. interpreter_constraints, main=twine_subsystem.main, ), ), Get(Digest, MergeDigests(pkg.digest for pkg in request.packages)), Get(ConfigFiles, ConfigFilesRequest, twine_subsystem.config_request()), ) input_digest = await Get( Digest, MergeDigests((packages_digest, config_files.snapshot.digest))) pex_proc_requests = [] twine_envs = await MultiGet( Get(Environment, EnvironmentRequest, twine_env_request(repo)) for repo in request.field_set.repositories.value) for repo, env in zip(request.field_set.repositories.value, twine_envs): pex_proc_requests.append( VenvPexProcess( twine_pex, argv=twine_upload_args(twine_subsystem, config_files, repo, dists), input_digest=input_digest, extra_env=twine_env(env, repo), description=repo, )) processes = await MultiGet( Get(Process, VenvPexProcess, request) for request in pex_proc_requests) return PublishProcesses( PublishPackages( names=dists, process=InteractiveProcess.from_process(process), description=process.description, data=PublishOutputData({"repository": process.description}), ) for process in processes)
async def publish_helm_chart( request: PublishHelmChartRequest, helm_subsystem: HelmSubsystem) -> PublishProcesses: remotes = helm_subsystem.remotes() built_artifacts = [ (pkg, artifact, artifact.metadata) for pkg in request.packages for artifact in pkg.artifacts if isinstance(artifact, BuiltHelmArtifact) and artifact.metadata ] registries_to_push = list( remotes.get(*(request.field_set.registries.value or []))) if not registries_to_push: return PublishProcesses([ PublishPackages( names=tuple(metadata.artifact_name for _, _, metadata in built_artifacts), description= f"(by missing `{request.field_set.registries.alias}` on {request.field_set.address})", ) ]) push_repository = (request.field_set.repository.value or helm_subsystem.default_registry_repository) publish_refs = [ registry.package_ref(metadata.artifact_name, repository=push_repository) for _, _, metadata in built_artifacts for registry in registries_to_push ] if request.field_set.skip_push.value: return PublishProcesses([ PublishPackages( names=tuple(publish_refs), description= f"(by `{request.field_set.skip_push.alias}` on {request.field_set.address})", ) ]) processes = await MultiGet( Get( Process, HelmProcess( [ "push", artifact.relpath, registry.repository_ref(push_repository) ], input_digest=pkg.digest, description= f"Pushing Helm chart '{metadata.name}' with version '{metadata.version}' into OCI registry: {registry.address}", ), ) for pkg, artifact, metadata in built_artifacts if artifact.relpath for registry in registries_to_push) interactive_processes = await MultiGet( Get(InteractiveProcess, InteractiveProcessRequest(process)) for process in processes) refs_and_processes = zip(publish_refs, interactive_processes) return PublishProcesses([ PublishPackages(names=(package_ref, ), process=process) for package_ref, process in refs_and_processes ])