@jcoreio/aws-ecr-utils 1.1.1 → 1.3.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.
Files changed (56) hide show
  1. package/ImageManifestSchema.d.ts +58 -0
  2. package/ImageManifestSchema.js +22 -0
  3. package/ImageManifestSchema.mjs +15 -0
  4. package/checkECRImageAccess.d.ts +18 -0
  5. package/checkECRImageAccess.js +180 -0
  6. package/checkECRImageAccess.mjs +133 -0
  7. package/checkECRRepositoryPolicy.d.ts +20 -0
  8. package/checkECRRepositoryPolicy.js +132 -0
  9. package/checkECRRepositoryPolicy.mjs +100 -0
  10. package/copyECRImage.js +79 -104
  11. package/copyECRImage.mjs +67 -0
  12. package/ecrImageExists.js +51 -74
  13. package/ecrImageExists.mjs +31 -0
  14. package/formatECRImageUri.d.ts +6 -0
  15. package/formatECRImageUri.js +20 -0
  16. package/formatECRImageUri.mjs +13 -0
  17. package/formatECRRepositoryHostname.d.ts +5 -0
  18. package/formatECRRepositoryHostname.js +13 -0
  19. package/formatECRRepositoryHostname.mjs +7 -0
  20. package/index.d.ts +5 -0
  21. package/index.js +41 -13
  22. package/index.mjs +11 -0
  23. package/loginToECR.js +44 -65
  24. package/loginToECR.mjs +38 -0
  25. package/package.json +27 -105
  26. package/parseECRImageUri.d.ts +3 -2
  27. package/parseECRImageUri.js +6 -10
  28. package/parseECRImageUri.mjs +11 -0
  29. package/parseECRRepositoryHostname.d.ts +6 -0
  30. package/parseECRRepositoryHostname.js +22 -0
  31. package/parseECRRepositoryHostname.mjs +10 -0
  32. package/tagECRImage.js +81 -115
  33. package/tagECRImage.mjs +50 -0
  34. package/upsertECRRepository.js +45 -64
  35. package/upsertECRRepository.mjs +33 -0
  36. package/es/copyECRImage.d.ts +0 -13
  37. package/es/copyECRImage.js +0 -76
  38. package/es/ecrImageExists.d.ts +0 -9
  39. package/es/ecrImageExists.js +0 -45
  40. package/es/index.d.ts +0 -6
  41. package/es/index.js +0 -56
  42. package/es/loginToECR.d.ts +0 -8
  43. package/es/loginToECR.js +0 -56
  44. package/es/parseECRImageUri.d.ts +0 -6
  45. package/es/parseECRImageUri.js +0 -19
  46. package/es/tagECRImage.d.ts +0 -10
  47. package/es/tagECRImage.js +0 -65
  48. package/es/upsertECRRepository.d.ts +0 -6
  49. package/es/upsertECRRepository.js +0 -45
  50. /package/{es/copyECRImage.js.flow → copyECRImage.mjs.flow} +0 -0
  51. /package/{es/ecrImageExists.js.flow → ecrImageExists.mjs.flow} +0 -0
  52. /package/{es/index.js.flow → index.mjs.flow} +0 -0
  53. /package/{es/loginToECR.js.flow → loginToECR.mjs.flow} +0 -0
  54. /package/{es/parseECRImageUri.js.flow → parseECRImageUri.mjs.flow} +0 -0
  55. /package/{es/tagECRImage.js.flow → tagECRImage.mjs.flow} +0 -0
  56. /package/{es/upsertECRRepository.js.flow → upsertECRRepository.mjs.flow} +0 -0
package/loginToECR.js CHANGED
@@ -1,92 +1,71 @@
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"] = loginToECR;
9
-
10
8
  var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
11
-
12
9
  var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
13
-
14
10
  var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
15
-
16
11
  var _awsSdk = _interopRequireDefault(require("aws-sdk"));
17
-
18
12
  var _promisifyChildProcess = require("promisify-child-process");
19
-
20
13
  var _base64Js = _interopRequireDefault(require("base64-js"));
21
-
22
14
  /**
23
15
  * @prettier
24
16
  */
25
17
  function loginToECR(_x) {
26
18
  return _loginToECR.apply(this, arguments);
27
19
  }
28
-
29
20
  function _loginToECR() {
30
21
  _loginToECR = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee(_ref) {
31
22
  var ecr, awsConfig, _yield$ecr$getAuthori, authorizationData, _ref2, authorizationToken, proxyEndpoint, decoded, _decoded$split, _decoded$split2, user, password, child;
32
-
33
23
  return _regenerator["default"].wrap(function _callee$(_context) {
34
- while (1) {
35
- switch (_context.prev = _context.next) {
36
- case 0:
37
- ecr = _ref.ecr, awsConfig = _ref.awsConfig;
38
- if (!ecr) ecr = new _awsSdk["default"].ECR(awsConfig);
39
- _context.next = 4;
40
- return ecr.getAuthorizationToken().promise();
41
-
42
- case 4:
43
- _yield$ecr$getAuthori = _context.sent;
44
- authorizationData = _yield$ecr$getAuthori.authorizationData;
45
- _ref2 = (authorizationData === null || authorizationData === void 0 ? void 0 : authorizationData[0]) || {}, authorizationToken = _ref2.authorizationToken, proxyEndpoint = _ref2.proxyEndpoint;
46
-
47
- if (authorizationToken) {
48
- _context.next = 9;
49
- break;
50
- }
51
-
52
- throw new Error('failed to get authorizationToken from ECR');
53
-
54
- case 9:
55
- if (proxyEndpoint) {
56
- _context.next = 11;
57
- break;
58
- }
59
-
60
- throw new Error('failed to get proxyEndpoint from ECR');
61
-
62
- case 11:
63
- // this is silly...
64
- decoded = new Buffer(_base64Js["default"].toByteArray(authorizationToken)).toString('utf8');
65
- _decoded$split = decoded.split(/:/), _decoded$split2 = (0, _slicedToArray2["default"])(_decoded$split, 2), user = _decoded$split2[0], password = _decoded$split2[1];
66
- child = (0, _promisifyChildProcess.spawn)('docker', ['login', '-u', user, '--password-stdin', proxyEndpoint], {
67
- stdio: 'pipe',
68
- encoding: 'utf8'
69
- });
70
-
71
- if (child.stdin) {
72
- _context.next = 16;
73
- break;
74
- }
75
-
76
- throw new Error('expected child.stdin to be defined');
77
-
78
- case 16:
79
- child.stdin.write(password);
80
- child.stdin.end();
81
- _context.next = 20;
82
- return child;
83
-
84
- case 20:
85
- case "end":
86
- return _context.stop();
87
- }
24
+ while (1) switch (_context.prev = _context.next) {
25
+ case 0:
26
+ ecr = _ref.ecr, awsConfig = _ref.awsConfig;
27
+ if (!ecr) ecr = new _awsSdk["default"].ECR(awsConfig);
28
+ _context.next = 4;
29
+ return ecr.getAuthorizationToken().promise();
30
+ case 4:
31
+ _yield$ecr$getAuthori = _context.sent;
32
+ authorizationData = _yield$ecr$getAuthori.authorizationData;
33
+ _ref2 = (authorizationData === null || authorizationData === void 0 ? void 0 : authorizationData[0]) || {}, authorizationToken = _ref2.authorizationToken, proxyEndpoint = _ref2.proxyEndpoint;
34
+ if (authorizationToken) {
35
+ _context.next = 9;
36
+ break;
37
+ }
38
+ throw new Error('failed to get authorizationToken from ECR');
39
+ case 9:
40
+ if (proxyEndpoint) {
41
+ _context.next = 11;
42
+ break;
43
+ }
44
+ throw new Error('failed to get proxyEndpoint from ECR');
45
+ case 11:
46
+ // this is silly...
47
+ decoded = new Buffer(_base64Js["default"].toByteArray(authorizationToken)).toString('utf8');
48
+ _decoded$split = decoded.split(/:/), _decoded$split2 = (0, _slicedToArray2["default"])(_decoded$split, 2), user = _decoded$split2[0], password = _decoded$split2[1];
49
+ child = (0, _promisifyChildProcess.spawn)('docker', ['login', '-u', user, '--password-stdin', proxyEndpoint], {
50
+ stdio: 'pipe',
51
+ encoding: 'utf8'
52
+ });
53
+ if (child.stdin) {
54
+ _context.next = 16;
55
+ break;
56
+ }
57
+ throw new Error('expected child.stdin to be defined');
58
+ case 16:
59
+ child.stdin.write(password);
60
+ child.stdin.end();
61
+ _context.next = 20;
62
+ return child;
63
+ case 20:
64
+ case "end":
65
+ return _context.stop();
88
66
  }
89
67
  }, _callee);
90
68
  }));
