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==",
|
"integrity": "sha512-t+i85G2LLauDOlH3MQqxVblCKMt5yyRHZsO7NoVKE8T1W1aIosH1bs5xH2RqwXaWw2Si+r66W/tuHRQzKbR51w==",
|
||||||
"dev": true
|
"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": {
|
"@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",
|
||||||
|
@ -1156,6 +1162,11 @@
|
||||||
"integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==",
|
"integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==",
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
|
"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",
|
||||||
|
|
|
@ -15,12 +15,14 @@
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@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"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@redhat-actions/action-io-generator": "^1.5.0",
|
"@redhat-actions/action-io-generator": "^1.5.0",
|
||||||
"@redhat-actions/eslint-config": "^1.3.2",
|
"@redhat-actions/eslint-config": "^1.3.2",
|
||||||
"@redhat-actions/tsconfig": "^1.1.1",
|
"@redhat-actions/tsconfig": "^1.1.1",
|
||||||
|
"@types/ini": "^1.3.30",
|
||||||
"@types/node": "^12.12.7",
|
"@types/node": "^12.12.7",
|
||||||
"@typescript-eslint/eslint-plugin": "^4.22.0",
|
"@typescript-eslint/eslint-plugin": "^4.22.0",
|
||||||
"@typescript-eslint/parser": "^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 os from "os";
|
||||||
import * as path from "path";
|
import * as path from "path";
|
||||||
import {
|
import {
|
||||||
|
isStorageDriverOverlay, findFuseOverlayfsPath,
|
||||||
splitByNewline,
|
splitByNewline,
|
||||||
isFullImageName, getFullImageName,
|
isFullImageName, getFullImageName,
|
||||||
getFullDockerImageName,
|
getFullDockerImageName,
|
||||||
|
@ -29,6 +30,7 @@ let isImageFromDocker = false;
|
||||||
let sourceImages: string[];
|
let sourceImages: string[];
|
||||||
let destinationImages: string[];
|
let destinationImages: string[];
|
||||||
let dockerPodmanRoot: string;
|
let dockerPodmanRoot: string;
|
||||||
|
let dockerPodmanOpts: string[];
|
||||||
|
|
||||||
async function getPodmanPath(): Promise<string> {
|
async function getPodmanPath(): Promise<string> {
|
||||||
if (podmanPath == null) {
|
if (podmanPath == null) {
|
||||||
|
@ -208,7 +210,7 @@ async function run(): Promise<void> {
|
||||||
// push the image
|
// push the image
|
||||||
for (const destinationImage of destinationImages) {
|
for (const destinationImage of destinationImages) {
|
||||||
const args = [
|
const args = [
|
||||||
...(isImageFromDocker ? [ "--root", dockerPodmanRoot ] : []),
|
...(isImageFromDocker ? dockerPodmanOpts : []),
|
||||||
"push",
|
"push",
|
||||||
"--quiet",
|
"--quiet",
|
||||||
"--digestfile",
|
"--digestfile",
|
||||||
|
@ -260,7 +262,7 @@ async function pullImageFromDocker(): Promise<ImageStorageCheckResult> {
|
||||||
for (const imageWithTag of sourceImages) {
|
for (const imageWithTag of sourceImages) {
|
||||||
const commandResult: ExecResult = await execute(
|
const commandResult: ExecResult = await execute(
|
||||||
await getPodmanPath(),
|
await getPodmanPath(),
|
||||||
[ "--root", dockerPodmanRoot, "pull", `docker-daemon:${imageWithTag}` ],
|
[ ...dockerPodmanOpts, "pull", `docker-daemon:${imageWithTag}` ],
|
||||||
{ ignoreReturnCode: true, failOnStdErr: false, group: true }
|
{ ignoreReturnCode: true, failOnStdErr: false, group: true }
|
||||||
);
|
);
|
||||||
if (commandResult.exitCode === 0) {
|
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
|
// appending 'docker.io/library' infront of image name as pulled image name
|
||||||
// from Docker image storage starts with the 'docker.io/library'
|
// from Docker image storage starts with the 'docker.io/library'
|
||||||
const pulledImageCreationTimeStamp = await execute(await getPodmanPath(), [
|
const pulledImageCreationTimeStamp = await execute(await getPodmanPath(), [
|
||||||
"--root", dockerPodmanRoot,
|
...dockerPodmanOpts,
|
||||||
"image",
|
"image",
|
||||||
"inspect",
|
"inspect",
|
||||||
getFullDockerImageName(imageWithTag),
|
getFullDockerImageName(imageWithTag),
|
||||||
|
@ -346,7 +348,25 @@ async function isPodmanLocalImageLatest(): Promise<boolean> {
|
||||||
|
|
||||||
async function createDockerPodmanImageStroage(): Promise<void> {
|
async function createDockerPodmanImageStroage(): Promise<void> {
|
||||||
core.info(`Creating temporary Podman image storage for pulling from Docker daemon`);
|
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> {
|
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.
|
* 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[] {
|
export function splitByNewline(s: string): string[] {
|
||||||
return s.split(/\r?\n/);
|
return s.split(/\r?\n/);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue