Skip to content

Commit

Permalink
docker(install): set optim vm type on macos
Browse files Browse the repository at this point in the history
Signed-off-by: CrazyMax <[email protected]>
  • Loading branch information
crazy-max committed Sep 27, 2024
1 parent 2c5e187 commit 98042ca
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/docker/assets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ export const limaYamlData = `
# The vmType can be specified only on creating the instance.
# The vmType of existing instances cannot be changed.
# Builtin default: "qemu"
vmType: qemu
vmType: {{vmType}}
# OS: "Linux".
# Builtin default: "Linux"
Expand Down Expand Up @@ -188,7 +188,7 @@ mounts:
# Mount type for above mounts, such as "reverse-sshfs" (from sshocker), "9p" (EXPERIMENTAL, from QEMU’s virtio-9p-pci, aka virtfs),
# or "virtiofs" (EXPERIMENTAL, needs \`vmType: vz\`)
# Builtin default: "reverse-sshfs" (for QEMU), "virtiofs" (for vz)
mountType: null
mountType: {{mountType}}
containerd:
system: false
Expand Down
26 changes: 26 additions & 0 deletions src/docker/install.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import os from 'os';
import path from 'path';
import retry from 'async-retry';
import * as handlebars from 'handlebars';
import * as semver from 'semver';
import * as util from 'util';
import * as core from '@actions/core';
import * as httpm from '@actions/http-client';
Expand Down Expand Up @@ -140,6 +141,22 @@ export class Install {
await io.mkdirP(limaDir);
const dockerHost = `unix://${limaDir}/docker.sock`;

// fallback to a version requiring QEMU with colima
let macosVersion = '12.0.0';
await core.group('macOS version', async () => {
macosVersion = await Exec.getExecOutput(`sw_vers`, ['-productVersion'], {
ignoreReturnCode: true,
silent: true
}).then(res => {
if (res.exitCode == 0 && res.stdout.length > 0) {
return res.stdout.trim();
}
core.info(`sw_vers failed to get macOS version. Using ${macosVersion} as fallback.`);
return macosVersion;
});
core.info(macosVersion);
});

// avoid brew to auto update and upgrade unrelated packages.
let envs = Object.assign({}, process.env, {
HOMEBREW_NO_AUTO_UPDATE: '1',
Expand All @@ -158,6 +175,13 @@ export class Install {
await Exec.exec('lima', ['--version'], {env: envs});
});

let limaVmType = 'vz';
let limaMountType = 'virtiofs';
if (semver.satisfies(macosVersion, '<13.0.0')) {
limaVmType = 'qemu';
limaMountType = '9p';
}

await core.group('Creating lima config', async () => {
let limaDaemonConfig = {};
if (this.daemonConfig) {
Expand All @@ -167,7 +191,9 @@ export class Install {
return new handlebars.SafeString(JSON.stringify(obj));
});
const limaCfg = handlebars.compile(limaYamlData)({
vmType: limaVmType,
customImages: Install.limaCustomImages(),
mountType: limaMountType,
daemonConfig: limaDaemonConfig,
dockerSock: `${limaDir}/docker.sock`,
dockerBinVersion: this._version,
Expand Down

0 comments on commit 98042ca

Please sign in to comment.