mirror of
https://github.com/hoverkraft-tech/compose-action.git
synced 2026-08-31 23:52:49 +08:00
Some checks failed
Internal - Main - Continuous Integration / ci (push) Has been cancelled
Need fix to Issue / main (push) Has been cancelled
Prepare release / release (push) Has been cancelled
Internal - Main - Continuous Integration / prepare-docs (push) Has been cancelled
Internal - Main - Continuous Integration / sync-docs (push) Has been cancelled
Mark stale issues and pull requests / main (push) Has been cancelled
Bumps the github-actions-dependencies group with 6 updates: --- updated-dependencies: - dependency-name: hoverkraft-tech/ci-github-common/.github/workflows/linter.yml dependency-version: 0.36.0 dependency-type: direct:production update-type: version-update:semver-minor dependency-group: github-actions-dependencies - dependency-name: hoverkraft-tech/ci-github-common/.github/workflows/greetings.yml dependency-version: 0.36.0 dependency-type: direct:production update-type: version-update:semver-minor dependency-group: github-actions-dependencies - dependency-name: hoverkraft-tech/ci-github-common dependency-version: 0.36.0 dependency-type: direct:production update-type: version-update:semver-minor dependency-group: github-actions-dependencies - dependency-name: hoverkraft-tech/ci-github-common/.github/workflows/need-fix-to-issue.yml dependency-version: 0.36.0 dependency-type: direct:production update-type: version-update:semver-minor dependency-group: github-actions-dependencies - dependency-name: hoverkraft-tech/ci-github-common/.github/workflows/semantic-pull-request.yml dependency-version: 0.36.0 dependency-type: direct:production update-type: version-update:semver-minor dependency-group: github-actions-dependencies - dependency-name: hoverkraft-tech/ci-github-common/.github/workflows/stale.yml dependency-version: 0.36.0 dependency-type: direct:production update-type: version-update:semver-minor dependency-group: github-actions-dependencies ... Signed-off-by: dependabot[bot] <support@github.com> Signed-off-by: Emilien Escalle <emilien.escalle@escemi.com>
70 lines
2.0 KiB
TypeScript
70 lines
2.0 KiB
TypeScript
import { exec } from "@actions/exec";
|
|
import { mkdirP } from "@actions/io";
|
|
import { basename } from "node:path";
|
|
import { cacheFile, downloadTool } from "@actions/tool-cache";
|
|
import type { DockerComposeInstallerAdapter } from "./docker-compose-installer-adapter.js";
|
|
|
|
export class ManualInstallerAdapter implements DockerComposeInstallerAdapter {
|
|
async install(version: string): Promise<void> {
|
|
const dockerComposePluginPath = await this.getDockerComposePluginPath();
|
|
|
|
// Create the directory if it doesn't exist
|
|
await mkdirP(basename(dockerComposePluginPath));
|
|
|
|
await this.downloadFile(version, dockerComposePluginPath);
|
|
await exec(`chmod +x ${dockerComposePluginPath}`);
|
|
await cacheFile(
|
|
dockerComposePluginPath,
|
|
"docker-compose",
|
|
"docker-compose",
|
|
version,
|
|
);
|
|
}
|
|
|
|
private async getDockerComposePluginPath(): Promise<string> {
|
|
const dockerConfig =
|
|
process.env.DOCKER_CONFIG || `${process.env.HOME}/.docker`;
|
|
|
|
const dockerComposePluginPath = `${dockerConfig}/cli-plugins/docker-compose`;
|
|
return dockerComposePluginPath;
|
|
}
|
|
|
|
private async downloadFile(
|
|
version: string,
|
|
installerPath: string,
|
|
): Promise<void> {
|
|
if (!version.startsWith("v") && parseInt(version.split(".")[0], 10) >= 2) {
|
|
version = `v${version}`;
|
|
}
|
|
|
|
const system = await this.getSystem();
|
|
const hardware = await this.getHardware();
|
|
|
|
const url = `https://github.com/docker/compose/releases/download/${version}/docker-compose-${system}-${hardware}`;
|
|
await downloadTool(url, installerPath);
|
|
}
|
|
|
|
private async getSystem(): Promise<string> {
|
|
return this.runCommand("uname -s");
|
|
}
|
|
|
|
private async getHardware(): Promise<string> {
|
|
return this.runCommand("uname -m");
|
|
}
|
|
|
|
private async runCommand(command: string): Promise<string> {
|
|
let output = "";
|
|
const result = await exec(command, [], {
|
|
listeners: {
|
|
stdout: (data: Buffer) => {
|
|
output += data.toString();
|
|
},
|
|
},
|
|
});
|
|
if (result !== 0) {
|
|
throw new Error(`Failed to run command: ${command}`);
|
|
}
|
|
return output.trim();
|
|
}
|
|
}
|