Skip to content

Commit ca5ab56

Browse files
authored
Merge pull request #895 from crazy-max/remove-export-legacy
buildx(history): remove legacy export-build tool
2 parents 5b2d914 + 9edbb73 commit ca5ab56

2 files changed

Lines changed: 0 additions & 181 deletions

File tree

__tests__/buildx/history.test.itg.ts

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -187,40 +187,4 @@ maybe('export', () => {
187187
expect(fs.existsSync(exportRes?.dockerbuildFilename)).toBe(true);
188188
expect(exportRes?.summaries).toBeDefined();
189189
});
190-
191-
it('export using container', async () => {
192-
const buildx = new Buildx();
193-
const build = new Build({buildx: buildx});
194-
195-
fs.mkdirSync(tmpDir, {recursive: true});
196-
await expect(
197-
(async () => {
198-
// prettier-ignore
199-
const buildCmd = await buildx.getCommand([
200-
'--builder', process.env.CTN_BUILDER_NAME ?? 'default',
201-
'build', '-f', path.join(fixturesDir, 'hello.Dockerfile'),
202-
'--metadata-file', build.getMetadataFilePath(),
203-
fixturesDir
204-
]);
205-
await Exec.exec(buildCmd.command, buildCmd.args);
206-
})()
207-
).resolves.not.toThrow();
208-
209-
const metadata = build.resolveMetadata();
210-
expect(metadata).toBeDefined();
211-
const buildRef = build.resolveRef(metadata);
212-
expect(buildRef).toBeDefined();
213-
214-
const history = new History({buildx: buildx});
215-
const exportRes = await history.export({
216-
refs: [buildRef ?? ''],
217-
useContainer: true
218-
});
219-
220-
expect(exportRes).toBeDefined();
221-
expect(exportRes?.dockerbuildFilename).toBeDefined();
222-
expect(exportRes?.dockerbuildSize).toBeDefined();
223-
expect(fs.existsSync(exportRes?.dockerbuildFilename)).toBe(true);
224-
expect(exportRes?.summaries).toBeDefined();
225-
});
226190
});

src/buildx/history.ts

Lines changed: 0 additions & 145 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,12 @@
1414
* limitations under the License.
1515
*/
1616

17-
import {ChildProcessByStdio, spawn} from 'child_process';
1817
import fs from 'fs';
19-
import os from 'os';
2018
import path from 'path';
21-
import {Readable, Writable} from 'stream';
2219
import * as core from '@actions/core';
2320

2421
import {Buildx} from './buildx.js';
2522
import {Context} from '../context.js';
26-
import {Docker} from '../docker/docker.js';
2723
import {Exec} from '../exec.js';
2824
import {GitHub} from '../github/github.js';
2925
import {Util} from '../util.js';
@@ -101,10 +97,6 @@ export class History {
10197
core.info(`exporting build record to ${outDir}`);
10298
fs.mkdirSync(outDir, {recursive: true});
10399

104-
if (opts.useContainer || (await this.buildx.versionSatisfies('<0.23.0'))) {
105-
return await this.exportLegacy(builderName, nodeName, refs, outDir, opts.image);
106-
}
107-
108100
if (await this.buildx.versionSatisfies('<0.24.0')) {
109101
// wait 3 seconds to ensure build records are finalized: https://github.com/moby/buildkit/pull/5109
110102
// not necessary since buildx 0.24.0: https://github.com/docker/buildx/pull/3152
@@ -162,143 +154,6 @@ export class History {
162154
};
163155
}
164156

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-
302157
private static exportFilename(refs: Array<string>): string {
303158
let name = `${GitHub.context.repo.owner}~${GitHub.context.repo.repo}~${refs[0].substring(0, 6).toUpperCase()}`;
304159
if (refs.length > 1) {

0 commit comments

Comments
 (0)