Skip to content

Commit 58e0ddd

Browse files
authored
Revert inadvertent pull platform filtering from apple#545. (apple#593)
- Reverts an inadvertent "fix" from apple#545. - Closes apple#592. ## Type of Change - [x] Bug fix - [ ] New feature - [ ] Breaking change - [ ] Documentation update ## Motivation and Context See apple#592 ## Testing - [x] Tested locally - [ ] Added/updated tests - [ ] Added/updated docs
1 parent 0ba2c42 commit 58e0ddd

3 files changed

Lines changed: 67 additions & 8 deletions

File tree

Sources/CLI/Image/ImagePull.swift

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,13 @@ extension Application {
4545
@Option(
4646
help: "Set OS if image can target multiple operating systems"
4747
)
48-
var os: String = "linux"
48+
var os: String?
4949

5050
@Option(
5151
name: [.customLong("arch"), .customShort("a")],
5252
help: "Set arch if image can target multiple architectures"
5353
)
54-
var arch: String = Arch.hostArchitecture().rawValue
54+
var arch: String?
5555

5656
@Argument var reference: String
5757

@@ -69,8 +69,10 @@ extension Application {
6969
var p: Platform?
7070
if let platform {
7171
p = try Platform(from: platform)
72-
} else {
73-
p = try Platform(from: "\(os)/\(arch)")
72+
} else if let arch {
73+
p = try Platform(from: "\(os ?? "linux")/\(arch)")
74+
} else if let os {
75+
p = try Platform(from: "\(os)/\(arch ?? Arch.hostArchitecture().rawValue)")
7476
}
7577

7678
let scheme = try RequestScheme(registry.scheme)

Sources/CLI/Image/ImageSave.swift

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,13 @@ extension Application {
4040
@Option(
4141
help: "Set OS if image can target multiple operating systems"
4242
)
43-
var os: String = "linux"
43+
var os: String?
4444

4545
@Option(
4646
name: [.customLong("arch"), .customShort("a")],
4747
help: "Set arch if image can target multiple architectures"
4848
)
49-
var arch: String = Arch.hostArchitecture().rawValue
49+
var arch: String?
5050

5151
@Option(
5252
name: .shortAndLong, help: "Path to save the image tar archive", completion: .file(),
@@ -61,8 +61,10 @@ extension Application {
6161
var p: Platform?
6262
if let platform {
6363
p = try Platform(from: platform)
64-
} else {
65-
p = try Platform(from: "\(os)/\(arch)")
64+
} else if let arch {
65+
p = try Platform(from: "\(os ?? "linux")/\(arch)")
66+
} else if let os {
67+
p = try Platform(from: "\(os)/\(arch ?? Arch.hostArchitecture().rawValue)")
6668
}
6769

6870
let progressConfig = try ProgressConfig(

Tests/CLITests/Subcommands/Images/TestCLIImages.swift

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
// limitations under the License.
1515
//===----------------------------------------------------------------------===//
1616

17+
import ContainerClient
1718
import ContainerizationOCI
1819
import Foundation
1920
import Testing
@@ -167,6 +168,60 @@ extension TestCLIImagesCommand {
167168
}
168169
}
169170

171+
@Test func testPullOs() throws {
172+
do {
173+
let os = "linux"
174+
let arch = Arch.hostArchitecture().rawValue
175+
let pullArgs = [
176+
"--os",
177+
os,
178+
]
179+
180+
try doPull(imageName: alpine318, args: pullArgs)
181+
182+
let output = try doInspectImages(image: alpine318)
183+
#expect(output.count == 1, "expected a single image inspect output, got \(output)")
184+
185+
var found = false
186+
for v in output[0].variants {
187+
if v.platform.os == os && v.platform.architecture == arch {
188+
found = true
189+
}
190+
}
191+
#expect(found, "expected to find image with os \(os) and architecture \(arch), instead got \(output[0])")
192+
} catch {
193+
Issue.record("failed to pull and inspect image \(error)")
194+
return
195+
}
196+
}
197+
198+
@Test func testPullArch() throws {
199+
do {
200+
let os = "linux"
201+
let arch = "amd64"
202+
let pullArgs = [
203+
"--arch",
204+
arch,
205+
]
206+
207+
try doPull(imageName: alpine318, args: pullArgs)
208+
209+
let output = try doInspectImages(image: alpine318)
210+
#expect(output.count == 1, "expected a single image inspect output, got \(output)")
211+
212+
var found = false
213+
for v in output[0].variants {
214+
if v.platform.os == os && v.platform.architecture == arch {
215+
found = true
216+
}
217+
}
218+
#expect(found, "expected to find image with os \(os) and architecture \(arch), instead got \(output[0])")
219+
} catch {
220+
Issue.record("failed to pull and inspect image \(error)")
221+
return
222+
}
223+
}
224+
170225
@Test func testPullRemoveSingle() throws {
171226
do {
172227
try doPull(imageName: alpine)

0 commit comments

Comments
 (0)