mirror of
https://github.com/redhat-actions/buildah-build.git
synced 2025-06-08 01:49:03 +00:00
Resolve reviews
Signed-off-by: divyansh42 <diagrawa@redhat.com>
This commit is contained in:
parent
14aeab7d17
commit
6c8dd380f7
5 changed files with 37 additions and 16 deletions
2
dist/index.js
vendored
2
dist/index.js
vendored
File diff suppressed because one or more lines are too long
2
dist/index.js.map
vendored
2
dist/index.js.map
vendored
File diff suppressed because one or more lines are too long
|
@ -1,9 +1,8 @@
|
|||
import * as core from "@actions/core";
|
||||
import * as exec from "@actions/exec";
|
||||
import * as io from "@actions/io";
|
||||
import * as path from "path";
|
||||
import CommandResult from "./types";
|
||||
import { checkStorageDriver } from "./utils";
|
||||
import { isStorageDriverOverlay, findFuseOverlayfsPath } from "./utils";
|
||||
|
||||
export interface BuildahConfigSettings {
|
||||
entrypoint?: string[];
|
||||
|
@ -33,12 +32,18 @@ export class BuildahCli implements Buildah {
|
|||
this.executable = executable;
|
||||
}
|
||||
|
||||
async checkFuseOverlayfs(): Promise<void> {
|
||||
const fuseOverlayfsPath = await io.which("fuse-overlayfs");
|
||||
|
||||
if (fuseOverlayfsPath.startsWith("/usr/bin")) {
|
||||
if (await checkStorageDriver()) {
|
||||
this.storageOptsEnv = "overlay.mount_program=/usr/bin/fuse-overlayfs";
|
||||
// Checks for storage driver if found "overlay",
|
||||
// then checks if "fuse-overlayfs" is installed.
|
||||
// If yes, add mount program to use "fuse-overlayfs"
|
||||
async setStorageOptsEnv(): Promise<void> {
|
||||
if (await isStorageDriverOverlay()) {
|
||||
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`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,7 +17,7 @@ export async function run(): Promise<void> {
|
|||
await cli.execute([ "version" ]);
|
||||
|
||||
// Check if fuse-overlayfs exists and find the storage driver
|
||||
await cli.checkFuseOverlayfs();
|
||||
await cli.setStorageOptsEnv();
|
||||
|
||||
const DEFAULT_TAG = "latest";
|
||||
const workspace = process.env.GITHUB_WORKSPACE || process.cwd();
|
||||
|
|
24
src/utils.ts
24
src/utils.ts
|
@ -2,27 +2,31 @@ 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 checkStorageDriver(): Promise<boolean> {
|
||||
let xdgConfigHome = "~/.config";
|
||||
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",
|
||||
const filePaths: string[] = [
|
||||
"/etc/containers/storage.conf",
|
||||
path.join(xdgConfigHome, "containers/storage.conf"),
|
||||
];
|
||||
const storageDriver = await findStorageDriver(filePaths);
|
||||
|
@ -38,3 +42,15 @@ async function fileExists(filePath: string): Promise<boolean> {
|
|||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
export async function findFuseOverlayfsPath(): Promise<string> {
|
||||
let fuseOverlayfsPath = "";
|
||||
try {
|
||||
fuseOverlayfsPath = await io.which("fuse-overlayfs");
|
||||
}
|
||||
catch (err) {
|
||||
core.debug(err);
|
||||
}
|
||||
|
||||
return fuseOverlayfsPath;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue