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
12 changes: 12 additions & 0 deletions Sources/ContainerBuild/Builder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,9 @@ public struct Builder: Sendable {
public let contentStore: ContentStore
public let buildArgs: [String]
public let contextDir: String
public let dockerfilePath: String?
public let dockerfile: Data
public let dockerignore: Data?
public let labels: [String]
public let noCache: Bool
public let platforms: [Platform]
Expand All @@ -258,7 +260,9 @@ public struct Builder: Sendable {
contentStore: ContentStore,
buildArgs: [String],
contextDir: String,
dockerfilePath: String?,
dockerfile: Data,
dockerignore: Data?,
labels: [String],
noCache: Bool,
platforms: [Platform],
Expand All @@ -275,7 +279,9 @@ public struct Builder: Sendable {
self.contentStore = contentStore
self.buildArgs = buildArgs
self.contextDir = contextDir
self.dockerfilePath = dockerfilePath
self.dockerfile = dockerfile
self.dockerignore = dockerignore
self.labels = labels
self.noCache = noCache
self.platforms = platforms
Expand Down Expand Up @@ -319,6 +325,12 @@ extension CallOptions {
("progress", config.terminal != nil ? "tty" : "plain"),
("target", config.target),
]
if let dockerfilePath = config.dockerfilePath {
headers.append(("dockerfile-path", dockerfilePath))
}
if let dockerignore = config.dockerignore {
headers.append(("dockerignore", dockerignore.base64EncodedString()))
}
for tag in config.tags {
headers.append(("tag", tag))
}
Expand Down
42 changes: 24 additions & 18 deletions Sources/ContainerCommands/BuildCommand.swift
Original file line number Diff line number Diff line change
Expand Up @@ -204,24 +204,11 @@ extension Application {
throw ValidationError("builder is not running")
}

let buildFilePath: String
if let file = self.file {
buildFilePath = file
} else {
guard
let resolvedPath = try BuildFile.resolvePath(
contextDir: self.contextDir,
log: log
)
else {
throw ValidationError("failed to find Dockerfile or Containerfile in the context directory \(self.contextDir)")
}
buildFilePath = resolvedPath
}

let buildFileData: Data
var buildFilePath: String? = nil
var ignoreFileData: Data? = nil
// Dockerfile should be read from stdin
if file == "-" {
if let file = self.file, file == "-" {
let tempFile = FileManager.default.temporaryDirectory.appendingPathComponent("Dockerfile-\(UUID().uuidString)")
defer {
try? FileManager.default.removeItem(at: tempFile)
Expand All @@ -244,7 +231,24 @@ extension Application {
try fileHandle.close()
buildFileData = try Data(contentsOf: URL(filePath: tempFile.path()))
} else {
buildFileData = try Data(contentsOf: URL(filePath: buildFilePath))
let path = try file ?? BuildFile.resolvePath(contextDir: self.contextDir, log: log)

guard let path else {
throw ValidationError("failed to find Dockerfile or Containerfile in the context directory \(self.contextDir)")
}

let ignoreFileURL = URL(filePath: path + ".dockerignore")
ignoreFileData = try? Data(contentsOf: ignoreFileURL)

if ignoreFileData != nil {
let hiddenDirName = ".\(UUID().uuidString)"
let buildFileName = URL(filePath: path).lastPathComponent

buildFilePath = "\(hiddenDirName)/\(buildFileName)"
ignoreFileData?.append("\n\(hiddenDirName)".data(using: .utf8) ?? Data())
}

buildFileData = try Data(contentsOf: URL(filePath: path))
}

let systemHealth = try await ClientHealthCheck.ping(timeout: .seconds(10))
Expand Down Expand Up @@ -316,13 +320,15 @@ extension Application {
}
return results
}()
group.addTask { [terminal, buildArg, contextDir, label, noCache, target, quiet, cacheIn, cacheOut, pull] in
group.addTask { [terminal, buildArg, contextDir, buildFilePath, ignoreFileData, label, noCache, target, quiet, cacheIn, cacheOut, pull] in
let config = Builder.BuildConfig(
buildID: buildID,
contentStore: RemoteContentStoreClient(),
buildArgs: buildArg,
contextDir: contextDir,
dockerfilePath: buildFilePath,
dockerfile: buildFileData,
dockerignore: ignoreFileData,
labels: label,
noCache: noCache,
platforms: [Platform](platforms),
Expand Down
Loading
Loading