mirror of
https://github.com/redhat-actions/push-to-registry.git
synced 2025-02-23 10:31:22 +01:00
Setup storage-opts for temporary storage
This commit is contained in:
parent
d6ba509bbd
commit
fa01218bc2
6 changed files with 97 additions and 7 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
11
package-lock.json
generated
11
package-lock.json
generated
|
@ -139,6 +139,12 @@
|
|||
"integrity": "sha512-t+i85G2LLauDOlH3MQqxVblCKMt5yyRHZsO7NoVKE8T1W1aIosH1bs5xH2RqwXaWw2Si+r66W/tuHRQzKbR51w==",
|
||||
"dev": true
|
||||
},
|
||||
"@types/ini": {
|
||||
"version": "1.3.31",
|
||||
"resolved": "https://registry.npmjs.org/@types/ini/-/ini-1.3.31.tgz",
|
||||
"integrity": "sha512-8ecxxaG4AlVEM1k9+BsziMw8UsX0qy3jYI1ad/71RrDZ+rdL6aZB0wLfAuflQiDhkD5o4yJ0uPK3OSUic3fG0w==",
|
||||
"dev": true
|
||||
},
|
||||
"@types/json-schema": {
|
||||
"version": "7.0.7",
|
||||
"resolved": "https://registry.npmjs.org/@types/json-schema/-/json-schema-7.0.7.tgz",
|
||||
|
@ -1156,6 +1162,11 @@
|
|||
"integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==",
|
||||
"dev": true
|
||||
},
|
||||
"ini": {
|
||||
"version": "2.0.0",
|
||||
"resolved": "https://registry.npmjs.org/ini/-/ini-2.0.0.tgz",
|
||||
"integrity": "sha512-7PnF4oN3CvZF23ADhA5wRaYEQpJ8qygSkbtTXWBeXWXmEVRXK+1ITciHWwHhsjv1TmW0MgacIv6hEi5pX5NQdA=="
|
||||
},
|
||||
"is-arrayish": {
|
||||
"version": "0.2.1",
|
||||
"resolved": "https://registry.npmjs.org/is-arrayish/-/is-arrayish-0.2.1.tgz",
|
||||
|
|
|
@ -15,12 +15,14 @@
|
|||
"dependencies": {
|
||||
"@actions/core": "^1.2.6",
|
||||
"@actions/exec": "^1.0.4",
|
||||
"@actions/io": "^1.0.2"
|
||||
"@actions/io": "^1.0.2",
|
||||
"ini": "^2.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@redhat-actions/action-io-generator": "^1.5.0",
|
||||
"@redhat-actions/eslint-config": "^1.3.2",
|
||||
"@redhat-actions/tsconfig": "^1.1.1",
|
||||
"@types/ini": "^1.3.30",
|
||||
"@types/node": "^12.12.7",
|
||||
"@typescript-eslint/eslint-plugin": "^4.22.0",
|
||||
"@typescript-eslint/parser": "^4.22.0",
|
||||
|
|
28
src/index.ts
28
src/index.ts
|
@ -5,6 +5,7 @@ import * as fs from "fs";
|
|||
import * as os from "os";
|
||||
import * as path from "path";
|
||||
import {
|
||||
isStorageDriverOverlay, findFuseOverlayfsPath,
|
||||
splitByNewline,
|
||||
isFullImageName, getFullImageName,
|
||||
getFullDockerImageName,
|
||||
|
@ -29,6 +30,7 @@ let isImageFromDocker = false;
|
|||
let sourceImages: string[];
|
||||
let destinationImages: string[];
|
||||
let dockerPodmanRoot: string;
|
||||
let dockerPodmanOpts: string[];
|
||||
|
||||
async function getPodmanPath(): Promise<string> {
|
||||
if (podmanPath == null) {
|
||||
|
@ -208,7 +210,7 @@ async function run(): Promise<void> {
|
|||
// push the image
|
||||
for (const destinationImage of destinationImages) {
|
||||
const args = [
|
||||
...(isImageFromDocker ? [ "--root", dockerPodmanRoot ] : []),
|
||||
...(isImageFromDocker ? dockerPodmanOpts : []),
|
||||
"push",
|
||||
"--quiet",
|
||||
"--digestfile",
|
||||
|
@ -260,7 +262,7 @@ async function pullImageFromDocker(): Promise<ImageStorageCheckResult> {
|
|||
for (const imageWithTag of sourceImages) {
|
||||
const commandResult: ExecResult = await execute(
|
||||
await getPodmanPath(),
|
||||
[ "--root", dockerPodmanRoot, "pull", `docker-daemon:${imageWithTag}` ],
|
||||
[ ...dockerPodmanOpts, "pull", `docker-daemon:${imageWithTag}` ],
|
||||
{ ignoreReturnCode: true, failOnStdErr: false, group: true }
|
||||
);
|
||||
if (commandResult.exitCode === 0) {
|
||||
|
@ -329,7 +331,7 @@ async function isPodmanLocalImageLatest(): Promise<boolean> {
|
|||
// appending 'docker.io/library' infront of image name as pulled image name
|
||||
// from Docker image storage starts with the 'docker.io/library'
|
||||
const pulledImageCreationTimeStamp = await execute(await getPodmanPath(), [
|
||||
"--root", dockerPodmanRoot,
|
||||
...dockerPodmanOpts,
|
||||
"image",
|
||||
"inspect",
|
||||
getFullDockerImageName(imageWithTag),
|
||||
|
@ -346,7 +348,25 @@ async function isPodmanLocalImageLatest(): Promise<boolean> {
|
|||
|
||||
async function createDockerPodmanImageStroage(): Promise<void> {
|
||||
core.info(`Creating temporary Podman image storage for pulling from Docker daemon`);
|
||||
dockerPodmanRoot = await fs.promises.mkdtemp(path.join(os.tmpdir(), "docker-podman"));
|
||||
dockerPodmanRoot = await fs.promises.mkdtemp(path.join(os.tmpdir(), "podman-from-docker-"));
|
||||
|
||||
dockerPodmanOpts = [ "--root", dockerPodmanRoot ];
|
||||
|
||||
if (await isStorageDriverOverlay()) {
|
||||
const fuseOverlayfsPath = await findFuseOverlayfsPath();
|
||||
if (fuseOverlayfsPath) {
|
||||
core.info(`Overriding storage mount_program with "fuse-overlayfs" in environment`);
|
||||
dockerPodmanOpts.push("--storage-opt");
|
||||
dockerPodmanOpts.push(`overlay.mount_program=${fuseOverlayfsPath}`);
|
||||
}
|
||||
else {
|
||||
core.warning(`"fuse-overlayfs" is not found. Install it before running this action. `
|
||||
+ `For more detail see https://github.com/redhat-actions/buildah-build/issues/45`);
|
||||
}
|
||||
}
|
||||
else {
|
||||
core.info("Storage driver is not 'overlay', so not overriding storage configuration");
|
||||
}
|
||||
}
|
||||
|
||||
async function removeDockerPodmanImageStroage(): Promise<void> {
|
||||
|
|
57
src/util.ts
57
src/util.ts
|
@ -3,6 +3,63 @@
|
|||
* Licensed under the MIT License. See LICENSE file in the project root for license information.
|
||||
**************************************************************************************************/
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
export function splitByNewline(s: string): string[] {
|
||||
return s.split(/\r?\n/);
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue