Resolve reviews

Signed-off-by: divyansh42 <diagrawa@redhat.com>
This commit is contained in:
divyansh42 2021-04-09 11:06:13 +05:30
parent 14aeab7d17
commit 6c8dd380f7
5 changed files with 37 additions and 16 deletions

2
dist/index.js vendored

File diff suppressed because one or more lines are too long

2
dist/index.js.map vendored

File diff suppressed because one or more lines are too long

View file

@ -1,9 +1,8 @@
import * as core from "@actions/core"; import * as core from "@actions/core";
import * as exec from "@actions/exec"; import * as exec from "@actions/exec";
import * as io from "@actions/io";
import * as path from "path"; import * as path from "path";
import CommandResult from "./types"; import CommandResult from "./types";
import { checkStorageDriver } from "./utils"; import { isStorageDriverOverlay, findFuseOverlayfsPath } from "./utils";
export interface BuildahConfigSettings { export interface BuildahConfigSettings {
entrypoint?: string[]; entrypoint?: string[];
@ -33,12 +32,18 @@ export class BuildahCli implements Buildah {
this.executable = executable; this.executable = executable;
} }
async checkFuseOverlayfs(): Promise<void> { // Checks for storage driver if found "overlay",
const fuseOverlayfsPath = await io.which("fuse-overlayfs"); // then checks if "fuse-overlayfs" is installed.
// If yes, add mount program to use "fuse-overlayfs"
if (fuseOverlayfsPath.startsWith("/usr/bin")) { async setStorageOptsEnv(): Promise<void> {
if (await checkStorageDriver()) { if (await isStorageDriverOverlay()) {
this.storageOptsEnv = "overlay.mount_program=/usr/bin/fuse-overlayfs"; const fuseOverlayfsPath = await findFuseOverlayfsPath();
if (fuseOverlayfsPath) {
core.info(`Overriding storage mount_program with "fuse-overlayfs" in environment`);
this.storageOptsEnv = `overlay.mount_program=${fuseOverlayfsPath}`;
}
else {
core.warning(`"fuse-overlayfs" is not found. Install it before running this action`);
} }
} }
} }

View file

@ -17,7 +17,7 @@ export async function run(): Promise<void> {
await cli.execute([ "version" ]); await cli.execute([ "version" ]);
// Check if fuse-overlayfs exists and find the storage driver // Check if fuse-overlayfs exists and find the storage driver
await cli.checkFuseOverlayfs(); await cli.setStorageOptsEnv();
const DEFAULT_TAG = "latest"; const DEFAULT_TAG = "latest";
const workspace = process.env.GITHUB_WORKSPACE || process.cwd(); const workspace = process.env.GITHUB_WORKSPACE || process.cwd();

View file

@ -2,27 +2,31 @@ import * as ini from "ini";
import { promises as fs } from "fs"; import { promises as fs } from "fs";
import * as core from "@actions/core"; import * as core from "@actions/core";
import * as path from "path"; import * as path from "path";
import * as io from "@actions/io";
import * as os from "os";
async function findStorageDriver(filePaths: string[]): Promise<string> { async function findStorageDriver(filePaths: string[]): Promise<string> {
let storageDriver = ""; let storageDriver = "";
for (const filePath of filePaths) { for (const filePath of filePaths) {
core.debug(`Checking if the storage file exists at ${filePath}`); core.debug(`Checking if the storage file exists at ${filePath}`);
if (await fileExists(filePath)) { if (await fileExists(filePath)) {
core.debug(`Storage file exists at ${filePath}`); core.debug(`Storage file exists at ${filePath}`);
const fileContent = ini.parse(await fs.readFile(filePath, "utf-8")); const fileContent = ini.parse(await fs.readFile(filePath, "utf-8"));
if (fileContent.storage.driver) {
storageDriver = fileContent.storage.driver; storageDriver = fileContent.storage.driver;
} }
} }
}
return storageDriver; return storageDriver;
} }
export async function checkStorageDriver(): Promise<boolean> { export async function isStorageDriverOverlay(): Promise<boolean> {
let xdgConfigHome = "~/.config"; let xdgConfigHome = path.join(os.homedir(), ".config");
if (process.env.XDG_CONFIG_HOME) { if (process.env.XDG_CONFIG_HOME) {
xdgConfigHome = process.env.XDG_CONFIG_HOME; xdgConfigHome = process.env.XDG_CONFIG_HOME;
} }
const filePaths: string[] = [ "/etc/containers/storage.conf", const filePaths: string[] = [
"/etc/containers/storage.conf",
path.join(xdgConfigHome, "containers/storage.conf"), path.join(xdgConfigHome, "containers/storage.conf"),
]; ];
const storageDriver = await findStorageDriver(filePaths); const storageDriver = await findStorageDriver(filePaths);
@ -38,3 +42,15 @@ async function fileExists(filePath: string): Promise<boolean> {
return false; return false;
} }
} }
export async function findFuseOverlayfsPath(): Promise<string> {
let fuseOverlayfsPath = "";
try {
fuseOverlayfsPath = await io.which("fuse-overlayfs");
}
catch (err) {
core.debug(err);
}
return fuseOverlayfsPath;
}