|
14 | 14 | * limitations under the License. |
15 | 15 | */ |
16 | 16 |
|
17 | | -import {ChildProcessByStdio, spawn} from 'child_process'; |
18 | 17 | import fs from 'fs'; |
19 | | -import os from 'os'; |
20 | 18 | import path from 'path'; |
21 | | -import {Readable, Writable} from 'stream'; |
22 | 19 | import * as core from '@actions/core'; |
23 | 20 |
|
24 | 21 | import {Buildx} from './buildx.js'; |
25 | 22 | import {Context} from '../context.js'; |
26 | | -import {Docker} from '../docker/docker.js'; |
27 | 23 | import {Exec} from '../exec.js'; |
28 | 24 | import {GitHub} from '../github/github.js'; |
29 | 25 | import {Util} from '../util.js'; |
@@ -101,10 +97,6 @@ export class History { |
101 | 97 | core.info(`exporting build record to ${outDir}`); |
102 | 98 | fs.mkdirSync(outDir, {recursive: true}); |
103 | 99 |
|
104 | | - if (opts.useContainer || (await this.buildx.versionSatisfies('<0.23.0'))) { |
105 | | - return await this.exportLegacy(builderName, nodeName, refs, outDir, opts.image); |
106 | | - } |
107 | | - |
108 | 100 | if (await this.buildx.versionSatisfies('<0.24.0')) { |
109 | 101 | // wait 3 seconds to ensure build records are finalized: https://github.com/moby/buildkit/pull/5109 |
110 | 102 | // not necessary since buildx 0.24.0: https://github.com/docker/buildx/pull/3152 |
@@ -162,143 +154,6 @@ export class History { |
162 | 154 | }; |
163 | 155 | } |
164 | 156 |
|
165 | | - private async exportLegacy(builderName: string, nodeName: string, refs: Array<string>, outDir: string, image?: string): Promise<ExportResponse> { |
166 | | - if (os.platform() === 'win32') { |
167 | | - throw new Error('Exporting a build record is currently not supported on Windows'); |
168 | | - } |
169 | | - if (!(await Docker.isAvailable())) { |
170 | | - throw new Error('Docker is required to export a build record'); |
171 | | - } |
172 | | - if (!(await Docker.isDaemonRunning())) { |
173 | | - throw new Error('Docker daemon needs to be running to export a build record'); |
174 | | - } |
175 | | - if (!(await this.buildx.versionSatisfies('>=0.13.0'))) { |
176 | | - throw new Error('Buildx >= 0.13.0 is required to export a build record'); |
177 | | - } |
178 | | - |
179 | | - // wait 3 seconds to ensure build records are finalized: https://github.com/moby/buildkit/pull/5109 |
180 | | - await Util.sleep(3); |
181 | | - |
182 | | - const buildxInFifoPath = Context.tmpName({ |
183 | | - template: 'buildx-in-XXXXXX.fifo', |
184 | | - tmpdir: Context.tmpDir() |
185 | | - }); |
186 | | - await Exec.exec('mkfifo', [buildxInFifoPath]); |
187 | | - |
188 | | - const buildxOutFifoPath = Context.tmpName({ |
189 | | - template: 'buildx-out-XXXXXX.fifo', |
190 | | - tmpdir: Context.tmpDir() |
191 | | - }); |
192 | | - await Exec.exec('mkfifo', [buildxOutFifoPath]); |
193 | | - |
194 | | - const buildxDialStdioCmd = await this.buildx.getCommand(['--builder', builderName, 'dial-stdio']); |
195 | | - core.info(`[command]${buildxDialStdioCmd.command} ${buildxDialStdioCmd.args.join(' ')}`); |
196 | | - const buildxDialStdioProc = spawn(buildxDialStdioCmd.command, buildxDialStdioCmd.args, { |
197 | | - stdio: ['pipe', 'pipe', 'inherit'], |
198 | | - detached: true |
199 | | - }); |
200 | | - let buildxDialStdioKilled = false; |
201 | | - fs.createReadStream(buildxInFifoPath).pipe(buildxDialStdioProc.stdin); |
202 | | - buildxDialStdioProc.stdout.pipe(fs.createWriteStream(buildxOutFifoPath)); |
203 | | - buildxDialStdioProc.on('exit', (code, signal) => { |
204 | | - buildxDialStdioKilled = true; |
205 | | - if (signal) { |
206 | | - core.info(`Process "buildx dial-stdio" was killed with signal ${signal}`); |
207 | | - } else { |
208 | | - core.info(`Process "buildx dial-stdio" exited with code ${code}`); |
209 | | - } |
210 | | - }); |
211 | | - |
212 | | - const tmpDockerbuildFilename = path.join(outDir, 'rec.dockerbuild'); |
213 | | - const summaryFilename = path.join(outDir, 'summary.json'); |
214 | | - |
215 | | - let dockerRunProc: ChildProcessByStdio<Writable, Readable, null> | undefined; |
216 | | - let dockerRunProcKilled = false; |
217 | | - await new Promise<void>((resolve, reject) => { |
218 | | - const ebargs: Array<string> = ['--ref-state-dir=/buildx-refs', `--node=${builderName}/${nodeName}`]; |
219 | | - for (const ref of refs) { |
220 | | - ebargs.push(`--ref=${ref}`); |
221 | | - } |
222 | | - if (typeof process.getuid === 'function') { |
223 | | - ebargs.push(`--uid=${process.getuid()}`); |
224 | | - } |
225 | | - if (typeof process.getgid === 'function') { |
226 | | - ebargs.push(`--gid=${process.getgid()}`); |
227 | | - } |
228 | | - // prettier-ignore |
229 | | - const dockerRunArgs = [ |
230 | | - 'run', '--rm', '-i', |
231 | | - '-v', `${Buildx.refsDir}:/buildx-refs`, |
232 | | - '-v', `${outDir}:/out`, |
233 | | - image || process.env['DOCKER_BUILD_EXPORT_BUILD_IMAGE'] || 'docker.io/dockereng/export-build:latest', |
234 | | - ...ebargs |
235 | | - ] |
236 | | - core.info(`[command]docker ${dockerRunArgs.join(' ')}`); |
237 | | - dockerRunProc = spawn('docker', dockerRunArgs, { |
238 | | - stdio: ['pipe', 'pipe', 'inherit'], |
239 | | - env: { |
240 | | - ...process.env, |
241 | | - DOCKER_CONTENT_TRUST: 'false' |
242 | | - } |
243 | | - }); |
244 | | - fs.createReadStream(buildxOutFifoPath).pipe(dockerRunProc.stdin); |
245 | | - dockerRunProc.stdout.pipe(fs.createWriteStream(buildxInFifoPath)); |
246 | | - dockerRunProc.on('close', code => { |
247 | | - if (code === 0) { |
248 | | - if (!fs.existsSync(tmpDockerbuildFilename)) { |
249 | | - reject(new Error(`Failed to export build record: ${tmpDockerbuildFilename} not found`)); |
250 | | - } else { |
251 | | - resolve(); |
252 | | - } |
253 | | - } else { |
254 | | - reject(new Error(`Process "docker run" closed with code ${code}`)); |
255 | | - } |
256 | | - }); |
257 | | - dockerRunProc.on('error', err => { |
258 | | - core.error(`Error executing "docker run": ${err}`); |
259 | | - reject(err); |
260 | | - }); |
261 | | - dockerRunProc.on('exit', (code, signal) => { |
262 | | - dockerRunProcKilled = true; |
263 | | - if (signal) { |
264 | | - core.info(`Process "docker run" was killed with signal ${signal}`); |
265 | | - } else { |
266 | | - core.info(`Process "docker run" exited with code ${code}`); |
267 | | - } |
268 | | - }); |
269 | | - }) |
270 | | - .catch(err => { |
271 | | - throw err; |
272 | | - }) |
273 | | - .finally(() => { |
274 | | - if (buildxDialStdioProc && !buildxDialStdioKilled) { |
275 | | - core.debug('Force terminating "buildx dial-stdio" process'); |
276 | | - buildxDialStdioProc.kill('SIGKILL'); |
277 | | - } |
278 | | - if (dockerRunProc && !dockerRunProcKilled) { |
279 | | - core.debug('Force terminating "docker run" process'); |
280 | | - dockerRunProc.kill('SIGKILL'); |
281 | | - } |
282 | | - }); |
283 | | - |
284 | | - const dockerbuildPath = path.join(outDir, `${History.exportFilename(refs)}.dockerbuild`); |
285 | | - fs.renameSync(tmpDockerbuildFilename, dockerbuildPath); |
286 | | - const dockerbuildStats = fs.statSync(dockerbuildPath); |
287 | | - |
288 | | - core.info(`Parsing ${summaryFilename}`); |
289 | | - fs.statSync(summaryFilename); |
290 | | - const summaries = <Summaries>JSON.parse(fs.readFileSync(summaryFilename, {encoding: 'utf-8'})); |
291 | | - |
292 | | - return { |
293 | | - dockerbuildFilename: dockerbuildPath, |
294 | | - dockerbuildSize: dockerbuildStats.size, |
295 | | - builderName: builderName, |
296 | | - nodeName: nodeName, |
297 | | - refs: refs, |
298 | | - summaries: summaries |
299 | | - }; |
300 | | - } |
301 | | - |
302 | 157 | private static exportFilename(refs: Array<string>): string { |
303 | 158 | let name = `${GitHub.context.repo.owner}~${GitHub.context.repo.repo}~${refs[0].substring(0, 6).toUpperCase()}`; |
304 | 159 | if (refs.length > 1) { |
|
0 commit comments