diff --git a/__tests__/docker/install.test.itg.ts b/__tests__/docker/install.test.itg.ts index 479e453..4d0dde9 100644 --- a/__tests__/docker/install.test.itg.ts +++ b/__tests__/docker/install.test.itg.ts @@ -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(() => { diff --git a/__tests__/docker/install.test.ts b/__tests__/docker/install.test.ts index c1b1db2..6b04848 100644 --- a/__tests__/docker/install.test.ts +++ b/__tests__/docker/install.test.ts @@ -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: '' + } + ]); + }); +}); diff --git a/src/docker/assets.ts b/src/docker/assets.ts index a99f7de..fd42cf1 100644 --- a/src/docker/assets.ts +++ b/src/docker/assets.ts @@ -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" diff --git a/src/docker/install.ts b/src/docker/install.ts index e76506a..b655224 100644 --- a/src/docker/install.ts +++ b/src/docker/install.ts @@ -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; @@ -136,8 +142,9 @@ export class Install { await io.mkdirP(limaDir); const dockerHost = `unix://${limaDir}/docker.sock`; - // avoid brew to upgrade unrelated packages. + // avoid brew to auto update and upgrade unrelated packages. let envs = Object.assign({}, process.env, { + HOMEBREW_NO_AUTO_UPDATE: '1', HOMEBREW_NO_INSTALLED_DEPENDENTS_CHECK: '1' }) as { [key: string]: string; @@ -149,6 +156,10 @@ export class Install { }); } + await core.group('Lima version', async () => { + await Exec.exec('lima', ['--version'], {env: envs}); + }); + await core.group('Creating lima config', async () => { let limaDaemonConfig = {}; if (this.daemonConfig) { @@ -158,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, @@ -182,7 +194,7 @@ export class Install { }; await core.group('Starting lima instance', async () => { - const limaStartArgs = ['start', `--name=${this.limaInstanceName}`, '--tty=false']; + const limaStartArgs = ['start', `--name=${this.limaInstanceName}`]; if (process.env.LIMA_START_ARGS) { limaStartArgs.push(process.env.LIMA_START_ARGS); } @@ -507,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; + } } diff --git a/src/util.ts b/src/util.ts index faeed7e..75fcc3b 100644 --- a/src/util.ts +++ b/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 = []; + 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 = []; + if (input == '') { return res; } - const records = parse(items, { + const records = parse(input, { columns: false, relaxQuotes: true, comment: opts?.comment,