1import * as _ from 'lodash-es' 10type CtxTarSpec = { tarPath: string } 12// minimal docker build context for local builds: the Dockerfile (at tar root) + the already-baked 13// tmpdockertars/*.tar.gz it ADDs. Avoids sending all of ptDir (5GB+) as context. Mirrors kaniko's 14// localctx but uses tarPath (local builds need no in-container reconstruction). Hash-cached. 15// --format=ustar + COPYFILE_DISABLE avoid bsdtar PAX headers / macOS xattrs that the docker daemon 16// can't parse/restore when the context is supplied via stdin. 17export const genLocalDockerCtxTar = async ({dockerfileContent, tarSpecsA}: {dockerfileContent: string, tarSpecsA: CtxTarSpec[]}) => { 18 const tarPaths = _.uniq(tarSpecsA.map(ts => ts.tarPath).filter(Boolean) as string[]) 19 const sha = calcShortHash(dockerfileContent + '\n' + tarPaths.sort().join('\n')) 20 const stageRel = `tmpdockertars/.ldc-stage-${sha}` 21 const ctxTarRel = `tmpdockertars/localdockerctx-${sha}.tar` 22 const ctxTarAbs = `${ptDir}/${ctxTarRel}` 27 [getTarCmd(), '--format=ustar', '-cf', ctxTarAbs, '-C', `${ptDir}/${stageRel}`, 'Dockerfile', '-C', ptDir, ...tarPaths], 28 {env: {...process.env, COPYFILE_DISABLE: '1'}},