2021-02-08 20:07:42 +05:30
|
|
|
/***************************************************************************************************
|
|
|
|
* Copyright (c) Red Hat, Inc. All rights reserved.
|
|
|
|
* Licensed under the MIT License. See LICENSE file in the project root for license information.
|
|
|
|
**************************************************************************************************/
|
|
|
|
|
2021-10-12 10:22:18 -07:00
|
|
|
import * as ini from "ini";
|
|
|
|
import { promises as fs } from "fs";
|
|
|
|
import * as core from "@actions/core";
|
|
|
|
import * as path from "path";
|
|
|
|
import * as io from "@actions/io";
|
|
|
|
import * as os from "os";
|
|
|
|
|
|
|
|
async function findStorageDriver(filePaths: string[]): Promise<string> {
|
|
|
|
let storageDriver = "";
|
|
|
|
for (const filePath of filePaths) {
|
|
|
|
core.debug(`Checking if the storage file exists at ${filePath}`);
|
|
|
|
if (await fileExists(filePath)) {
|
|
|
|
core.debug(`Storage file exists at ${filePath}`);
|
|
|
|
const fileContent = ini.parse(await fs.readFile(filePath, "utf-8"));
|
|
|
|
if (fileContent.storage.driver) {
|
|
|
|
storageDriver = fileContent.storage.driver;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return storageDriver;
|
|
|
|
}
|
|
|
|
|
|
|
|
export async function isStorageDriverOverlay(): Promise<boolean> {
|
|
|
|
let xdgConfigHome = path.join(os.homedir(), ".config");
|
|
|
|
if (process.env.XDG_CONFIG_HOME) {
|
|
|
|
xdgConfigHome = process.env.XDG_CONFIG_HOME;
|
|
|
|
}
|
|
|
|
const filePaths: string[] = [
|
|
|
|
"/etc/containers/storage.conf",
|
|
|
|
path.join(xdgConfigHome, "containers/storage.conf"),
|
|
|
|
];
|
|
|
|
const storageDriver = await findStorageDriver(filePaths);
|
|
|
|
return (storageDriver === "overlay");
|
|
|
|
}
|
|
|
|
|
|
|
|
async function fileExists(filePath: string): Promise<boolean> {
|
|
|
|
try {
|
|
|
|
await fs.access(filePath);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
catch (err) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export async function findFuseOverlayfsPath(): Promise<string | undefined> {
|
|
|
|
let fuseOverlayfsPath;
|
|
|
|
try {
|
|
|
|
fuseOverlayfsPath = await io.which("fuse-overlayfs");
|
|
|
|
}
|
|
|
|
catch (err) {
|
|
|
|
core.debug(err);
|
|
|
|
}
|
|
|
|
|
|
|
|
return fuseOverlayfsPath;
|
|
|
|
}
|
|
|
|
|
2021-02-08 20:07:42 +05:30
|
|
|
export function splitByNewline(s: string): string[] {
|
|
|
|
return s.split(/\r?\n/);
|
|
|
|
}
|
2021-10-12 10:22:18 -07:00
|
|
|
|
|
|
|
export function isFullImageName(image: string): boolean {
|
|
|
|
return image.indexOf(":") > 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
export function getFullImageName(image: string, tag: string): string {
|
|
|
|
if (isFullImageName(tag)) {
|
|
|
|
return tag;
|
|
|
|
}
|
|
|
|
return `${image}:${tag}`;
|
|
|
|
}
|
|
|
|
|
|
|
|
const DOCKER_IO = `docker.io`;
|
|
|
|
const DOCKER_IO_NAMESPACED = DOCKER_IO + `/library`;
|
|
|
|
|
|
|
|
export function getFullDockerImageName(image: string): string {
|
|
|
|
switch (image.split("/").length) {
|
|
|
|
case 1:
|
|
|
|
return `${DOCKER_IO_NAMESPACED}/${image}`;
|
|
|
|
case 2:
|
2023-02-15 13:21:30 +01:00
|
|
|
if (image.includes("amazonaws.com")) return image;
|
2021-10-12 10:22:18 -07:00
|
|
|
return `${DOCKER_IO}/${image}`;
|
|
|
|
default:
|
|
|
|
return image;
|
|
|
|
}
|
|
|
|
}
|