mirror of
https://github.com/apple/container.git
synced 2026-08-29 03:46:39 +00:00
Send tar hash in the first BuildTransfer packet (#1149)
Send the hash of entire tar file in the first BuildTransfer packet to prevent container-builder-shim from using stale cached contents. This PR resolves #1143. This PR relies on apple/container-builder-shim#64. ## Type of Change - [X] Bug fix - [ ] New feature - [ ] Breaking change - [ ] Documentation update ## Motivation and Context Current container-builder-shim uses only first few bytes of tar file as checksum, which leads to the usage of stale cached contents if the change of build context is not included in the first bytes of tar file. ## Testing - [X] Tested locally - [ ] Added/updated tests - [ ] Added/updated docs --------- Co-authored-by: Ronit Sabhaya <ronitsabhaya75@gmail.com> Co-authored-by: J Logan <john_logan@apple.com>
This commit is contained in:
co-authored by
Ronit Sabhaya
J Logan
parent
6e9b8d724d
commit
fabfc55568
@@ -18,6 +18,7 @@ import Collections
|
||||
import ContainerAPIClient
|
||||
import ContainerizationArchive
|
||||
import ContainerizationOCI
|
||||
import CryptoKit
|
||||
import Foundation
|
||||
import GRPC
|
||||
|
||||
@@ -199,7 +200,7 @@ actor BuildFSSync: BuildPipelineHandler {
|
||||
format: .paxRestricted,
|
||||
filter: .none)
|
||||
|
||||
try Archiver.compress(
|
||||
let tarHash = try Archiver.compress(
|
||||
source: contextDir,
|
||||
destination: tarURL,
|
||||
writerConfiguration: writerCfg
|
||||
@@ -229,6 +230,25 @@ actor BuildFSSync: BuildPipelineHandler {
|
||||
pathInArchive: URL(fileURLWithPath: rel))
|
||||
}
|
||||
|
||||
let hash = tarHash.compactMap { String(format: "%02x", $0) }.joined()
|
||||
let header = BuildTransfer(
|
||||
id: packet.id,
|
||||
source: tarURL.path,
|
||||
complete: false,
|
||||
isDir: false,
|
||||
metadata: [
|
||||
"os": "linux",
|
||||
"stage": "fssync",
|
||||
"mode": "tar",
|
||||
"hash": hash,
|
||||
]
|
||||
)
|
||||
var resp = ClientStream()
|
||||
resp.buildID = buildID
|
||||
resp.buildTransfer = header
|
||||
resp.packetType = .buildTransfer(header)
|
||||
sender.yield(resp)
|
||||
|
||||
for try await chunk in try tarURL.bufferedCopyReader() {
|
||||
let part = BuildTransfer(
|
||||
id: packet.id,
|
||||
|
||||
Reference in New Issue
Block a user