diff --git a/src/docker/install.ts b/src/docker/install.ts index f3008cb4..e1450452 100644 --- a/src/docker/install.ts +++ b/src/docker/install.ts @@ -200,8 +200,12 @@ export class Install { await io.mkdirP(limaDir); const dockerHost = `unix://${limaDir}/docker.sock`; + // this.toolDir is a very long path which causes trouble when mounting it in lima. + // Copy it to a shorter path. + const limaToolsDir = path.join(limaDir, 'tools'); + await core.group('Listing toolDir', async () => { - await Exec.exec('ls', ['-la', this.toolDir]); + await Exec.exec('cp', ['-r', this.toolDir, limaToolsDir]); }); // avoid brew to auto update and upgrade unrelated packages. @@ -239,7 +243,7 @@ export class Install { srcArchiveVersion: srcArchive.version?.replace(/^v/, ''), srcArchiveChannel: srcArchive.channel, srcImageTag: (src as InstallSourceImage).tag, - toolDir: this.toolDir + toolDir: limaToolsDir, }); core.info(`Writing lima config to ${path.join(limaDir, 'lima.yaml')}`); fs.writeFileSync(path.join(limaDir, 'lima.yaml'), limaCfg); diff --git a/src/undock.ts b/src/undock.ts new file mode 100644 index 00000000..81c3c8d2 --- /dev/null +++ b/src/undock.ts @@ -0,0 +1,70 @@ +/** + * Copyright 2023 actions-toolkit authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import os from 'os'; +import * as core from '@actions/core'; +import * as tc from '@actions/tool-cache'; + +export class Undock { + static _toolDir: string; + + static async install(): Promise { + core.info('Installing undock...'); + + const version = '0.8.0'; + const url = this.undockUrl(version); + + const archivePath = await tc.downloadTool(url); + const extractedPath = await tc.extractTar(archivePath); + + const undockPath = extractedPath + `undock_${version}_${this.platformArch()}/undock`; + const toolDir = await tc.cacheDir(undockPath, 'undock', version); + + core.debug(`undock dir: ${toolDir}`); + core.addPath(toolDir); + this._toolDir = toolDir; + } + + private static undockUrl(version): string { + const pa = this.platformArch(); + const extension = os.platform() === 'win32' ? 'zip' : 'tar.gz'; + return `https://github.com/crazy-max/undock/releases/download/v${version}/undock_${version}_${pa}.${extension}`; + } + + private static platformArch(): string { + const platform = os.platform() === 'win32' ? 'windows' : os.platform(); + + let arch = os.arch(); + switch (arch) { + case 'x64': { + arch = 'amd64'; + break; + } + case 'ppc64': { + arch = 'ppc64le'; + break; + } + case 'arm': { + // eslint-disable-next-line @typescript-eslint/no-explicit-any + const arm_version = (process.config.variables as any).arm_version; + arch = arm_version ? 'armv' + arm_version : 'arm'; + break; + } + } + + return `${platform}_${arch}`; + } +}