mirror of
https://github.com/redhat-actions/podman-login.git
synced 2025-02-22 18:11:21 +01:00
Add ability to pull image from docker after login
Signed-off-by: divyansh42 <diagrawa@redhat.com>
This commit is contained in:
parent
4c93cb1ea3
commit
fc74315ff2
6 changed files with 66 additions and 27 deletions
33
.github/workflows/example.yml
vendored
33
.github/workflows/example.yml
vendored
|
@ -1,6 +1,7 @@
|
|||
name: Test Login and Pull
|
||||
on:
|
||||
push:
|
||||
pull_request_target:
|
||||
workflow_dispatch:
|
||||
schedule:
|
||||
- cron: '0 0 * * *' # every day at midnight
|
||||
|
@ -42,6 +43,10 @@ jobs:
|
|||
buildah-pull:
|
||||
name: Log in and pull image with Buildah
|
||||
runs-on: ubuntu-20.04
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
install_latest: [ true, false ]
|
||||
steps:
|
||||
|
||||
- uses: actions/checkout@v2
|
||||
|
@ -50,7 +55,7 @@ jobs:
|
|||
if: matrix.install_latest
|
||||
run: |
|
||||
bash .github/install_latest_podman.sh
|
||||
|
||||
|
||||
- name: Log in to quay.io
|
||||
uses: ./
|
||||
with:
|
||||
|
@ -60,3 +65,29 @@ jobs:
|
|||
|
||||
- name: Pull image with Buildah
|
||||
run: buildah pull ${{ env.IMAGE_PATH }}
|
||||
|
||||
docker-pull:
|
||||
name: Log in and pull image with Docker
|
||||
runs-on: ubuntu-20.04
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
install_latest: [ true, false ]
|
||||
steps:
|
||||
|
||||
- uses: actions/checkout@v2
|
||||
|
||||
- name: Install latest podman
|
||||
if: matrix.install_latest
|
||||
run: |
|
||||
bash .github/install_latest_podman.sh
|
||||
|
||||
- name: Log in to quay.io
|
||||
uses: ./
|
||||
with:
|
||||
username: ${{ env.REGISTRY_USER }}
|
||||
password: ${{ env.REGISTRY_PASSWORD }}
|
||||
registry: ${{ env.IMAGE_REGISTRY }}
|
||||
|
||||
- name: Pull image with Docker
|
||||
run: docker pull ${{ env.IMAGE_PATH }}
|
||||
|
|
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,18 +0,0 @@
|
|||
import * as core from "@actions/core";
|
||||
import { Inputs } from "./generated/inputs-outputs";
|
||||
|
||||
export interface ActionInputs {
|
||||
registry: string;
|
||||
username: string;
|
||||
password: string;
|
||||
logout: string;
|
||||
}
|
||||
|
||||
export function getInputs(): ActionInputs {
|
||||
return {
|
||||
registry: core.getInput(Inputs.REGISTRY, { required: true }),
|
||||
username: core.getInput(Inputs.USERNAME, { required: true }),
|
||||
password: core.getInput(Inputs.PASSWORD, { required: true }),
|
||||
logout: core.getInput(Inputs.LOGOUT) || "true",
|
||||
};
|
||||
}
|
31
src/index.ts
31
src/index.ts
|
@ -4,14 +4,17 @@
|
|||
**************************************************************************************************/
|
||||
|
||||
import * as core from "@actions/core";
|
||||
import { promises as fs } from "fs";
|
||||
import * as io from "@actions/io";
|
||||
import * as os from "os";
|
||||
import * as path from "path";
|
||||
import { getInputs } from "./context";
|
||||
import { execute } from "./utils";
|
||||
import { execute, getDockerConfigJson } from "./utils";
|
||||
import * as stateHelper from "./state-helper";
|
||||
import { Inputs } from "./generated/inputs-outputs";
|
||||
|
||||
let podmanPath: string | undefined;
|
||||
let registry: string;
|
||||
const dockerConfigPath = path.join(os.homedir(), ".docker", "config.json");
|
||||
|
||||
async function getPodmanPath(): Promise<string> {
|
||||
if (podmanPath == null) {
|
||||
|
@ -27,9 +30,10 @@ async function run(): Promise<void> {
|
|||
throw new Error("❌ Only supported on linux platform");
|
||||
}
|
||||
|
||||
const {
|
||||
registry, username, password, logout,
|
||||
} = getInputs();
|
||||
registry = core.getInput(Inputs.REGISTRY, { required: true });
|
||||
const username = core.getInput(Inputs.USERNAME, { required: true });
|
||||
const password = core.getInput(Inputs.PASSWORD, { required: true });
|
||||
const logout = core.getInput(Inputs.LOGOUT) || "true";
|
||||
|
||||
stateHelper.setRegistry(registry);
|
||||
stateHelper.setLogout(logout);
|
||||
|
@ -42,7 +46,6 @@ async function run(): Promise<void> {
|
|||
"-p",
|
||||
password,
|
||||
];
|
||||
|
||||
await execute(await getPodmanPath(), args);
|
||||
core.info(`✅ Successfully logged in to ${registry} as ${username}`);
|
||||
|
||||
|
@ -57,6 +60,17 @@ async function run(): Promise<void> {
|
|||
const REGISTRY_AUTH_ENVVAR = "REGISTRY_AUTH_FILE";
|
||||
core.info(`Exporting ${REGISTRY_AUTH_ENVVAR}=${podmanAuthFilePath}`);
|
||||
core.exportVariable(REGISTRY_AUTH_ENVVAR, podmanAuthFilePath);
|
||||
|
||||
const podmanConfigJson = await fs.readFile(podmanAuthFilePath, "utf-8");
|
||||
const podmanConfig = JSON.parse(podmanConfigJson);
|
||||
const generatedAuth = podmanConfig.auths[registry];
|
||||
|
||||
core.info(`✍️ Writing registry credentials to "${dockerConfigPath}"`);
|
||||
const dockerConfig = JSON.parse(await getDockerConfigJson());
|
||||
|
||||
dockerConfig.auths[registry] = generatedAuth;
|
||||
|
||||
await fs.writeFile(dockerConfigPath, JSON.stringify(dockerConfig, undefined, 8), "utf-8");
|
||||
}
|
||||
|
||||
async function registryLogout(): Promise<void> {
|
||||
|
@ -64,6 +78,11 @@ async function registryLogout(): Promise<void> {
|
|||
return;
|
||||
}
|
||||
await execute(await getPodmanPath(), [ "logout", stateHelper.registry ]);
|
||||
|
||||
const dockerConfig = JSON.parse(await getDockerConfigJson());
|
||||
core.info(`Removing registry credentials from "${dockerConfigPath}"`);
|
||||
delete dockerConfig.auths[registry];
|
||||
await fs.writeFile(dockerConfigPath, JSON.stringify(dockerConfig, undefined, 8), "utf-8");
|
||||
}
|
||||
|
||||
if (!stateHelper.IsPost) {
|
||||
|
|
|
@ -6,6 +6,8 @@
|
|||
import * as core from "@actions/core";
|
||||
import * as exec from "@actions/exec";
|
||||
import * as path from "path";
|
||||
import { promises as fs } from "fs";
|
||||
import * as os from "os";
|
||||
|
||||
interface ExecResult {
|
||||
exitCode: number;
|
||||
|
@ -64,3 +66,8 @@ export async function execute(
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
export async function getDockerConfigJson(): Promise<string> {
|
||||
const dockerConfigPath = path.join(os.homedir(), ".docker", "config.json");
|
||||
return fs.readFile(dockerConfigPath, "utf-8");
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue