Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion Sources/ContainerBuild/BuildImageResolver.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,13 @@ struct BuildImageResolver: BuildPipelineHandler {
let contentStore: ContentStore
let quiet: Bool
let output: FileHandle
let pull: Bool

public init(_ contentStore: ContentStore, quiet: Bool = false, output: FileHandle = FileHandle.standardError) throws {
public init(_ contentStore: ContentStore, quiet: Bool = false, output: FileHandle = FileHandle.standardError, pull: Bool = false) throws {
self.contentStore = contentStore
self.quiet = quiet
self.output = output
self.pull = pull
}

func accept(_ packet: ServerStream) throws -> Bool {
Expand Down Expand Up @@ -72,6 +74,9 @@ struct BuildImageResolver: BuildPipelineHandler {
defer { progress.finish() }
progress.start()

if self.pull {
return try await ClientImage.pull(reference: ref, platform: platform)
}
// Use fetch() which checks cache first, then pulls if needed
return try await ClientImage.fetch(reference: ref, platform: platform, progressUpdate: progress.handler)
}()
Expand Down
2 changes: 1 addition & 1 deletion Sources/ContainerBuild/BuildPipelineHandler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public actor BuildPipeline {
[
try BuildFSSync(URL(filePath: config.contextDir)),
try BuildRemoteContentProxy(config.contentStore),
try BuildImageResolver(config.contentStore, quiet: config.quiet, output: config.terminal?.handle ?? FileHandle.standardError),
try BuildImageResolver(config.contentStore, quiet: config.quiet, output: config.terminal?.handle ?? FileHandle.standardError, pull: config.pull),
try BuildStdio(quiet: config.quiet, output: config.terminal?.handle ?? FileHandle.standardError),
]
}
Expand Down
3 changes: 3 additions & 0 deletions Sources/ContainerBuild/Builder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@ public struct Builder: Sendable {
public let exports: [BuildExport]
public let cacheIn: [String]
public let cacheOut: [String]
public let pull: Bool

public init(
buildID: String,
Expand All @@ -266,6 +267,7 @@ public struct Builder: Sendable {
exports: [BuildExport],
cacheIn: [String],
cacheOut: [String],
pull: Bool
) {
self.buildID = buildID
self.contentStore = contentStore
Expand All @@ -282,6 +284,7 @@ public struct Builder: Sendable {
self.exports = exports
self.cacheIn = cacheIn
self.cacheOut = cacheOut
self.pull = pull
}
}
}
Expand Down
8 changes: 6 additions & 2 deletions Sources/ContainerCommands/BuildCommand.swift
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,9 @@ extension Application {
@Argument(help: "Build directory")
var contextDir: String = "."

@Flag(name: .long, help: "Pull latest image")
var pull: Bool = false

public func run() async throws {
do {
let timeout: Duration = .seconds(300)
Expand Down Expand Up @@ -278,7 +281,7 @@ extension Application {
}
return results
}()
group.addTask { [terminal, buildArg, contextDir, label, noCache, target, quiet, cacheIn, cacheOut] in
group.addTask { [terminal, buildArg, contextDir, label, noCache, target, quiet, cacheIn, cacheOut, pull] in
let config = Builder.BuildConfig(
buildID: buildID,
contentStore: RemoteContentStoreClient(),
Expand All @@ -294,7 +297,8 @@ extension Application {
quiet: quiet,
exports: exports,
cacheIn: cacheIn,
cacheOut: cacheOut
cacheOut: cacheOut,
pull: pull
)
progress.finish()

Expand Down