mirror of
https://github.com/apple/container.git
synced 2026-09-28 01:46:25 -04:00
Create RequestScheme type to handle registry interactions (#6)
Its a bit weird to have to pass `--http` when pulling / pushing images if we are trying to do so from a local registry This PR adds a `RequestScheme` enum type which tries to detect if the connection to the registry should be over http or https. This auto detection is the default behavior and can be overridden by passing the `--scheme http/https` flag to the `run` ,`pull`, `push` `login` and `registry default` command The auto detection works by looking at the hostname / IP. HTTP is used in the following cases - If the hostname starts with `localhost` or is `127.x.x.x` - if the host looks like an IP from the private address space - If the host ends with the current default dns domain name Also in this PR: - Removing some used CLI flag groups and TODOs - Better error messages when registry credentials are not found for a host Signed-off-by: Aditya Ramani <a_ramani@apple.com>
This commit is contained in:
@@ -31,18 +31,19 @@ extension Application {
|
||||
@OptionGroup
|
||||
var global: Flags.Global
|
||||
|
||||
@Option(help: "Platform string in the form 'os/arch/variant'. Example 'linux/arm64/v8', 'linux/amd64'") var platform: String?
|
||||
@OptionGroup
|
||||
var registry: Flags.Registry
|
||||
|
||||
@Flag(help: "Pull using plain-text http") var http: Bool = false
|
||||
@Option(help: "Platform string in the form 'os/arch/variant'. Example 'linux/arm64/v8', 'linux/amd64'") var platform: String?
|
||||
|
||||
@Argument var reference: String
|
||||
|
||||
init() {}
|
||||
|
||||
init(platform: String? = nil, http: Bool = false, reference: String) {
|
||||
init(platform: String? = nil, scheme: String = "auto", reference: String) {
|
||||
self.global = Flags.Global()
|
||||
self.registry = Flags.Registry(scheme: scheme)
|
||||
self.platform = platform
|
||||
self.http = http
|
||||
self.reference = reference
|
||||
}
|
||||
|
||||
@@ -52,6 +53,8 @@ extension Application {
|
||||
p = try Platform(from: platform)
|
||||
}
|
||||
|
||||
let scheme = try RequestScheme(registry.scheme)
|
||||
|
||||
let processedReference = try ClientImage.normalizeReference(reference)
|
||||
let progressConfig = try ProgressConfig(
|
||||
showTasks: true,
|
||||
@@ -70,7 +73,7 @@ extension Application {
|
||||
let taskManager = ProgressTaskCoordinator()
|
||||
let fetchTask = await taskManager.startTask()
|
||||
let image = try await ClientImage.pull(
|
||||
reference: processedReference, platform: p, progressUpdate: ProgressTaskCoordinator.handler(for: fetchTask, from: progress.handler)
|
||||
reference: processedReference, platform: p, scheme: scheme, progressUpdate: ProgressTaskCoordinator.handler(for: fetchTask, from: progress.handler)
|
||||
)
|
||||
|
||||
progress.set(description: "Unpacking image")
|
||||
|
||||
@@ -30,9 +30,10 @@ extension Application {
|
||||
@OptionGroup
|
||||
var global: Flags.Global
|
||||
|
||||
@Option(help: "Platform string in the form 'os/arch/variant'. Example 'linux/arm64/v8', 'linux/amd64'") var platform: String?
|
||||
@OptionGroup
|
||||
var registry: Flags.Registry
|
||||
|
||||
@Flag(help: "Push using plain-text http") var http: Bool = false
|
||||
@Option(help: "Platform string in the form 'os/arch/variant'. Example 'linux/arm64/v8', 'linux/amd64'") var platform: String?
|
||||
|
||||
@Argument var reference: String
|
||||
|
||||
@@ -42,6 +43,7 @@ extension Application {
|
||||
p = try Platform(from: platform)
|
||||
}
|
||||
|
||||
let scheme = try RequestScheme(registry.scheme)
|
||||
let image = try await ClientImage.get(reference: reference)
|
||||
|
||||
let progressConfig = try ProgressConfig(
|
||||
@@ -56,7 +58,7 @@ extension Application {
|
||||
progress.finish()
|
||||
}
|
||||
progress.start()
|
||||
_ = try await image.push(platform: p, insecure: http, progressUpdate: progress.handler)
|
||||
_ = try await image.push(platform: p, scheme: scheme, progressUpdate: progress.handler)
|
||||
progress.finish()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user