91
69
  return _loginToECR.apply(this, arguments);
92
- }
70
+ }
71
+ module.exports = exports.default;
package/loginToECR.mjs ADDED
@@ -0,0 +1,38 @@
1
+ /**
2
+ * @prettier
3
+ */
4
+ import AWS from 'aws-sdk';
5
+ import { spawn } from 'promisify-child-process';
6
+ import base64 from 'base64-js';
7
+ export default async function loginToECR({
8
+ ecr,
9
+ awsConfig
10
+ }) {
11
+ if (!ecr) ecr = new AWS.ECR(awsConfig);
12
+ const {
13
+ authorizationData
14
+ } = await ecr.getAuthorizationToken().promise();
15
+ const {
16
+ authorizationToken,
17
+ proxyEndpoint
18
+ } = (authorizationData === null || authorizationData === void 0 ? void 0 : authorizationData[0]) || {};
19
+ if (!authorizationToken) {
20
+ throw new Error('failed to get authorizationToken from ECR');
21
+ }
22
+ if (!proxyEndpoint) {
23
+ throw new Error('failed to get proxyEndpoint from ECR');
24
+ }
25
+ // this is silly...
26
+ const decoded = new Buffer(base64.toByteArray(authorizationToken)).toString('utf8');
27
+ const [user, password] = decoded.split(/:/);
28
+ const child = spawn('docker', ['login', '-u', user, '--password-stdin', proxyEndpoint], {
29
+ stdio: 'pipe',
30
+ encoding: 'utf8'
31
+ });
32
+ if (!child.stdin) {
33
+ throw new Error('expected child.stdin to be defined');
34
+ }
35
+ child.stdin.write(password);
36
+ child.stdin.end();
37
+ await child;
38
+ }
package/package.json CHANGED
@@ -1,71 +1,8 @@
1
1
  {
2
2
  "name": "@jcoreio/aws-ecr-utils",
3
- "version": "1.1.1",
3
+ "version": "1.3.0",
4
4
  "description": "utilities for working with AWS Elastic Container Registry",
5
- "main": "index.js",
6
5
  "sideEffects": false,
7
- "scripts": {
8
- "lint": "eslint $npm_package_config_lint",
9
- "lint:fix": "eslint $npm_package_config_lint",
10
- "prettier": "prettier --write $npm_package_config_prettier",
11
- "prettier:check": "prettier --list-different $npm_package_config_prettier",
12
- "tsc": "tsc",
13
- "tsc:watch": "npm run tsc -- --watch",
14
- "clean": "rimraf es lib $(cd src; ls) *.js *.d.ts *.js.flow",
15
- "build": "npm run clean && npm run build:types && npm run build:js",
16
- "build:types": "tsc -p tsconfig.build.json && tsc -p tsconfig.build.json --outDir es && copy 'src/**/*.js.flow' . && copy 'src/**/*.js.flow' es",
17
- "build:js": "babel src --out-dir es --extensions \".ts\" --source-maps inline && cross-env BABEL_ENV=es5 babel src --out-dir . --extensions \".ts\"",
18
- "test": "cross-env NODE_ENV=test BABEL_ENV=es5 mocha $npm_package_config_mocha && cross-env NODE_ENV=test BABEL_ENV=coverage nyc --reporter=lcov --reporter=text mocha $npm_package_config_mocha",
19
- "test:watch": "cross-env NODE_ENV=test BABEL_ENV=test mocha $npm_package_config_mocha --watch",
20
- "test:debug": "cross-env NODE_ENV=test BABEL_ENV=test mocha --inspect-brk $npm_package_config_mocha",
21
- "codecov": "nyc report --reporter=text-lcov > coverage.lcov; codecov",
22
- "prepublishOnly": "npm run clean && npm run prettier:check && npm run lint && flow && npm test && npm run build",
23
- "open:coverage": "open coverage/lcov-report/index.html",
24
- "semantic-release": "semantic-release"
25
- },
26
- "config": {
27
- "lint": "--cache --ext .js,.ts src test",
28
- "mocha": "--extension js --extension ts test/configure.js 'src/**/*.spec.ts' 'test/**/*.ts'",
29
- "prettier": ".babelrc.js *.{json,md} {src,test}/**/*.{js,ts,flow}",
30
- "commitizen": {
31
- "path": "cz-conventional-changelog"
32
- }
33
- },
34
- "husky": {
35
- "hooks": {
36
- "pre-commit": "lint-staged && npm run lint && npm run tsc && flow",
37
- "commit-msg": "commitlint -e $GIT_PARAMS",
38
- "pre-push": "npm test"
39
- }
40
- },
41
- "lint-staged": {
42
- "*.{js,ts,json,css,md,flow}": [
43
- "prettier --write"
44
- ]
45
- },
46
- "commitlint": {
47
- "extends": [
48
- "@jedwards1211/commitlint-config"
49
- ]
50
- },
51
- "prettier": {
52
- "semi": false,
53
- "singleQuote": true,
54
- "trailingComma": "es5"
55
- },
56
- "nyc": {
57
- "include": [
58
- "src/**/*.ts"
59
- ],
60
- "exclude": [
61
- "src/**/*.spec.ts"
62
- ],
63
- "require": [
64
- "@babel/register"
65
- ],
66
- "sourceMap": false,
67
- "instrument": false
68
- },
69
6
  "repository": {
70
7
  "type": "git",
71
8
  "url": "https://github.com/jcoreio/aws-ecr-utils.git"
@@ -81,48 +18,33 @@
81
18
  "url": "https://github.com/jcoreio/aws-ecr-utils/issues"
82
19
  },
83
20
  "homepage": "https://github.com/jcoreio/aws-ecr-utils#readme",
84
- "devDependencies": {
85
- "@babel/cli": "^7.15.7",
86
- "@babel/core": "^7.15.5",
87
- "@babel/plugin-proposal-export-default-from": "^7.14.5",
88
- "@babel/plugin-proposal-export-namespace-from": "^7.14.5",
89
- "@babel/plugin-transform-runtime": "^7.15.0",
90
- "@babel/preset-env": "^7.15.6",
91
- "@babel/preset-typescript": "^7.15.0",
92
- "@babel/register": "^7.15.3",
93
- "@commitlint/cli": "^13.2.0",
94
- "@commitlint/config-conventional": "^13.2.0",
95
- "@jedwards1211/commitlint-config": "^1.0.2",
96
- "@jedwards1211/eslint-config": "^2.0.2",
97
- "@jedwards1211/eslint-config-typescript": "^2.0.2",
98
- "@types/chai": "^4.2.22",
99
- "@types/mocha": "^9.0.0",
100
- "@types/node": "^16.10.2",
101
- "@typescript-eslint/eslint-plugin": "^4.32.0",
102
- "@typescript-eslint/parser": "^4.32.0",
103
- "@typescript-eslint/typescript-estree": "^4.32.0",
104
- "babel-plugin-istanbul": "^6.0.0",
105
- "chai": "^4.3.4",
106
- "codecov": "^3.8.3",
107
- "copy": "^0.3.2",
108
- "cross-env": "^7.0.3",
109
- "eslint": "^7.32.0",
110
- "eslint-config-prettier": "^8.3.0",
111
- "flow-bin": "^0.161.0",
112
- "husky": "^7.0.2",
113
- "lint-staged": "^11.1.2",
114
- "mocha": "^9.1.2",
115
- "nyc": "^15.1.0",
116
- "prettier": "^2.4.1",
117
- "prettier-eslint": "^13.0.0",
118
- "rimraf": "^3.0.2",
119
- "semantic-release": "^18.0.0",
120
- "typescript": "^4.4.3"
121
- },
122
21
  "dependencies": {
123
- "@babel/runtime": "^7.15.4",
22
+ "@babel/runtime": "^7.18.6",
124
23
  "aws-sdk": "^2.1070.0",
125
24
  "base64-js": "^1.5.1",
126
- "promisify-child-process": "^4.1.1"
127
- }
25
+ "inquirer": "^8.2.6",
26
+ "is-interactive": "^1.0.0",
27
+ "promisify-child-process": "^4.1.1",
28
+ "zod": "^3.22.4"
29
+ },
30
+ "main": "index.js",
31
+ "module": "index.mjs",
32
+ "types": "index.d.ts",
33
+ "exports": {
34
+ ".": {
35
+ "types": "./index.d.ts",
36
+ "require": "./index.js",
37
+ "default": "./index.mjs"
38
+ },
39
+ "./package.json": "./package.json",
40
+ "./*": {
41
+ "types": "./*.d.ts",
42
+ "require": "./*.js",
43
+ "default": "./*.mjs"
44
+ }
45
+ },
46
+ "engines": {
47
+ "node": ">=16"
48
+ },
49
+ "packageManager": "pnpm@8.3.1"
128
50
  }
