From c8a1b7a531119e0942fc8ae3a13acdbfb53750ff Mon Sep 17 00:00:00 2001 From: CrazyMax <1951866+crazy-max@users.noreply.github.com> Date: Sun, 10 Dec 2023 15:11:39 +0100 Subject: [PATCH 1/3] docker(install): don't auto update brew when installing lima Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com> --- src/docker/install.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/docker/install.ts b/src/docker/install.ts index e76506a5..32d34332 100644 --- a/src/docker/install.ts +++ b/src/docker/install.ts @@ -136,8 +136,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; From 348446a8d6b402722141c2d4c9e14615b03edf0a Mon Sep 17 00:00:00 2001 From: CrazyMax <1951866+crazy-max@users.noreply.github.com> Date: Sun, 10 Dec 2023 19:23:44 +0100 Subject: [PATCH 2/3] docker(install): print lima version Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com> --- src/docker/install.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/docker/install.ts b/src/docker/install.ts index 32d34332..17a445a4 100644 --- a/src/docker/install.ts +++ b/src/docker/install.ts @@ -150,6 +150,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) { @@ -183,7 +187,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); } From 4995997eed95ab2a9c251d8c5e893cc901b0adba Mon Sep 17 00:00:00 2001 From: CrazyMax <1951866+crazy-max@users.noreply.github.com> Date: Sun, 10 Dec 2023 16:03:53 +0100 Subject: [PATCH 3/3] docker(install): allow specifying custom lima images Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com> --- __tests__/docker/install.test.itg.ts | 4 +++- __tests__/docker/install.test.ts | 29 ++++++++++++++++++++++++++++ src/docker/assets.ts | 5 +++++ src/docker/install.ts | 28 +++++++++++++++++++++++++++ src/util.ts | 14 ++++++++------ 5 files changed, 73 insertions(+), 7 deletions(-) diff --git a/__tests__/docker/install.test.itg.ts b/__tests__/docker/install.test.itg.ts index 479e4531..4d0dde95 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 c1b1db20..6b04848a 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 a99f7de7..fd42cf1a 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 17a445a4..b6552240 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; @@ -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; + } } diff --git a/src/util.ts b/src/util.ts index faeed7e0..75fcc3b4 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,