Skip to content

Commit

Permalink
Copy tools to shorter path
Browse files Browse the repository at this point in the history
Signed-off-by: Paweł Gronowski <[email protected]>
  • Loading branch information
vvoland committed Oct 17, 2024
1 parent bcb34bf commit 2ed7185
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/docker/install.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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);
Expand Down
70 changes: 70 additions & 0 deletions src/undock.ts
Original file line number Diff line number Diff line change
@@ -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<void> {
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}`;
}
}

0 comments on commit 2ed7185

Please sign in to comment.