Testing out the real shit.

This commit is contained in:
Daan Selen
2025-08-09 00:20:16 +02:00
parent 8bcfb9c6f9
commit 02f8d16e0b
4 changed files with 27683 additions and 10 deletions

File diff suppressed because one or more lines are too long

View File

@@ -8,8 +8,11 @@
"name": "docker-scout-action",
"version": "1.0.0",
"dependencies": {
"@actions/core": "1.11.1",
"@actions/exec": "1.1.1"
"@actions/core": "^1.11.1",
"@actions/exec": "^1.1.1"
},
"devDependencies": {
"@vercel/ncc": "^0.38.3"
}
},
"node_modules/@actions/core": {
@@ -51,6 +54,15 @@
"node": ">=14"
}
},
"node_modules/@vercel/ncc": {
"version": "0.38.3",
"resolved": "https://registry.npmjs.org/@vercel/ncc/-/ncc-0.38.3.tgz",
"integrity": "sha512-rnK6hJBS6mwc+Bkab+PGPs9OiS0i/3kdTO+CkI8V0/VrW3vmz7O2Pxjw/owOlmo6PKEIxRSeZKv/kuL9itnpYA==",
"dev": true,
"bin": {
"ncc": "dist/ncc/cli.js"
}
},
"node_modules/tunnel": {
"version": "0.0.6",
"resolved": "https://registry.npmjs.org/tunnel/-/tunnel-0.0.6.tgz",

View File

@@ -7,7 +7,10 @@
"start": "node index.js"
},
"dependencies": {
"@actions/core": "1.11.1",
"@actions/exec": "1.1.1"
"@actions/core": "^1.11.1",
"@actions/exec": "^1.1.1"
},
"devDependencies": {
"@vercel/ncc": "^0.38.3"
}
}
}

98
docker-scout/src/index.js Normal file
View File

@@ -0,0 +1,98 @@
const fs = require('fs');
const os = require('os');
const core = require('@actions/core');
const exec = require('@actions/exec');
const path = require('path');
async function pullDockerImage(version) {
await core.group(`Pull docker/scout-cli image`, async () => {
await exec.exec(`docker pull docker.io/docker/scout-cli:${version}`);
});
}
async function copyBinary(version) {
await core.group(`Copy binary`, async () => {
const res = await exec.getExecOutput('docker', ['create', `docker.io/docker/scout-cli:${version}`], {
ignoreReturnCode: true
});
if (res.stderr.length > 0 && res.exitCode != 0) {
throw new Error(res.stderr);
}
const ctnid = res.stdout.trim();
const dockerCfgPath = process.env.DOCKER_CONFIG || path.join(os.homedir(), '.docker');
const pluginsPath = path.join(dockerCfgPath, 'cli-plugins');
fs.mkdirSync(pluginsPath, { recursive: true });
await exec.exec(`docker cp ${ctnid}:/docker-scout ${pluginsPath}`);
await exec.exec(`docker rm -v ${ctnid}`);
});
}
async function dockerInfo() {
await core.group(`Docker info`, async () => {
await exec.exec(`docker info`);
});
}
/*
async function getScoutVersion() {
let version;
await core.group(`Docker scout version`, async () => {
const res = await exec.getExecOutput('docker', ['scout', 'version'], {
ignoreReturnCode: true,
silent: true
});
if (res.stderr.length > 0 && res.exitCode != 0) {
throw new Error(res.stderr);
}
const matchVersion = res.stdout.trim().match(/version:\s(.*?)\s/);
version = matchVersion ? matchVersion[1] : null;
if (!version) {
throw new Error('Failed to get Docker scout version');
}
core.info(version);
});
return version;
}
*/
async function runScoutCommand(commands, image, format, outputFile) {
const resultPath = path.join(fs.mkdtempSync(path.join(os.tmpdir(), 'docker-scout-action-')), 'result.txt');
core.setOutput('result-file', resultPath);
for (const cmd of commands) {
if (outputFile) {
const res = await exec.getExecOutput('docker', ['scout', cmd, image, '--format', format], { silent: true });
if (res.stderr && res.stderr.length > 0) {
throw new Error(res.stderr);
}
fs.appendFile(resultPath, res.stdout);
} else {
await exec.exec('docker', ['scout', cmd, image, '--format', format]);
}
}
return resultPath;
}
async function main(inputs) {
try {
const commandInput = core.getInput('command');
const commands = commandInput.split(',').map(cmd => cmd.trim()).filter(cmd => cmd.length > 0);
const scoutVersion = core.getInput('version');
const outputFormat = core.getInput('format');
const imageName = core.getInput('image');
const outputFile = core.getInput('output-file') === 'true';
await pullDockerImage(scoutVersion);
await copyBinary(scoutVersion);
await dockerInfo();
//const version = await getScoutVersion();
// TODO: cache binary (no changes per your request)
await runScoutCommand(commands, imageName, outputFormat, outputFile);
}
catch (error) {
core.setFailed(error.message);
console.error(error);
}
}
main()