@@ -1,6 +1,7 @@
1
+ import AWS from 'aws-sdk';
1
2
  export default function parseECRImageUri(imageUri: string): {
2
- registryId: string;
3
+ registryId: AWS.ECR.RegistryId;
3
4
  region: string;
4
- repositoryName: string;
5
+ repositoryName: AWS.ECR.RepositoryName;
5
6
  imageTag: string;
6
7
  };
@@ -1,28 +1,24 @@
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"] = parseECRImageUri;
9
-
10
8
  var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
11
-
12
9
  function parseECRImageUri(imageUri) {
13
10
  var match = /(\d+)\.dkr\.ecr\.([^.]+)\.amazonaws\.com\/([^:]+):(.+)/.exec(imageUri);
14
11
  if (!match) throw new Error("invalid imageUri: ".concat(imageUri));
15
-
16
12
  var _match = (0, _slicedToArray2["default"])(match, 5),
17
- registryId = _match[1],
18
- region = _match[2],
19
- repositoryName = _match[3],
20
- imageTag = _match[4];
21
-
13
+ registryId = _match[1],
14
+ region = _match[2],
15
+ repositoryName = _match[3],
16
+ imageTag = _match[4];
22
17
  return {
23
18
  registryId: registryId,
24
19
  region: region,
25
20
  repositoryName: repositoryName,
26
21
  imageTag: imageTag
27
22
  };
28
- }
23
+ }
24
+ module.exports = exports.default;
@@ -0,0 +1,11 @@
1
+ export default function parseECRImageUri(imageUri) {
2
+ const match = /(\d+)\.dkr\.ecr\.([^.]+)\.amazonaws\.com\/([^:]+):(.+)/.exec(imageUri);
3
+ if (!match) throw new Error(`invalid imageUri: ${imageUri}`);
4
+ const [, registryId, region, repositoryName, imageTag] = match;
5
+ return {
6
+ registryId,
7
+ region,
8
+ repositoryName,
9
+ imageTag
10
+ };
11
+ }
@@ -0,0 +1,6 @@
1
+ import AWS from 'aws-sdk';
2
+ export default function parseECRRepositoryHostname(hostname: string): {
3
+ registryId: AWS.ECR.RegistryId;
4
+ region: string;
5
+ repositoryName: AWS.ECR.RepositoryName;
6
+ };
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports["default"] = parseECRRepositoryHostname;
8
+ var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
9
+ function parseECRRepositoryHostname(hostname) {
10
+ var match = /^([^.]+)\.dkr\.ecr\.([^.]+)\.amazonaws\.com\/([^:]+)/.exec(hostname);
11
+ if (!match) throw new Error("invalid ECR repository hostname: ".concat(hostname));
12
+ var _match = (0, _slicedToArray2["default"])(match, 4),
13
+ registryId = _match[1],
14
+ region = _match[2],
15
+ repositoryName = _match[3];
16
+ return {
17
+ registryId: registryId,
18
+ region: region,
19
+ repositoryName: repositoryName
20
+ };
21
+ }
22
+ module.exports = exports.default;
@@ -0,0 +1,10 @@
1
+ export default function parseECRRepositoryHostname(hostname) {
2
+ const match = /^([^.]+)\.dkr\.ecr\.([^.]+)\.amazonaws\.com\/([^:]+)/.exec(hostname);
3
+ if (!match) throw new Error(`invalid ECR repository hostname: ${hostname}`);
4
+ const [, registryId, region, repositoryName] = match;
5
+ return {
6
+ registryId,
7
+ region,
8
+ repositoryName
9
+ };
10
+ }
package/tagECRImage.js CHANGED
@@ -1,142 +1,108 @@
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"] = tagECRImage;
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 _awsSdk = _interopRequireDefault(require("aws-sdk"));
17
-
18
- var _parseECRImageUri2 = _interopRequireDefault(require("./parseECRImageUri"));
19
-
12
+ var _parseECRImageUri2 = _interopRequireDefault(require("./parseECRImageUri.js"));
20
13
  function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; }
