Fix buildah issue of using overlay as storage driver

Signed-off-by: divyansh42 <diagrawa@redhat.com>
This commit is contained in:
divyansh42 2021-04-08 17:37:32 +05:30
parent 65f18d484c
commit 67f10fa66b
9 changed files with 81 additions and 14 deletions

View file

@ -1,7 +1,9 @@
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";
export interface BuildahConfigSettings {
entrypoint?: string[];
@ -25,10 +27,22 @@ interface Buildah {
export class BuildahCli implements Buildah {
private readonly executable: string;
public storageOptsEnv = "";
constructor(executable: string) {
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";
}
}
}
private static getImageFormatOption(useOCI: boolean): string[] {
return [ "--format", useOCI ? "oci" : "docker" ];
}
@ -158,6 +172,15 @@ export class BuildahCli implements Buildah {
},
};
// To solve https://github.com/redhat-actions/buildah-build/issues/45
if (this.storageOptsEnv) {
finalExecOptions.env = {
...process.env,
STORAGE_OPTS: this.storageOptsEnv,
};
}
const exitCode = await exec.exec(this.executable, args, finalExecOptions);
if (execOptions.ignoreReturnCode !== true && exitCode !== 0) {

View file

@ -16,6 +16,9 @@ export async function run(): Promise<void> {
// print buildah version
await cli.execute([ "version" ]);
// Check if fuse-overlayfs exists and find the storage driver
await cli.checkFuseOverlayfs();
const DEFAULT_TAG = "latest";
const workspace = process.env.GITHUB_WORKSPACE || process.cwd();
const dockerFiles = getInputList(Inputs.DOCKERFILES);

40
src/utils.ts Normal file
View file

@ -0,0 +1,40 @@
import * as ini from "ini";
import { promises as fs } from "fs";
import * as core from "@actions/core";
import * as path from "path";
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"));
storageDriver = fileContent.storage.driver;
}
}
return storageDriver;
}
export async function checkStorageDriver(): Promise<boolean> {
let xdgConfigHome = "~/.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;
}
}