mirror of
https://github.com/docker/actions-toolkit.git
synced 2024-11-26 22:26:08 +08:00
buildx: localstate refs
Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com>
This commit is contained in:
parent
33688c4ac8
commit
e41efdd2aa
@ -26,6 +26,7 @@ import {Exec} from '../../src/exec';
|
||||
|
||||
import {Cert} from '../../src/types/buildx';
|
||||
|
||||
const fixturesDir = path.join(__dirname, '..', 'fixtures');
|
||||
// prettier-ignore
|
||||
const tmpDir = path.join(process.env.TEMP || '/tmp', 'buildx-jest');
|
||||
const tmpName = path.join(tmpDir, '.tmpname-jest');
|
||||
@ -252,3 +253,38 @@ describe('resolveCertsDriverOpts', () => {
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
describe('refs', () => {
|
||||
it('returns all refs', async () => {
|
||||
const refs = Buildx.refs({
|
||||
dir: path.join(fixturesDir, 'buildx-refs')
|
||||
});
|
||||
expect(Object.keys(refs).length).toEqual(11);
|
||||
});
|
||||
it('returns default builder refs', async () => {
|
||||
const refs = Buildx.refs({
|
||||
dir: path.join(fixturesDir, 'buildx-refs'),
|
||||
builderName: 'default'
|
||||
});
|
||||
expect(Object.keys(refs).length).toEqual(8);
|
||||
});
|
||||
it('returns foo builder refs', async () => {
|
||||
const refs = Buildx.refs({
|
||||
dir: path.join(fixturesDir, 'buildx-refs'),
|
||||
builderName: 'foo'
|
||||
});
|
||||
expect(Object.keys(refs).length).toEqual(3);
|
||||
});
|
||||
it('returns default builder refs since', async () => {
|
||||
const mdate = new Date('2023-09-05T00:00:00Z');
|
||||
fs.utimesSync(path.join(fixturesDir, 'buildx-refs', 'default', 'default', '36dix0eiv9evr61vrwzn32w7q'), mdate, mdate);
|
||||
fs.utimesSync(path.join(fixturesDir, 'buildx-refs', 'default', 'default', '49p5r8und2konke5pmlyzqp3n'), mdate, mdate);
|
||||
fs.utimesSync(path.join(fixturesDir, 'buildx-refs', 'default', 'default', 'a8zqzhhv5yiazm396jobsgdw2'), mdate, mdate);
|
||||
const refs = Buildx.refs({
|
||||
dir: path.join(fixturesDir, 'buildx-refs'),
|
||||
builderName: 'default',
|
||||
since: new Date('2024-01-10T00:00:00Z')
|
||||
});
|
||||
expect(Object.keys(refs).length).toEqual(5);
|
||||
});
|
||||
});
|
||||
|
@ -0,0 +1 @@
|
||||
{"Definition":"eyJncm91cCI6eyJkZWZhdWx0Ijp7InRhcmdldHMiOlsiZGV2Il19fSwidGFyZ2V0Ijp7ImRldiI6eyJjb250ZXh0IjoiLiIsImRvY2tlcmZpbGUiOiJEb2NrZXJmaWxlIiwiYXJncyI6eyJCVUlMREtJVF9DT05URVhUX0tFRVBfR0lUX0RJUiI6IjEiLCJERUZBVUxUX1BST0RVQ1RfTElDRU5TRSI6IiIsIkRPQ0tFUl9CVUlMRFRBR1MiOiIiLCJET0NLRVJfREVCVUciOiIiLCJET0NLRVJfTERGTEFHUyI6IiIsIkRPQ0tFUl9TVEFUSUMiOiIxIiwiUEFDS0FHRVJfTkFNRSI6IiIsIlBMQVRGT1JNIjoiIiwiUFJPRFVDVCI6IiIsIlNZU1RFTUQiOiJmYWxzZSIsIlZFUlNJT04iOiIifSwidGFncyI6WyJkb2NrZXItZGV2Il0sInRhcmdldCI6ImRldiIsIm91dHB1dCI6WyJ0eXBlPWRvY2tlciJdfX19","Targets":["dev"],"Refs":["vzxn0jxr44khtq7hc8drtzwjv"]}
|
@ -0,0 +1 @@
|
||||
{"LocalPath":"/home/crazymax/github/docker/docker-alpine-s6","DockerfilePath":""}
|
@ -0,0 +1 @@
|
||||
{"LocalPath":"/home/crazymax/github/docker_org/buildx","DockerfilePath":""}
|
@ -0,0 +1 @@
|
||||
{"LocalPath":"/home/crazymax/github/docker_org/buildx","DockerfilePath":"/home/crazymax/github/docker_org/buildx/Dockerfile"}
|
@ -0,0 +1 @@
|
||||
{"LocalPath":"/home/crazymax/github/docker_org/buildx","DockerfilePath":"/home/crazymax/github/docker_org/buildx/Dockerfile"}
|
@ -0,0 +1 @@
|
||||
{"LocalPath":"/home/crazymax/github/docker_org/buildx","DockerfilePath":""}
|
@ -0,0 +1 @@
|
||||
{"LocalPath":"/home/crazymax/github/docker_org/buildx","DockerfilePath":"/home/crazymax/github/docker_org/buildx/Dockerfile"}
|
@ -0,0 +1 @@
|
||||
{"LocalPath":"/home/crazymax/github/docker_org/buildx","DockerfilePath":""}
|
@ -0,0 +1 @@
|
||||
{"Target":"dev","LocalPath":"/home/crazymax/github/docker_org/docker","DockerfilePath":"/home/crazymax/github/docker_org/docker/Dockerfile","GroupRef":"1fugf958r4peyg86h6scim5t5"}
|
@ -0,0 +1 @@
|
||||
{"Target":"default","LocalPath":"/home/crazymax/github/docker_org/compose/.dev/47231","DockerfilePath":"/home/crazymax/github/docker_org/compose/.dev/47231/bad/Dockerfile"}
|
@ -0,0 +1 @@
|
||||
{"Target":"default","LocalPath":"/home/crazymax/github/docker_org/compose/.dev/47231","DockerfilePath":"/home/crazymax/github/docker_org/compose/.dev/47231/bad/Dockerfile"}
|
@ -0,0 +1 @@
|
||||
{"Target":"default","LocalPath":"/home/crazymax/github/docker_org/compose/.dev/47231","DockerfilePath":"/home/crazymax/github/docker_org/compose/.dev/47231/bad/Dockerfile"}
|
@ -22,7 +22,7 @@ import * as semver from 'semver';
|
||||
import {Docker} from '../docker/docker';
|
||||
import {Exec} from '../exec';
|
||||
|
||||
import {Cert} from '../types/buildx';
|
||||
import {Cert, LocalRefsOpts, LocalRefsResponse, LocalState} from '../types/buildx';
|
||||
|
||||
export interface BuildxOpts {
|
||||
standalone?: boolean;
|
||||
@ -45,6 +45,14 @@ export class Buildx {
|
||||
return process.env.BUILDX_CONFIG || path.join(Docker.configDir, 'buildx');
|
||||
}
|
||||
|
||||
static get refsDir(): string {
|
||||
return path.join(Buildx.configDir, 'refs');
|
||||
}
|
||||
|
||||
static get refsGroupDir(): string {
|
||||
return path.join(Buildx.refsDir, '__group__');
|
||||
}
|
||||
|
||||
static get certsDir(): string {
|
||||
return path.join(Buildx.configDir, 'certs');
|
||||
}
|
||||
@ -168,4 +176,46 @@ export class Buildx {
|
||||
}
|
||||
return driverOpts;
|
||||
}
|
||||
|
||||
public static refs(opts: LocalRefsOpts, refs: LocalRefsResponse = {}): LocalRefsResponse {
|
||||
const {dir, builderName, nodeName, since} = opts;
|
||||
|
||||
let dirpath = path.resolve(dir);
|
||||
if (opts.builderName) {
|
||||
dirpath = path.join(dirpath, opts.builderName);
|
||||
}
|
||||
if (opts.nodeName) {
|
||||
dirpath = path.join(dirpath, opts.nodeName);
|
||||
}
|
||||
if (!fs.existsSync(dirpath)) {
|
||||
return refs;
|
||||
}
|
||||
|
||||
const files = fs.readdirSync(dirpath);
|
||||
for (const file of files) {
|
||||
const filePath = path.join(dirpath, file);
|
||||
const stat = fs.statSync(filePath);
|
||||
if (stat.isDirectory()) {
|
||||
const nopts: LocalRefsOpts = {...opts};
|
||||
if (!builderName) {
|
||||
if (file === '__group__') {
|
||||
continue;
|
||||
}
|
||||
nopts.builderName = file;
|
||||
} else if (!nodeName) {
|
||||
nopts.nodeName = file;
|
||||
}
|
||||
Buildx.refs(nopts, refs);
|
||||
} else {
|
||||
if (since && stat.mtime < since) {
|
||||
continue;
|
||||
}
|
||||
const localState = <LocalState>JSON.parse(fs.readFileSync(filePath, 'utf8'));
|
||||
const ref = `${builderName}/${nodeName}/${file}`;
|
||||
refs[ref] = localState;
|
||||
}
|
||||
}
|
||||
|
||||
return refs;
|
||||
}
|
||||
}
|
||||
|
@ -26,3 +26,21 @@ export interface DownloadVersion {
|
||||
downloadURL: string;
|
||||
releasesURL: string;
|
||||
}
|
||||
|
||||
export interface LocalRefsOpts {
|
||||
dir: string;
|
||||
builderName?: string;
|
||||
nodeName?: string;
|
||||
since?: Date;
|
||||
}
|
||||
|
||||
export interface LocalRefsResponse {
|
||||
[ref: string]: LocalState;
|
||||
}
|
||||
|
||||
export interface LocalState {
|
||||
Target: string;
|
||||
LocalPath: string;
|
||||
DockerfilePath: string;
|
||||
GroupRef?: string;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user