21
-
22
14
  function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
23
-
24
- function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
25
-
26
- 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; }
27
-
28
- 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; }
29
-
15
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
16
+ 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; }
17
+ 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; } /**
18
+ * @prettier
19
+ */
30
20
  function tagECRImage(_x) {
31
21
  return _tagECRImage.apply(this, arguments);
32
22
  }
33
-
34
23
  function _tagECRImage() {
35
24
  _tagECRImage = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee(_ref) {
36
25
  var ecr, awsConfig, imageUri, tags, _parseECRImageUri, region, repositoryName, imageTag, imageManifest, _iterator, _step, tag;
37
-
38
26
  return _regenerator["default"].wrap(function _callee$(_context) {
39
- while (1) {
40
- switch (_context.prev = _context.next) {
41
- case 0:
42
- ecr = _ref.ecr, awsConfig = _ref.awsConfig, imageUri = _ref.imageUri, tags = _ref.tags;
43
- _parseECRImageUri = (0, _parseECRImageUri2["default"])(imageUri), region = _parseECRImageUri.region, repositoryName = _parseECRImageUri.repositoryName, imageTag = _parseECRImageUri.imageTag;
44
- if (!ecr) ecr = new _awsSdk["default"].ECR(_objectSpread(_objectSpread({}, awsConfig), {}, {
45
- region: region
46
- }));
47
- _context.next = 5;
48
- return ecr.batchGetImage({
49
- repositoryName: repositoryName,
50
- imageIds: [{
51
- imageTag: imageTag
52
- }]
53
- }).promise().then(function (r) {
54
- var _r$images, _r$images$;
55
-
56
- return r === null || r === void 0 ? void 0 : (_r$images = r.images) === null || _r$images === void 0 ? void 0 : (_r$images$ = _r$images[0]) === null || _r$images$ === void 0 ? void 0 : _r$images$.imageManifest;
57
- });
58
-
59
- case 5:
60
- imageManifest = _context.sent;
61
-
62
- if (imageManifest) {
63
- _context.next = 8;
64
- break;
65
- }
66
-
67
- throw new Error("failed to get image manifest for ".concat(imageUri));
68
-
69
- case 8:
70
- if (!imageManifest) {
71
- _context.next = 34;
72
- break;
73
- }
74
-
75
- // add other tags to ECR
76
- _iterator = _createForOfIteratorHelper(tags);
77
- _context.prev = 10;
78
-
79
- _iterator.s();
80
-
81
- case 12:
82
- if ((_step = _iterator.n()).done) {
83
- _context.next = 26;
84
- break;
85
- }
86
-
87
- tag = _step.value;
88
- // eslint-disable-next-line no-console
89
- console.error("Adding tag ".concat(repositoryName, ":").concat(tag));
90
- _context.prev = 15;
91
- _context.next = 18;
92
- return ecr.putImage({
93
- repositoryName: repositoryName,
94
- imageManifest: imageManifest,
95
- imageTag: tag.substring(tag.indexOf(':') + 1)
96
- }).promise();
97
-
98
- case 18:
99
- _context.next = 24;
27
+ while (1) switch (_context.prev = _context.next) {
28
+ case 0:
29
+ ecr = _ref.ecr, awsConfig = _ref.awsConfig, imageUri = _ref.imageUri, tags = _ref.tags;
30
+ _parseECRImageUri = (0, _parseECRImageUri2["default"])(imageUri), region = _parseECRImageUri.region, repositoryName = _parseECRImageUri.repositoryName, imageTag = _parseECRImageUri.imageTag;
31
+ if (!ecr) ecr = new _awsSdk["default"].ECR(_objectSpread(_objectSpread({}, awsConfig), {}, {
32
+ region: region
33
+ }));
34
+ _context.next = 5;
35
+ return ecr.batchGetImage({
36
+ repositoryName: repositoryName,
37
+ imageIds: [{
38
+ imageTag: imageTag
39
+ }]
40
+ }).promise().then(function (r) {
41
+ var _r$images;
42
+ return r === null || r === void 0 || (_r$images = r.images) === null || _r$images === void 0 || (_r$images = _r$images[0]) === null || _r$images === void 0 ? void 0 : _r$images.imageManifest;
43
+ });
44
+ case 5:
45
+ imageManifest = _context.sent;
46
+ if (imageManifest) {
47
+ _context.next = 8;
100
48
  break;
101
-
102
- case 20:
103
- _context.prev = 20;
104
- _context.t0 = _context["catch"](15);
105
-
106
- if (!((_context.t0 === null || _context.t0 === void 0 ? void 0 : _context.t0.code) !== 'ImageAlreadyExistsException')) {
107
- _context.next = 24;
108
- break;
109
- }
110
-
111
- throw _context.t0;
112
-
113
- case 24:
114
- _context.next = 12;
49
+ }
50
+ throw new Error("failed to get image manifest for ".concat(imageUri));
51
+ case 8:
52
+ if (!imageManifest) {
53
+ _context.next = 34;
115
54
  break;
116
-
117
- case 26:
118
- _context.next = 31;
55
+ }
56
+ // add other tags to ECR
57
+ _iterator = _createForOfIteratorHelper(tags);
58
+ _context.prev = 10;
59
+ _iterator.s();
60
+ case 12:
61
+ if ((_step = _iterator.n()).done) {
62
+ _context.next = 26;
119
63
  break;
120
-
121
- case 28:
122
- _context.prev = 28;
123
- _context.t1 = _context["catch"](10);
124
-
125
- _iterator.e(_context.t1);
126
-
127
- case 31:
128
- _context.prev = 31;
129
-
130
- _iterator.f();
131
-
132
- return _context.finish(31);
133
-
134
- case 34:
135
- case "end":
136
- return _context.stop();
137
- }
64
+ }
65
+ tag = _step.value;
66
+ // eslint-disable-next-line no-console
67
+ console.error("Adding tag ".concat(repositoryName, ":").concat(tag));
68
+ _context.prev = 15;
69
+ _context.next = 18;
70
+ return ecr.putImage({
71
+ repositoryName: repositoryName,
72
+ imageManifest: imageManifest,
73
+ imageTag: tag.substring(tag.indexOf(':') + 1)
74
+ }).promise();
75
+ case 18:
76
+ _context.next = 24;
77
+ break;
78
+ case 20:
79
+ _context.prev = 20;
80
+ _context.t0 = _context["catch"](15);
81
+ if (!((_context.t0 === null || _context.t0 === void 0 ? void 0 : _context.t0.code) !== 'ImageAlreadyExistsException')) {
82
+ _context.next = 24;
83
+ break;
84
+ }
85
+ throw _context.t0;
86
+ case 24:
87
+ _context.next = 12;
88
+ break;
89
+ case 26:
90
+ _context.next = 31;
91
+ break;
92
+ case 28:
93
+ _context.prev = 28;
94
+ _context.t1 = _context["catch"](10);
95
+ _iterator.e(_context.t1);
96
+ case 31:
97
+ _context.prev = 31;
98
+ _iterator.f();
99
+ return _context.finish(31);
100
+ case 34:
101
+ case "end":
102
+ return _context.stop();
138
103
  }
139
104
  }, _callee, null, [[10, 28, 31, 34], [15, 20]]);
140
105
  }));
141
106
  return _tagECRImage.apply(this, arguments);
142
- }
107
+ }
108
+ module.exports = exports.default;