mirror of
https://github.com/docker/actions-toolkit.git
synced 2024-11-26 22:26:08 +08:00
docker(install): allow specifying custom lima images
Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com>
This commit is contained in:
parent
348446a8d6
commit
4995997eed
@ -29,7 +29,9 @@ describe('install', () => {
|
||||
jest.resetModules();
|
||||
process.env = {
|
||||
...originalEnv,
|
||||
LIMA_START_ARGS: '--cpus 4 --memory 8'
|
||||
LIMA_START_ARGS: '--cpus 4 --memory 8',
|
||||
LIMA_IMAGES: `x86_64:https://cloud.debian.org/images/cloud/bookworm/20231013-1532/debian-12-genericcloud-amd64-20231013-1532.qcow2@sha512:6b55e88b027c14da1b55c85a25a9f7069d4560a8fdb2d948c986a585db469728a06d2c528303e34bb62d8b2984def38fd9ddfc00965846ff6e05b01d6e883bfe
|
||||
aarch64:https://cloud.debian.org/images/cloud/bookworm/20231013-1532/debian-12-genericcloud-arm64-20231013-1532.qcow2`
|
||||
};
|
||||
});
|
||||
afterEach(() => {
|
||||
|
@ -71,3 +71,32 @@ describe('getRelease', () => {
|
||||
await expect(Install.getRelease('foo')).rejects.toThrow(new Error('Cannot find Docker release foo in https://raw.githubusercontent.com/docker/actions-toolkit/main/.github/docker-releases.json'));
|
||||
});
|
||||
});
|
||||
|
||||
describe('limaImage', () => {
|
||||
const originalEnv = process.env;
|
||||
beforeEach(() => {
|
||||
jest.resetModules();
|
||||
process.env = {
|
||||
...originalEnv,
|
||||
LIMA_IMAGES: `x86_64:https://cloud-images.ubuntu.com/releases/23.10/release-20231011/ubuntu-23.10-server-cloudimg-amd64.img@sha256:f6529be56da3429a56e4f5ef202bf4958201bc63f8541e478caa6e8eb712e635
|
||||
aarch64:https://cloud-images.ubuntu.com/releases/23.10/release-20231011/ubuntu-23.10-server-cloudimg-arm64.img`
|
||||
};
|
||||
});
|
||||
afterEach(() => {
|
||||
process.env = originalEnv;
|
||||
});
|
||||
it('returns custom images', async () => {
|
||||
expect(Install.limaCustomImages()).toEqual([
|
||||
{
|
||||
location: 'https://cloud-images.ubuntu.com/releases/23.10/release-20231011/ubuntu-23.10-server-cloudimg-amd64.img',
|
||||
arch: 'x86_64',
|
||||
digest: 'sha256:f6529be56da3429a56e4f5ef202bf4958201bc63f8541e478caa6e8eb712e635'
|
||||
},
|
||||
{
|
||||
location: 'https://cloud-images.ubuntu.com/releases/23.10/release-20231011/ubuntu-23.10-server-cloudimg-arm64.img',
|
||||
arch: 'aarch64',
|
||||
digest: ''
|
||||
}
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
@ -144,6 +144,11 @@ os: null
|
||||
arch: null
|
||||
|
||||
images:
|
||||
{{#each customImages}}
|
||||
- location: "{{location}}"
|
||||
arch: "{{arch}}"
|
||||
digest: "{{digest}}"
|
||||
{{/each}}
|
||||
- location: "https://cloud-images.ubuntu.com/releases/22.04/release-20231026/ubuntu-22.04-server-cloudimg-amd64.img"
|
||||
arch: "x86_64"
|
||||
digest: "sha256:054db2d88c454bb0ad8dfd8883955e3946b57d2b0bf0d023f3ade3c93cdd14e5"
|
||||
|
@ -41,6 +41,12 @@ export interface InstallOpts {
|
||||
daemonConfig?: string;
|
||||
}
|
||||
|
||||
interface LimaImage {
|
||||
location: string;
|
||||
arch: string;
|
||||
digest?: string;
|
||||
}
|
||||
|
||||
export class Install {
|
||||
private readonly runDir: string;
|
||||
private readonly version: string;
|
||||
@ -163,6 +169,7 @@ export class Install {
|
||||
return new handlebars.SafeString(JSON.stringify(obj));
|
||||
});
|
||||
const limaCfg = handlebars.compile(limaYamlData)({
|
||||
customImages: Install.limaCustomImages(),
|
||||
daemonConfig: limaDaemonConfig,
|
||||
dockerSock: `${limaDir}/docker.sock`,
|
||||
dockerBinVersion: this._version,
|
||||
@ -512,4 +519,25 @@ EOF`,
|
||||
}
|
||||
return releases[version];
|
||||
}
|
||||
|
||||
public static limaCustomImages(): LimaImage[] {
|
||||
const res: LimaImage[] = [];
|
||||
const env = process.env.LIMA_IMAGES;
|
||||
if (!env) {
|
||||
return res;
|
||||
}
|
||||
for (const input of Util.getList(env, {ignoreComma: true, comment: '#'})) {
|
||||
const archIndex = input.indexOf(':');
|
||||
const arch = input.substring(0, archIndex).trim();
|
||||
const digestIndex = input.indexOf('@');
|
||||
const location = input.substring(archIndex + 1, digestIndex !== -1 ? digestIndex : undefined).trim();
|
||||
const digest = digestIndex !== -1 ? input.substring(digestIndex + 1).trim() : '';
|
||||
res.push({
|
||||
location: location,
|
||||
arch: arch,
|
||||
digest: digest
|
||||
});
|
||||
}
|
||||
return res;
|
||||
}
|
||||
}
|
||||
|
14
src/util.ts
14
src/util.ts
@ -19,22 +19,24 @@ import * as core from '@actions/core';
|
||||
import * as io from '@actions/io';
|
||||
import {parse} from 'csv-parse/sync';
|
||||
|
||||
export interface InputListOpts {
|
||||
export interface ListOpts {
|
||||
ignoreComma?: boolean;
|
||||
comment?: string;
|
||||
quote?: string | boolean | Buffer | null;
|
||||
}
|
||||
|
||||
export class Util {
|
||||
public static getInputList(name: string, opts?: InputListOpts): string[] {
|
||||
const res: Array<string> = [];
|
||||
public static getInputList(name: string, opts?: ListOpts): string[] {
|
||||
return this.getList(core.getInput(name), opts);
|
||||
}
|
||||
|
||||
const items = core.getInput(name);
|
||||
if (items == '') {
|
||||
public static getList(input: string, opts?: ListOpts): string[] {
|
||||
const res: Array<string> = [];
|
||||
if (input == '') {
|
||||
return res;
|
||||
}
|
||||
|
||||
const records = parse(items, {
|
||||
const records = parse(input, {
|
||||
columns: false,
|
||||
relaxQuotes: true,
|
||||
comment: opts?.comment,
|
||||
|
Loading…
Reference in New Issue
Block a user