fix registry auth string being suffixed with "/owner/repo:", dynamically determine .docker/config.json, renamed targetRegistries to targetRepos to better clarify content (list of "registry/owner/repo:prefix-" and not actual registries)
This commit is contained in:
parent
f92a7c85b3
commit
6c5883876a
@ -6,6 +6,10 @@ inputs:
|
|||||||
description: docker client image to use for building images
|
description: docker client image to use for building images
|
||||||
default: "docker:latest"
|
default: "docker:latest"
|
||||||
|
|
||||||
|
docker_auth_json_file:
|
||||||
|
description: location of the docker auth json file, relative to home dir or absolute path
|
||||||
|
default: ".docker/config.json"
|
||||||
|
|
||||||
docker_args:
|
docker_args:
|
||||||
description: "Extra arguments to pass to docker invocation"
|
description: "Extra arguments to pass to docker invocation"
|
||||||
default: ""
|
default: ""
|
||||||
|
|||||||
37
dist/index.js
vendored
37
dist/index.js
vendored
@ -62097,6 +62097,8 @@ const gBase64 = {
|
|||||||
// and finally,
|
// and finally,
|
||||||
|
|
||||||
|
|
||||||
|
// EXTERNAL MODULE: external "os"
|
||||||
|
var external_os_ = __nccwpck_require__(2037);
|
||||||
// EXTERNAL MODULE: external "path"
|
// EXTERNAL MODULE: external "path"
|
||||||
var external_path_ = __nccwpck_require__(1017);
|
var external_path_ = __nccwpck_require__(1017);
|
||||||
;// CONCATENATED MODULE: ./src/lib.js
|
;// CONCATENATED MODULE: ./src/lib.js
|
||||||
@ -62107,6 +62109,7 @@ var external_path_ = __nccwpck_require__(1017);
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
function processAdditionalRegistries(targetRegistries) {
|
function processAdditionalRegistries(targetRegistries) {
|
||||||
const additionalRegistries = core.getInput('additional_registries');
|
const additionalRegistries = core.getInput('additional_registries');
|
||||||
if (additionalRegistries != null && additionalRegistries.length > 0) {
|
if (additionalRegistries != null && additionalRegistries.length > 0) {
|
||||||
@ -62359,6 +62362,20 @@ function executeDockerBuild(dockerArgs, destinations) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function determineDockerConfigFileLocation(path) {
|
||||||
|
if (path == null || !path.length) {
|
||||||
|
return external_os_.homedir + '/.docker/config.json';
|
||||||
|
}
|
||||||
|
|
||||||
|
// absolute path
|
||||||
|
if (path.startsWith('/')) {
|
||||||
|
return path;
|
||||||
|
}
|
||||||
|
|
||||||
|
// relative path to home dir
|
||||||
|
return external_os_.homedir + '/' + path;
|
||||||
|
}
|
||||||
|
|
||||||
function lib_isTrueString(str) {
|
function lib_isTrueString(str) {
|
||||||
return str === '1'
|
return str === '1'
|
||||||
|| str === 'true'
|
|| str === 'true'
|
||||||
@ -62382,27 +62399,33 @@ try {
|
|||||||
|
|
||||||
const debug = lib_isTrueString(process.env['ACTIONS_STEP_DEBUG']);
|
const debug = lib_isTrueString(process.env['ACTIONS_STEP_DEBUG']);
|
||||||
|
|
||||||
let targetRegistries = [];
|
let targetRepos = [];
|
||||||
const repoStr = github.context.repo.owner + '/' + github.context.repo.repo;
|
const repoStr = github.context.repo.owner + '/' + github.context.repo.repo;
|
||||||
|
|
||||||
let ci_registry = false;
|
let ci_registry = false;
|
||||||
if (core.getBooleanInput('add_ci_registry_target')) {
|
if (core.getBooleanInput('add_ci_registry_target')) {
|
||||||
ci_registry = information.ci_hostname + '/' + repoStr + ':';
|
const ci_registry_repo = information.ci_hostname + '/' + repoStr + ':';
|
||||||
targetRegistries.push(ci_registry);
|
targetRepos.push(ci_registry_repo);
|
||||||
|
}
|
||||||
|
|
||||||
|
processAdditionalRegistries(targetRepos);
|
||||||
|
|
||||||
|
const dockerConfigFile = determineDockerConfigFileLocation(core.getInput('docker_auth_json_file'));
|
||||||
|
if (debug) {
|
||||||
|
console.log('determined .docker/config.json location: ', dockerConfigFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
processAdditionalRegistries(targetRegistries);
|
|
||||||
const registryAuthJson = {auths: {}};
|
const registryAuthJson = {auths: {}};
|
||||||
addCiRegistryAuth(ci_registry, registryAuthJson);
|
addCiRegistryAuth(ci_registry, registryAuthJson);
|
||||||
mergeArgRegistryAuthJson(registryAuthJson);
|
mergeArgRegistryAuthJson(registryAuthJson);
|
||||||
writeRegistryAuthJson(registryAuthJson, '/home/runner/.docker/config.json');
|
writeRegistryAuthJson(registryAuthJson, dockerConfigFile);
|
||||||
|
|
||||||
const tags = collectTags(information);
|
const tags = collectTags(information);
|
||||||
if (debug) {
|
if (debug) {
|
||||||
console.log('tags:', JSON.stringify(tags, null, 2));
|
console.log('tags:', JSON.stringify(tags, null, 2));
|
||||||
}
|
}
|
||||||
|
|
||||||
const destinations = prepareDestinations(targetRegistries, tags);
|
const destinations = prepareDestinations(targetRepos, tags);
|
||||||
if (debug || core.getBooleanInput('debug_log_destinations')) {
|
if (debug || core.getBooleanInput('debug_log_destinations')) {
|
||||||
console.log('destinations:', JSON.stringify(destinations, null, 2));
|
console.log('destinations:', JSON.stringify(destinations, null, 2));
|
||||||
}
|
}
|
||||||
|
|||||||
@ -4,6 +4,7 @@ import * as action_information from 'information';
|
|||||||
import {
|
import {
|
||||||
addCiRegistryAuth,
|
addCiRegistryAuth,
|
||||||
collectTags,
|
collectTags,
|
||||||
|
determineDockerConfigFileLocation,
|
||||||
executeDockerBuild,
|
executeDockerBuild,
|
||||||
isTrueString,
|
isTrueString,
|
||||||
mergeArgRegistryAuthJson,
|
mergeArgRegistryAuthJson,
|
||||||
@ -23,27 +24,33 @@ try {
|
|||||||
|
|
||||||
const debug = isTrueString(process.env['ACTIONS_STEP_DEBUG']);
|
const debug = isTrueString(process.env['ACTIONS_STEP_DEBUG']);
|
||||||
|
|
||||||
let targetRegistries = [];
|
let targetRepos = [];
|
||||||
const repoStr = github.context.repo.owner + '/' + github.context.repo.repo;
|
const repoStr = github.context.repo.owner + '/' + github.context.repo.repo;
|
||||||
|
|
||||||
let ci_registry = false;
|
let ci_registry = false;
|
||||||
if (core.getBooleanInput('add_ci_registry_target')) {
|
if (core.getBooleanInput('add_ci_registry_target')) {
|
||||||
ci_registry = information.ci_hostname + '/' + repoStr + ':';
|
const ci_registry_repo = information.ci_hostname + '/' + repoStr + ':';
|
||||||
targetRegistries.push(ci_registry);
|
targetRepos.push(ci_registry_repo);
|
||||||
|
}
|
||||||
|
|
||||||
|
processAdditionalRegistries(targetRepos);
|
||||||
|
|
||||||
|
const dockerConfigFile = determineDockerConfigFileLocation(core.getInput('docker_auth_json_file'));
|
||||||
|
if (debug) {
|
||||||
|
console.log('determined .docker/config.json location: ', dockerConfigFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
processAdditionalRegistries(targetRegistries);
|
|
||||||
const registryAuthJson = {auths: {}};
|
const registryAuthJson = {auths: {}};
|
||||||
addCiRegistryAuth(ci_registry, registryAuthJson);
|
addCiRegistryAuth(ci_registry, registryAuthJson);
|
||||||
mergeArgRegistryAuthJson(registryAuthJson);
|
mergeArgRegistryAuthJson(registryAuthJson);
|
||||||
writeRegistryAuthJson(registryAuthJson, '/home/runner/.docker/config.json');
|
writeRegistryAuthJson(registryAuthJson, dockerConfigFile);
|
||||||
|
|
||||||
const tags = collectTags(information);
|
const tags = collectTags(information);
|
||||||
if (debug) {
|
if (debug) {
|
||||||
console.log('tags:', JSON.stringify(tags, null, 2));
|
console.log('tags:', JSON.stringify(tags, null, 2));
|
||||||
}
|
}
|
||||||
|
|
||||||
const destinations = prepareDestinations(targetRegistries, tags);
|
const destinations = prepareDestinations(targetRepos, tags);
|
||||||
if (debug || core.getBooleanInput('debug_log_destinations')) {
|
if (debug || core.getBooleanInput('debug_log_destinations')) {
|
||||||
console.log('destinations:', JSON.stringify(destinations, null, 2));
|
console.log('destinations:', JSON.stringify(destinations, null, 2));
|
||||||
}
|
}
|
||||||
|
|||||||
15
src/lib.js
15
src/lib.js
@ -3,6 +3,7 @@ import * as github from '@actions/github';
|
|||||||
import * as child_process from 'child_process';
|
import * as child_process from 'child_process';
|
||||||
import * as fs from 'fs';
|
import * as fs from 'fs';
|
||||||
import {Base64} from 'js-base64';
|
import {Base64} from 'js-base64';
|
||||||
|
import * as os from 'os';
|
||||||
import * as path from 'path';
|
import * as path from 'path';
|
||||||
|
|
||||||
export function processAdditionalRegistries(targetRegistries) {
|
export function processAdditionalRegistries(targetRegistries) {
|
||||||
@ -257,6 +258,20 @@ export function executeDockerBuild(dockerArgs, destinations) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function determineDockerConfigFileLocation(path) {
|
||||||
|
if (path == null || !path.length) {
|
||||||
|
return os.homedir + '/.docker/config.json';
|
||||||
|
}
|
||||||
|
|
||||||
|
// absolute path
|
||||||
|
if (path.startsWith('/')) {
|
||||||
|
return path;
|
||||||
|
}
|
||||||
|
|
||||||
|
// relative path to home dir
|
||||||
|
return os.homedir + '/' + path;
|
||||||
|
}
|
||||||
|
|
||||||
export function isTrueString(str) {
|
export function isTrueString(str) {
|
||||||
return str === '1'
|
return str === '1'
|
||||||
|| str === 'true'
|
|| str === 'true'
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user