@jcoreio/aws-ecr-utils 1.1.0 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/checkECRRepositoryPolicy.d.ts +20 -0
- package/checkECRRepositoryPolicy.js +132 -0
- package/checkECRRepositoryPolicy.mjs +100 -0
- package/copyECRImage.js +79 -104
- package/copyECRImage.js.flow +8 -8
- package/copyECRImage.mjs +67 -0
- package/{es/copyECRImage.js.flow → copyECRImage.mjs.flow} +8 -8
- package/ecrImageExists.js +51 -74
- package/ecrImageExists.mjs +31 -0
- package/index.d.ts +2 -0
- package/index.js +20 -13
- package/index.js.flow +1 -0
- package/index.mjs +8 -0
- package/{es/index.js.flow → index.mjs.flow} +1 -0
- package/loginToECR.js +44 -65
- package/loginToECR.mjs +38 -0
- package/package.json +25 -104
- package/parseECRImageUri.d.ts +3 -2
- package/parseECRImageUri.js +6 -10
- package/parseECRImageUri.mjs +11 -0
- package/parseECRRepositoryHostname.d.ts +6 -0
- package/parseECRRepositoryHostname.js +22 -0
- package/parseECRRepositoryHostname.mjs +10 -0
- package/tagECRImage.js +81 -115
- package/tagECRImage.mjs +50 -0
- package/upsertECRRepository.js +45 -64
- package/upsertECRRepository.mjs +33 -0
- package/es/copyECRImage.d.ts +0 -13
- package/es/copyECRImage.js +0 -76
- package/es/ecrImageExists.d.ts +0 -9
- package/es/ecrImageExists.js +0 -45
- package/es/index.d.ts +0 -6
- package/es/index.js +0 -56
- package/es/loginToECR.d.ts +0 -8
- package/es/loginToECR.js +0 -56
- package/es/parseECRImageUri.d.ts +0 -6
- package/es/parseECRImageUri.js +0 -19
- package/es/tagECRImage.d.ts +0 -10
- package/es/tagECRImage.js +0 -65
- package/es/upsertECRRepository.d.ts +0 -6
- package/es/upsertECRRepository.js +0 -45
- /package/{es/ecrImageExists.js.flow → ecrImageExists.mjs.flow} +0 -0
- /package/{es/loginToECR.js.flow → loginToECR.mjs.flow} +0 -0
- /package/{es/parseECRImageUri.js.flow → parseECRImageUri.mjs.flow} +0 -0
- /package/{es/tagECRImage.js.flow → tagECRImage.mjs.flow} +0 -0
- /package/{es/upsertECRRepository.js.flow → upsertECRRepository.mjs.flow} +0 -0
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import AWS from 'aws-sdk';
|
|
2
|
+
/**
|
|
3
|
+
* Checks if the given ECR repository has a sufficient repository
|
|
4
|
+
* policy to allow the given AWS principal to access docker images.
|
|
5
|
+
*
|
|
6
|
+
* If not, prints a warning, and if the terminal is interactive, asks the user if they
|
|
7
|
+
* would like to add/update the repository policy.
|
|
8
|
+
*/
|
|
9
|
+
export default function checkECRRepositoryPolicy({ ecr, awsConfig, repositoryName, awsPrincipal, Action, log, }: {
|
|
10
|
+
ecr?: AWS.ECR;
|
|
11
|
+
awsConfig?: AWS.ConfigurationOptions;
|
|
12
|
+
repositoryName: string;
|
|
13
|
+
awsPrincipal: string;
|
|
14
|
+
Action?: string[];
|
|
15
|
+
log?: {
|
|
16
|
+
info: (...args: any[]) => void;
|
|
17
|
+
warn: (...args: any[]) => void;
|
|
18
|
+
error: (...args: any[]) => void;
|
|
19
|
+
};
|
|
20
|
+
}): Promise<boolean>;
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports["default"] = checkECRRepositoryPolicy;
|
|
8
|
+
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
|
|
9
|
+
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
10
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
11
|
+
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
|
12
|
+
var _awsSdk = _interopRequireDefault(require("aws-sdk"));
|
|
13
|
+
var _inquirer = _interopRequireDefault(require("inquirer"));
|
|
14
|
+
var _isInteractive = _interopRequireDefault(require("is-interactive"));
|
|
15
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
16
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2["default"])(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
17
|
+
/**
|
|
18
|
+
* Checks if the given ECR repository has a sufficient repository
|
|
19
|
+
* policy to allow the given AWS principal to access docker images.
|
|
20
|
+
*
|
|
21
|
+
* If not, prints a warning, and if the terminal is interactive, asks the user if they
|
|
22
|
+
* would like to add/update the repository policy.
|
|
23
|
+
*/
|
|
24
|
+
function checkECRRepositoryPolicy(_x) {
|
|
25
|
+
return _checkECRRepositoryPolicy.apply(this, arguments);
|
|
26
|
+
}
|
|
27
|
+
function _checkECRRepositoryPolicy() {
|
|
28
|
+
_checkECRRepositoryPolicy = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee(_ref) {
|
|
29
|
+
var _policy$Statement, _statementForAction$P;
|
|
30
|
+
var ecr, awsConfig, repositoryName, awsPrincipal, _ref$Action, Action, _ref$log, log, rootUserMatch, principalAliases, _yield$ecr$getReposit, policyText, policy, statementForAction, statementPrincipal, _yield$inquirer$promp, update, _statementForAction$A, finalPolicy;
|
|
31
|
+
return _regenerator["default"].wrap(function _callee$(_context) {
|
|
32
|
+
while (1) switch (_context.prev = _context.next) {
|
|
33
|
+
case 0:
|
|
34
|
+
ecr = _ref.ecr, awsConfig = _ref.awsConfig, repositoryName = _ref.repositoryName, awsPrincipal = _ref.awsPrincipal, _ref$Action = _ref.Action, Action = _ref$Action === void 0 ? ['ecr:GetDownloadUrlForLayer', 'ecr:BatchCheckLayerAvailability', 'ecr:BatchGetImage'] : _ref$Action, _ref$log = _ref.log, log = _ref$log === void 0 ? console : _ref$log;
|
|
35
|
+
rootUserMatch = /^arn:aws:iam::(\d+):root$/.exec(awsPrincipal);
|
|
36
|
+
if (rootUserMatch) awsPrincipal = rootUserMatch[1];
|
|
37
|
+
principalAliases = /^(\d+)$/.test(awsPrincipal) ? [awsPrincipal, "arn:aws:iam::".concat(awsPrincipal, ":root")] : [awsPrincipal];
|
|
38
|
+
if (!ecr) ecr = new _awsSdk["default"].ECR(awsConfig);
|
|
39
|
+
_context.next = 7;
|
|
40
|
+
return ecr.getRepositoryPolicy({
|
|
41
|
+
repositoryName: repositoryName
|
|
42
|
+
}).promise()["catch"](function (error) {
|
|
43
|
+
if (error.name === 'RepositoryPolicyNotFoundException') return {};
|
|
44
|
+
throw error;
|
|
45
|
+
});
|
|
46
|
+
case 7:
|
|
47
|
+
_yield$ecr$getReposit = _context.sent;
|
|
48
|
+
policyText = _yield$ecr$getReposit.policyText;
|
|
49
|
+
policy = JSON.parse(policyText || '{}');
|
|
50
|
+
statementForAction = (_policy$Statement = policy.Statement) === null || _policy$Statement === void 0 ? void 0 : _policy$Statement.find(function (s) {
|
|
51
|
+
return s.Effect === 'Allow' && Array.isArray(Action) && Action.every(function (a) {
|
|
52
|
+
var _s$Action;
|
|
53
|
+
return (_s$Action = s.Action) === null || _s$Action === void 0 ? void 0 : _s$Action.includes(a);
|
|
54
|
+
});
|
|
55
|
+
});
|
|
56
|
+
statementPrincipal = statementForAction === null || statementForAction === void 0 || (_statementForAction$P = statementForAction.Principal) === null || _statementForAction$P === void 0 ? void 0 : _statementForAction$P.AWS;
|
|
57
|
+
if (!(statementPrincipal && typeof statementPrincipal === 'string' && principalAliases.includes(statementPrincipal) || Array.isArray(statementPrincipal) && statementPrincipal.some(function (s) {
|
|
58
|
+
return principalAliases.includes(s);
|
|
59
|
+
}))) {
|
|
60
|
+
_context.next = 15;
|
|
61
|
+
break;
|
|
62
|
+
}
|
|
63
|
+
// eslint-disable-next-line no-console
|
|
64
|
+
log.info("Found policy on ECR repository ".concat(repositoryName, " to allow access for AWS Principal ").concat(awsPrincipal, "."));
|
|
65
|
+
return _context.abrupt("return", true);
|
|
66
|
+
case 15:
|
|
67
|
+
// eslint-disable-next-line no-console
|
|
68
|
+
console.warn("Missing policy on ECR repository ".concat(repositoryName, " to allow access for AWS Principal ").concat(awsPrincipal, ".\n\nThe policy should include:\n\n ").concat(JSON.stringify({
|
|
69
|
+
Version: '2012-10-17',
|
|
70
|
+
Statement: [{
|
|
71
|
+
Effect: 'Allow',
|
|
72
|
+
Principal: {
|
|
73
|
+
AWS: [awsPrincipal]
|
|
74
|
+
},
|
|
75
|
+
Action: Action
|
|
76
|
+
}]
|
|
77
|
+
}, null, 2).replace(/\n/gm, '\n '), "\n"));
|
|
78
|
+
if (!(0, _isInteractive["default"])()) {
|
|
79
|
+
_context.next = 28;
|
|
80
|
+
break;
|
|
81
|
+
}
|
|
82
|
+
_context.next = 19;
|
|
83
|
+
return _inquirer["default"].prompt([{
|
|
84
|
+
name: 'update',
|
|
85
|
+
message: 'Do you want to add/update the policy?',
|
|
86
|
+
type: 'confirm',
|
|
87
|
+
"default": false
|
|
88
|
+
}]);
|
|
89
|
+
case 19:
|
|
90
|
+
_yield$inquirer$promp = _context.sent;
|
|
91
|
+
update = _yield$inquirer$promp.update;
|
|
92
|
+
if (!update) {
|
|
93
|
+
_context.next = 28;
|
|
94
|
+
break;
|
|
95
|
+
}
|
|
96
|
+
finalPolicy = policy;
|
|
97
|
+
if ((statementForAction === null || statementForAction === void 0 || (_statementForAction$A = statementForAction.Action) === null || _statementForAction$A === void 0 ? void 0 : _statementForAction$A.length) === Action.length) {
|
|
98
|
+
statementForAction.Principal = _objectSpread(_objectSpread({}, statementForAction.Principal), {}, {
|
|
99
|
+
AWS: [].concat((0, _toConsumableArray2["default"])(typeof statementPrincipal === 'string' ? [statementPrincipal] : Array.isArray(statementPrincipal) ? statementPrincipal : []), [awsPrincipal])
|
|
100
|
+
});
|
|
101
|
+
} else {
|
|
102
|
+
finalPolicy = _objectSpread(_objectSpread({
|
|
103
|
+
Version: '2012-10-17'
|
|
104
|
+
}, policy), {}, {
|
|
105
|
+
Statement: [].concat((0, _toConsumableArray2["default"])(policy.Statement || []), [{
|
|
106
|
+
Effect: 'Allow',
|
|
107
|
+
Principal: {
|
|
108
|
+
AWS: [awsPrincipal]
|
|
109
|
+
},
|
|
110
|
+
Action: Action
|
|
111
|
+
}])
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
_context.next = 26;
|
|
115
|
+
return ecr.setRepositoryPolicy({
|
|
116
|
+
repositoryName: repositoryName,
|
|
117
|
+
policyText: JSON.stringify(finalPolicy, null, 2)
|
|
118
|
+
}).promise();
|
|
119
|
+
case 26:
|
|
120
|
+
log.info("updated policy on ECR repository ".concat(repositoryName));
|
|
121
|
+
return _context.abrupt("return", true);
|
|
122
|
+
case 28:
|
|
123
|
+
return _context.abrupt("return", false);
|
|
124
|
+
case 29:
|
|
125
|
+
case "end":
|
|
126
|
+
return _context.stop();
|
|
127
|
+
}
|
|
128
|
+
}, _callee);
|
|
129
|
+
}));
|
|
130
|
+
return _checkECRRepositoryPolicy.apply(this, arguments);
|
|
131
|
+
}
|
|
132
|
+
module.exports = exports.default;
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import AWS from 'aws-sdk';
|
|
2
|
+
import inquirer from 'inquirer';
|
|
3
|
+
import isInteractive from 'is-interactive';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Checks if the given ECR repository has a sufficient repository
|
|
7
|
+
* policy to allow the given AWS principal to access docker images.
|
|
8
|
+
*
|
|
9
|
+
* If not, prints a warning, and if the terminal is interactive, asks the user if they
|
|
10
|
+
* would like to add/update the repository policy.
|
|
11
|
+
*/
|
|
12
|
+
export default async function checkECRRepositoryPolicy({
|
|
13
|
+
ecr,
|
|
14
|
+
awsConfig,
|
|
15
|
+
repositoryName,
|
|
16
|
+
awsPrincipal,
|
|
17
|
+
Action = ['ecr:GetDownloadUrlForLayer', 'ecr:BatchCheckLayerAvailability', 'ecr:BatchGetImage'],
|
|
18
|
+
log = console
|
|
19
|
+
}) {
|
|
20
|
+
var _policy$Statement, _statementForAction$P;
|
|
21
|
+
const rootUserMatch = /^arn:aws:iam::(\d+):root$/.exec(awsPrincipal);
|
|
22
|
+
if (rootUserMatch) awsPrincipal = rootUserMatch[1];
|
|
23
|
+
const principalAliases = /^(\d+)$/.test(awsPrincipal) ? [awsPrincipal, `arn:aws:iam::${awsPrincipal}:root`] : [awsPrincipal];
|
|
24
|
+
if (!ecr) ecr = new AWS.ECR(awsConfig);
|
|
25
|
+
const {
|
|
26
|
+
policyText
|
|
27
|
+
} = await ecr.getRepositoryPolicy({
|
|
28
|
+
repositoryName
|
|
29
|
+
}).promise().catch(error => {
|
|
30
|
+
if (error.name === 'RepositoryPolicyNotFoundException') return {};
|
|
31
|
+
throw error;
|
|
32
|
+
});
|
|
33
|
+
const policy = JSON.parse(policyText || '{}');
|
|
34
|
+
const statementForAction = (_policy$Statement = policy.Statement) === null || _policy$Statement === void 0 ? void 0 : _policy$Statement.find(s => s.Effect === 'Allow' && Array.isArray(Action) && Action.every(a => {
|
|
35
|
+
var _s$Action;
|
|
36
|
+
return (_s$Action = s.Action) === null || _s$Action === void 0 ? void 0 : _s$Action.includes(a);
|
|
37
|
+
}));
|
|
38
|
+
const statementPrincipal = statementForAction === null || statementForAction === void 0 || (_statementForAction$P = statementForAction.Principal) === null || _statementForAction$P === void 0 ? void 0 : _statementForAction$P.AWS;
|
|
39
|
+
if (statementPrincipal && typeof statementPrincipal === 'string' && principalAliases.includes(statementPrincipal) || Array.isArray(statementPrincipal) && statementPrincipal.some(s => principalAliases.includes(s))) {
|
|
40
|
+
// eslint-disable-next-line no-console
|
|
41
|
+
log.info(`Found policy on ECR repository ${repositoryName} to allow access for AWS Principal ${awsPrincipal}.`);
|
|
42
|
+
return true;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// eslint-disable-next-line no-console
|
|
46
|
+
console.warn(`Missing policy on ECR repository ${repositoryName} to allow access for AWS Principal ${awsPrincipal}.
|
|
47
|
+
|
|
48
|
+
The policy should include:
|
|
49
|
+
|
|
50
|
+
${JSON.stringify({
|
|
51
|
+
Version: '2012-10-17',
|
|
52
|
+
Statement: [{
|
|
53
|
+
Effect: 'Allow',
|
|
54
|
+
Principal: {
|
|
55
|
+
AWS: [awsPrincipal]
|
|
56
|
+
},
|
|
57
|
+
Action
|
|
58
|
+
}]
|
|
59
|
+
}, null, 2).replace(/\n/gm, '\n ')}
|
|
60
|
+
`);
|
|
61
|
+
if (isInteractive()) {
|
|
62
|
+
const {
|
|
63
|
+
update
|
|
64
|
+
} = await inquirer.prompt([{
|
|
65
|
+
name: 'update',
|
|
66
|
+
message: 'Do you want to add/update the policy?',
|
|
67
|
+
type: 'confirm',
|
|
68
|
+
default: false
|
|
69
|
+
}]);
|
|
70
|
+
if (update) {
|
|
71
|
+
var _statementForAction$A;
|
|
72
|
+
let finalPolicy = policy;
|
|
73
|
+
if ((statementForAction === null || statementForAction === void 0 || (_statementForAction$A = statementForAction.Action) === null || _statementForAction$A === void 0 ? void 0 : _statementForAction$A.length) === Action.length) {
|
|
74
|
+
statementForAction.Principal = {
|
|
75
|
+
...statementForAction.Principal,
|
|
76
|
+
AWS: [...(typeof statementPrincipal === 'string' ? [statementPrincipal] : Array.isArray(statementPrincipal) ? statementPrincipal : []), awsPrincipal]
|
|
77
|
+
};
|
|
78
|
+
} else {
|
|
79
|
+
finalPolicy = {
|
|
80
|
+
Version: '2012-10-17',
|
|
81
|
+
...policy,
|
|
82
|
+
Statement: [...(policy.Statement || []), {
|
|
83
|
+
Effect: 'Allow',
|
|
84
|
+
Principal: {
|
|
85
|
+
AWS: [awsPrincipal]
|
|
86
|
+
},
|
|
87
|
+
Action
|
|
88
|
+
}]
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
await ecr.setRepositoryPolicy({
|
|
92
|
+
repositoryName,
|
|
93
|
+
policyText: JSON.stringify(finalPolicy, null, 2)
|
|
94
|
+
}).promise();
|
|
95
|
+
log.info(`updated policy on ECR repository ${repositoryName}`);
|
|
96
|
+
return true;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
return false;
|
|
100
|
+
}
|
package/copyECRImage.js
CHANGED
|
@@ -1,127 +1,102 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
|
6
5
|
value: true
|
|
7
6
|
});
|
|
8
7
|
exports["default"] = copyECRImage;
|
|
9
|
-
|
|
10
8
|
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
|
|
11
|
-
|
|
12
9
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
13
|
-
|
|
14
10
|
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
|
15
|
-
|
|
16
11
|
var _promisifyChildProcess = require("promisify-child-process");
|
|
17
|
-
|
|
18
|
-
var
|
|
19
|
-
|
|
20
|
-
var
|
|
21
|
-
|
|
22
|
-
var _parseECRImageUri3 = _interopRequireDefault(require("./parseECRImageUri"));
|
|
23
|
-
|
|
24
|
-
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
|
|
25
|
-
|
|
26
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { (0, _defineProperty2["default"])(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
|
27
|
-
|
|
12
|
+
var _loginToECR = _interopRequireDefault(require("./loginToECR.js"));
|
|
13
|
+
var _ecrImageExists = _interopRequireDefault(require("./ecrImageExists.js"));
|
|
14
|
+
var _parseECRImageUri3 = _interopRequireDefault(require("./parseECRImageUri.js"));
|
|
15
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
16
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2["default"])(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
28
17
|
function copyECRImage(_x) {
|
|
29
18
|
return _copyECRImage.apply(this, arguments);
|
|
30
19
|
}
|
|
31
|
-
|
|
32
20
|
function _copyECRImage() {
|
|
33
21
|
_copyECRImage = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee(_ref) {
|
|
34
22
|
var from, to, srcRepositoryUri, repositoryUri, _parseECRImageUri, fromRegion, _parseECRImageUri2, toRegion, repositoryName, imageTag;
|
|
35
|
-
|
|
36
23
|
return _regenerator["default"].wrap(function _callee$(_context) {
|
|
37
|
-
while (1) {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
if (!(from.imageUri === to.imageUri)) {
|
|
43
|
-
_context.next = 3;
|
|
44
|
-
break;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
return _context.abrupt("return");
|
|
48
|
-
|
|
49
|
-
case 3:
|
|
50
|
-
srcRepositoryUri = from.imageUri.replace(/:.+/, '');
|
|
51
|
-
repositoryUri = to.imageUri.replace(/:.+/, '');
|
|
52
|
-
_parseECRImageUri = (0, _parseECRImageUri3["default"])(from.imageUri), fromRegion = _parseECRImageUri.region;
|
|
53
|
-
_parseECRImageUri2 = (0, _parseECRImageUri3["default"])(to.imageUri), toRegion = _parseECRImageUri2.region, repositoryName = _parseECRImageUri2.repositoryName, imageTag = _parseECRImageUri2.imageTag;
|
|
54
|
-
_context.next = 9;
|
|
55
|
-
return (0, _ecrImageExists["default"])({
|
|
56
|
-
awsConfig: _objectSpread(_objectSpread({}, to.awsConfig), {}, {
|
|
57
|
-
region: toRegion
|
|
58
|
-
}),
|
|
59
|
-
ecr: to.ecr,
|
|
60
|
-
repositoryName: repositoryName,
|
|
61
|
-
imageTag: imageTag
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
case 9:
|
|
65
|
-
if (!_context.sent) {
|
|
66
|
-
_context.next = 13;
|
|
67
|
-
break;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
// eslint-disable-next-line no-console
|
|
71
|
-
console.error("Clarity image already exists in your ECR: ".concat(repositoryName, ":").concat(imageTag));
|
|
72
|
-
_context.next = 27;
|
|
24
|
+
while (1) switch (_context.prev = _context.next) {
|
|
25
|
+
case 0:
|
|
26
|
+
from = _ref.from, to = _ref.to;
|
|
27
|
+
if (!(from.imageUri === to.imageUri)) {
|
|
28
|
+
_context.next = 3;
|
|
73
29
|
break;
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
30
|
+
}
|
|
31
|
+
return _context.abrupt("return");
|
|
32
|
+
case 3:
|
|
33
|
+
srcRepositoryUri = from.imageUri.replace(/:.+/, '');
|
|
34
|
+
repositoryUri = to.imageUri.replace(/:.+/, '');
|
|
35
|
+
_parseECRImageUri = (0, _parseECRImageUri3["default"])(from.imageUri), fromRegion = _parseECRImageUri.region;
|
|
36
|
+
_parseECRImageUri2 = (0, _parseECRImageUri3["default"])(to.imageUri), toRegion = _parseECRImageUri2.region, repositoryName = _parseECRImageUri2.repositoryName, imageTag = _parseECRImageUri2.imageTag;
|
|
37
|
+
_context.next = 9;
|
|
38
|
+
return (0, _ecrImageExists["default"])({
|
|
39
|
+
awsConfig: _objectSpread(_objectSpread({}, to.awsConfig), {}, {
|
|
40
|
+
region: toRegion
|
|
41
|
+
}),
|
|
42
|
+
ecr: to.ecr,
|
|
43
|
+
repositoryName: repositoryName,
|
|
44
|
+
imageTag: imageTag
|
|
45
|
+
});
|
|
46
|
+
case 9:
|
|
47
|
+
if (!_context.sent) {
|
|
48
|
+
_context.next = 13;
|
|
49
|
+
break;
|
|
50
|
+
}
|
|
51
|
+
// eslint-disable-next-line no-console
|
|
52
|
+
console.error("Clarity image already exists in your ECR: ".concat(repositoryName, ":").concat(imageTag));
|
|
53
|
+
_context.next = 27;
|
|
54
|
+
break;
|
|
55
|
+
case 13:
|
|
56
|
+
// eslint-disable-next-line no-console
|
|
57
|
+
console.error("Logging into source ECR: ".concat(srcRepositoryUri.replace(/\/.*/, ''), "..."));
|
|
58
|
+
_context.next = 16;
|
|
59
|
+
return (0, _loginToECR["default"])({
|
|
60
|
+
ecr: from.ecr,
|
|
61
|
+
awsConfig: _objectSpread(_objectSpread({}, from.awsConfig), {}, {
|
|
62
|
+
region: fromRegion
|
|
63
|
+
})
|
|
64
|
+
});
|
|
65
|
+
case 16:
|
|
66
|
+
// eslint-disable-next-line no-console
|
|
67
|
+
console.error("Pulling ".concat(from.imageUri, "..."));
|
|
68
|
+
_context.next = 19;
|
|
69
|
+
return (0, _promisifyChildProcess.spawn)('docker', ['pull', from.imageUri], {
|
|
70
|
+
stdio: 'inherit'
|
|
71
|
+
});
|
|
72
|
+
case 19:
|
|
73
|
+
// eslint-disable-next-line no-console
|
|
74
|
+
console.error("Logging into dest ECR: ".concat(repositoryUri.replace(/\/.*/, ''), "..."));
|
|
75
|
+
_context.next = 22;
|
|
76
|
+
return (0, _loginToECR["default"])({
|
|
77
|
+
ecr: to.ecr,
|
|
78
|
+
awsConfig: _objectSpread(_objectSpread({}, to.awsConfig), {}, {
|
|
79
|
+
region: toRegion
|
|
80
|
+
})
|
|
81
|
+
});
|
|
82
|
+
case 22:
|
|
83
|
+
// eslint-disable-next-line no-console
|
|
84
|
+
console.error("Pushing ".concat(to.imageUri, "..."));
|
|
85
|
+
_context.next = 25;
|
|
86
|
+
return (0, _promisifyChildProcess.spawn)('docker', ['tag', from.imageUri, to.imageUri], {
|
|
87
|
+
stdio: 'inherit'
|
|
88
|
+
});
|
|
89
|
+
case 25:
|
|
90
|
+
_context.next = 27;
|
|
91
|
+
return (0, _promisifyChildProcess.spawn)('docker', ['push', to.imageUri], {
|
|
92
|
+
stdio: 'inherit'
|
|
93
|
+
});
|
|
94
|
+
case 27:
|
|
95
|
+
case "end":
|
|
96
|
+
return _context.stop();
|
|
123
97
|
}
|
|
124
98
|
}, _callee);
|
|
125
99
|
}));
|
|
126
100
|
return _copyECRImage.apply(this, arguments);
|
|
127
|
-
}
|
|
101
|
+
}
|
|
102
|
+
module.exports = exports.default;
|
package/copyECRImage.js.flow
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
// @flow
|
|
2
2
|
|
|
3
3
|
declare export default function copyECRImage(options: {|
|
|
4
|
-
from: {
|
|
4
|
+
from: {|
|
|
5
5
|
imageUri: string,
|
|
6
|
-
ecr
|
|
7
|
-
awsConfig
|
|
8
|
-
},
|
|
9
|
-
to: {
|
|
6
|
+
ecr?: any,
|
|
7
|
+
awsConfig?: { ... },
|
|
8
|
+
|},
|
|
9
|
+
to: {|
|
|
10
10
|
imageUri: string,
|
|
11
|
-
ecr
|
|
12
|
-
awsConfig
|
|
13
|
-
},
|
|
11
|
+
ecr?: any,
|
|
12
|
+
awsConfig?: { ... },
|
|
13
|
+
|},
|
|
14
14
|
|}): Promise<void>
|
package/copyECRImage.mjs
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { spawn } from 'promisify-child-process';
|
|
2
|
+
import loginToECR from "./loginToECR.mjs";
|
|
3
|
+
import ecrImageExists from "./ecrImageExists.mjs";
|
|
4
|
+
import parseECRImageUri from "./parseECRImageUri.mjs";
|
|
5
|
+
export default async function copyECRImage({
|
|
6
|
+
from,
|
|
7
|
+
to
|
|
8
|
+
}) {
|
|
9
|
+
if (from.imageUri === to.imageUri) return;
|
|
10
|
+
const srcRepositoryUri = from.imageUri.replace(/:.+/, '');
|
|
11
|
+
const repositoryUri = to.imageUri.replace(/:.+/, '');
|
|
12
|
+
const {
|
|
13
|
+
region: fromRegion
|
|
14
|
+
} = parseECRImageUri(from.imageUri);
|
|
15
|
+
const {
|
|
16
|
+
region: toRegion,
|
|
17
|
+
repositoryName,
|
|
18
|
+
imageTag
|
|
19
|
+
} = parseECRImageUri(to.imageUri);
|
|
20
|
+
if (await ecrImageExists({
|
|
21
|
+
awsConfig: {
|
|
22
|
+
...to.awsConfig,
|
|
23
|
+
region: toRegion
|
|
24
|
+
},
|
|
25
|
+
ecr: to.ecr,
|
|
26
|
+
repositoryName,
|
|
27
|
+
imageTag
|
|
28
|
+
})) {
|
|
29
|
+
// eslint-disable-next-line no-console
|
|
30
|
+
console.error(`Clarity image already exists in your ECR: ${repositoryName}:${imageTag}`);
|
|
31
|
+
} else {
|
|
32
|
+
// eslint-disable-next-line no-console
|
|
33
|
+
console.error(`Logging into source ECR: ${srcRepositoryUri.replace(/\/.*/, '')}...`);
|
|
34
|
+
await loginToECR({
|
|
35
|
+
ecr: from.ecr,
|
|
36
|
+
awsConfig: {
|
|
37
|
+
...from.awsConfig,
|
|
38
|
+
region: fromRegion
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
// eslint-disable-next-line no-console
|
|
43
|
+
console.error(`Pulling ${from.imageUri}...`);
|
|
44
|
+
await spawn('docker', ['pull', from.imageUri], {
|
|
45
|
+
stdio: 'inherit'
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
// eslint-disable-next-line no-console
|
|
49
|
+
console.error(`Logging into dest ECR: ${repositoryUri.replace(/\/.*/, '')}...`);
|
|
50
|
+
await loginToECR({
|
|
51
|
+
ecr: to.ecr,
|
|
52
|
+
awsConfig: {
|
|
53
|
+
...to.awsConfig,
|
|
54
|
+
region: toRegion
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
// eslint-disable-next-line no-console
|
|
59
|
+
console.error(`Pushing ${to.imageUri}...`);
|
|
60
|
+
await spawn('docker', ['tag', from.imageUri, to.imageUri], {
|
|
61
|
+
stdio: 'inherit'
|
|
62
|
+
});
|
|
63
|
+
await spawn('docker', ['push', to.imageUri], {
|
|
64
|
+
stdio: 'inherit'
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
}
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
// @flow
|
|
2
2
|
|
|
3
3
|
declare export default function copyECRImage(options: {|
|
|
4
|
-
from: {
|
|
4
|
+
from: {|
|
|
5
5
|
imageUri: string,
|
|
6
|
-
ecr
|
|
7
|
-
awsConfig
|
|
8
|
-
},
|
|
9
|
-
to: {
|
|
6
|
+
ecr?: any,
|
|
7
|
+
awsConfig?: { ... },
|
|
8
|
+
|},
|
|
9
|
+
to: {|
|
|
10
10
|
imageUri: string,
|
|
11
|
-
ecr
|
|
12
|
-
awsConfig
|
|
13
|
-
},
|
|
11
|
+
ecr?: any,
|
|
12
|
+
awsConfig?: { ... },
|
|
13
|
+
|},
|
|
14
14
|
|}): Promise<void>
|