Skip to content

Commit e370b26

Browse files
committed
add pull flag for fetching latest image
1 parent 62721e7 commit e370b26

File tree

4 files changed

+21
-6
lines changed

4 files changed

+21
-6
lines changed

Sources/ContainerBuild/BuildImageResolver.swift

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,11 @@ import Logging
2323

2424
struct BuildImageResolver: BuildPipelineHandler {
2525
let contentStore: ContentStore
26+
let pull: Bool
2627

27-
public init(_ contentStore: ContentStore) throws {
28+
public init(_ contentStore: ContentStore, pull: Bool) throws {
2829
self.contentStore = contentStore
30+
self.pull = pull
2931
}
3032

3133
func accept(_ packet: ServerStream) throws -> Bool {
@@ -54,8 +56,14 @@ struct BuildImageResolver: BuildPipelineHandler {
5456
}
5557

5658
let img = try await {
57-
guard let img = try? await ClientImage.pull(reference: ref, platform: platform) else {
58-
return try await ClientImage.fetch(reference: ref, platform: platform)
59+
if self.pull {
60+
return try await ClientImage.pull(reference: ref, platform: platform)
61+
}
62+
63+
// Try and fetch locally cached image
64+
guard let img = try? await ClientImage.fetch(reference: ref, platform: platform) else {
65+
// Fall back to pulling image
66+
return try await ClientImage.pull(reference: ref, platform: platform)
5967
}
6068
return img
6169
}()

Sources/ContainerBuild/BuildPipelineHandler.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public actor BuildPipeline {
3030
[
3131
try BuildFSSync(URL(filePath: config.contextDir)),
3232
try BuildRemoteContentProxy(config.contentStore),
33-
try BuildImageResolver(config.contentStore),
33+
try BuildImageResolver(config.contentStore, pull: config.pull),
3434
try BuildStdio(quiet: config.quiet, output: config.terminal?.handle ?? FileHandle.standardError),
3535
]
3636
}

Sources/ContainerBuild/Builder.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,7 @@ public struct Builder: Sendable {
249249
public let exports: [BuildExport]
250250
public let cacheIn: [String]
251251
public let cacheOut: [String]
252+
public let pull: Bool
252253

253254
public init(
254255
buildID: String,
@@ -266,6 +267,7 @@ public struct Builder: Sendable {
266267
exports: [BuildExport],
267268
cacheIn: [String],
268269
cacheOut: [String],
270+
pull: Bool
269271
) {
270272
self.buildID = buildID
271273
self.contentStore = contentStore
@@ -282,6 +284,7 @@ public struct Builder: Sendable {
282284
self.exports = exports
283285
self.cacheIn = cacheIn
284286
self.cacheOut = cacheOut
287+
self.pull = pull
285288
}
286289
}
287290
}

Sources/ContainerCommands/BuildCommand.swift

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,9 @@ extension Application {
125125
@Argument(help: "Build directory")
126126
var contextDir: String = "."
127127

128+
@Flag(name: .long, help: "Pull latest image")
129+
var pull: Bool = false
130+
128131
public func run() async throws {
129132
do {
130133
let timeout: Duration = .seconds(300)
@@ -278,7 +281,7 @@ extension Application {
278281
}
279282
return results
280283
}()
281-
group.addTask { [terminal, buildArg, contextDir, label, noCache, target, quiet, cacheIn, cacheOut] in
284+
group.addTask { [terminal, buildArg, contextDir, label, noCache, target, quiet, cacheIn, cacheOut, pull] in
282285
let config = Builder.BuildConfig(
283286
buildID: buildID,
284287
contentStore: RemoteContentStoreClient(),
@@ -294,7 +297,8 @@ extension Application {
294297
quiet: quiet,
295298
exports: exports,
296299
cacheIn: cacheIn,
297-
cacheOut: cacheOut
300+
cacheOut: cacheOut,
301+
pull: pull
298302
)
299303
progress.finish()
300304

0 commit comments

Comments
 (0)