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

@ -31,12 +31,6 @@ jobs:
RUN echo "hello world" RUN echo "hello world"
EOF EOF
# Workaround to fix https://github.com/containers/buildah/issues/3120
- run: |
sudo apt-get install fuse-overlayfs
mkdir -vp ~/.config/containers
printf "[storage.options]\nmount_program=\"/usr/bin/fuse-overlayfs\"" > ~/.config/containers/storage.conf
# Build image using Buildah action # Build image using Buildah action
- name: Build Image - name: Build Image
id: build_image id: build_image

View file

@ -68,12 +68,6 @@ jobs:
path: ${{ env.MVN_REPO_DIR }} path: ${{ env.MVN_REPO_DIR }}
key: ${{ env.MVN_HASH }} key: ${{ env.MVN_HASH }}
# Workaround to fix https://github.com/containers/buildah/issues/3120
- run: |
sudo apt-get install fuse-overlayfs
mkdir -vp ~/.config/containers
printf "[storage.options]\nmount_program=\"/usr/bin/fuse-overlayfs\"" > ~/.config/containers/storage.conf
# Build image using Buildah action # Build image using Buildah action
- name: Build Image - name: Build Image
id: build_image id: build_image

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

11
package-lock.json generated
View file

@ -166,6 +166,12 @@
"integrity": "sha512-t+i85G2LLauDOlH3MQqxVblCKMt5yyRHZsO7NoVKE8T1W1aIosH1bs5xH2RqwXaWw2Si+r66W/tuHRQzKbR51w==", "integrity": "sha512-t+i85G2LLauDOlH3MQqxVblCKMt5yyRHZsO7NoVKE8T1W1aIosH1bs5xH2RqwXaWw2Si+r66W/tuHRQzKbR51w==",
"dev": true "dev": true
}, },
"@types/ini": {
"version": "1.3.30",
"resolved": "https://registry.npmjs.org/@types/ini/-/ini-1.3.30.tgz",
"integrity": "sha512-2+iF8zPSbpU83UKE+PNd4r/MhwNAdyGpk3H+VMgEH3EhjFZq1kouLgRoZrmIcmoGX97xFvqdS44DkICR5Nz3tQ==",
"dev": true
},
"@types/json-schema": { "@types/json-schema": {
"version": "7.0.7", "version": "7.0.7",
"resolved": "https://registry.npmjs.org/@types/json-schema/-/json-schema-7.0.7.tgz", "resolved": "https://registry.npmjs.org/@types/json-schema/-/json-schema-7.0.7.tgz",
@ -1146,6 +1152,11 @@
"resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz", "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz",
"integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==" "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ=="
}, },
"ini": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/ini/-/ini-2.0.0.tgz",
"integrity": "sha512-7PnF4oN3CvZF23ADhA5wRaYEQpJ8qygSkbtTXWBeXWXmEVRXK+1ITciHWwHhsjv1TmW0MgacIv6hEi5pX5NQdA=="
},
"is-arrayish": { "is-arrayish": {
"version": "0.2.1", "version": "0.2.1",
"resolved": "https://registry.npmjs.org/is-arrayish/-/is-arrayish-0.2.1.tgz", "resolved": "https://registry.npmjs.org/is-arrayish/-/is-arrayish-0.2.1.tgz",

View file

@ -23,12 +23,14 @@
"@actions/core": "^1.2.6", "@actions/core": "^1.2.6",
"@actions/exec": "^1.0.4", "@actions/exec": "^1.0.4",
"@actions/io": "^1.0.2", "@actions/io": "^1.0.2",
"ini": "^2.0.0",
"language-recognizer": "0.0.1" "language-recognizer": "0.0.1"
}, },
"devDependencies": { "devDependencies": {
"@redhat-actions/action-io-generator": "^1.5.0", "@redhat-actions/action-io-generator": "^1.5.0",
"@redhat-actions/eslint-config": "^1.2.11", "@redhat-actions/eslint-config": "^1.2.11",
"@redhat-actions/tsconfig": "^1.1.1", "@redhat-actions/tsconfig": "^1.1.1",
"@types/ini": "^1.3.30",
"@types/node": "^12", "@types/node": "^12",
"@typescript-eslint/eslint-plugin": "^4.14.1", "@typescript-eslint/eslint-plugin": "^4.14.1",
"@typescript-eslint/parser": "^4.14.1", "@typescript-eslint/parser": "^4.14.1",

View file

@ -1,7 +1,9 @@
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";
export interface BuildahConfigSettings { export interface BuildahConfigSettings {
entrypoint?: string[]; entrypoint?: string[];
@ -25,10 +27,22 @@ interface Buildah {
export class BuildahCli implements Buildah { export class BuildahCli implements Buildah {
private readonly executable: string; private readonly executable: string;
public storageOptsEnv = "";
constructor(executable: string) { constructor(executable: string) {
this.executable = executable; 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[] { private static getImageFormatOption(useOCI: boolean): string[] {
return [ "--format", useOCI ? "oci" : "docker" ]; 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); const exitCode = await exec.exec(this.executable, args, finalExecOptions);
if (execOptions.ignoreReturnCode !== true && exitCode !== 0) { if (execOptions.ignoreReturnCode !== true && exitCode !== 0) {

View file

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