@payfit/nx-core 0.0.0-e2e

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 (136) hide show
  1. package/README.md +173 -0
  2. package/dist/src/codegen.d.ts +3 -0
  3. package/dist/src/codegen.js +25 -0
  4. package/dist/src/codegen.js.map +1 -0
  5. package/dist/src/executors/preview-deploy/README.md +5 -0
  6. package/dist/src/executors/preview-deploy/argocdOverride.d.ts +4 -0
  7. package/dist/src/executors/preview-deploy/argocdOverride.js +22 -0
  8. package/dist/src/executors/preview-deploy/argocdOverride.js.map +1 -0
  9. package/dist/src/executors/preview-deploy/executor.d.ts +4 -0
  10. package/dist/src/executors/preview-deploy/executor.js +143 -0
  11. package/dist/src/executors/preview-deploy/executor.js.map +1 -0
  12. package/dist/src/executors/preview-deploy/kargoPolicy.d.ts +14 -0
  13. package/dist/src/executors/preview-deploy/kargoPolicy.js +69 -0
  14. package/dist/src/executors/preview-deploy/kargoPolicy.js.map +1 -0
  15. package/dist/src/executors/preview-deploy/schema.json +28 -0
  16. package/dist/src/executors/publisher/README.md +3 -0
  17. package/dist/src/executors/publisher/docker.d.ts +3 -0
  18. package/dist/src/executors/publisher/docker.js +66 -0
  19. package/dist/src/executors/publisher/docker.js.map +1 -0
  20. package/dist/src/executors/publisher/executor.d.ts +4 -0
  21. package/dist/src/executors/publisher/executor.js +20 -0
  22. package/dist/src/executors/publisher/executor.js.map +1 -0
  23. package/dist/src/executors/publisher/helm.d.ts +3 -0
  24. package/dist/src/executors/publisher/helm.js +69 -0
  25. package/dist/src/executors/publisher/helm.js.map +1 -0
  26. package/dist/src/executors/publisher/lambda.d.ts +18 -0
  27. package/dist/src/executors/publisher/lambda.js +86 -0
  28. package/dist/src/executors/publisher/lambda.js.map +1 -0
  29. package/dist/src/executors/publisher/schema.json +62 -0
  30. package/dist/src/executors/release/README.md +15 -0
  31. package/dist/src/executors/release/executor.d.ts +4 -0
  32. package/dist/src/executors/release/executor.js +104 -0
  33. package/dist/src/executors/release/executor.js.map +1 -0
  34. package/dist/src/executors/release/schema.json +37 -0
  35. package/dist/src/generators/init/README.md +5 -0
  36. package/dist/src/generators/init/files/.circleci/config.yml.template +232 -0
  37. package/dist/src/generators/init/files/.circleci/teleport/shared-charts.conf.template +24 -0
  38. package/dist/src/generators/init/files/.npmrc.template +1 -0
  39. package/dist/src/generators/init/init.d.ts +13 -0
  40. package/dist/src/generators/init/init.js +278 -0
  41. package/dist/src/generators/init/init.js.map +1 -0
  42. package/dist/src/generators/init/schema.json +7 -0
  43. package/dist/src/index.d.ts +27 -0
  44. package/dist/src/index.js +118 -0
  45. package/dist/src/index.js.map +1 -0
  46. package/dist/src/scripts/codegen-with-auth.js +55 -0
  47. package/dist/src/scripts/version-actions.d.ts +8 -0
  48. package/dist/src/scripts/version-actions.js +41 -0
  49. package/dist/src/scripts/version-actions.js.map +1 -0
  50. package/dist/src/scripts/version-actions.mock.d.ts +6 -0
  51. package/dist/src/scripts/version-actions.mock.js +61 -0
  52. package/dist/src/scripts/version-actions.mock.js.map +1 -0
  53. package/dist/src/utils/common/aws-auth.d.ts +47 -0
  54. package/dist/src/utils/common/aws-auth.js +145 -0
  55. package/dist/src/utils/common/aws-auth.js.map +1 -0
  56. package/dist/src/utils/common/circleci.d.ts +2 -0
  57. package/dist/src/utils/common/circleci.js +20 -0
  58. package/dist/src/utils/common/circleci.js.map +1 -0
  59. package/dist/src/utils/common/exec.d.ts +4 -0
  60. package/dist/src/utils/common/exec.js +52 -0
  61. package/dist/src/utils/common/exec.js.map +1 -0
  62. package/dist/src/utils/common/github.d.ts +20 -0
  63. package/dist/src/utils/common/github.js +60 -0
  64. package/dist/src/utils/common/github.js.map +1 -0
  65. package/dist/src/utils/common/import-esm.d.ts +2 -0
  66. package/dist/src/utils/common/import-esm.js +12 -0
  67. package/dist/src/utils/common/import-esm.js.map +1 -0
  68. package/dist/src/utils/common/logger.d.ts +1 -0
  69. package/dist/src/utils/common/logger.js +8 -0
  70. package/dist/src/utils/common/logger.js.map +1 -0
  71. package/dist/src/utils/common/nx.d.ts +22 -0
  72. package/dist/src/utils/common/nx.js +174 -0
  73. package/dist/src/utils/common/nx.js.map +1 -0
  74. package/dist/src/utils/common/s3.d.ts +1 -0
  75. package/dist/src/utils/common/s3.js +18 -0
  76. package/dist/src/utils/common/s3.js.map +1 -0
  77. package/dist/src/utils/common/tsh.d.ts +11 -0
  78. package/dist/src/utils/common/tsh.js +112 -0
  79. package/dist/src/utils/common/tsh.js.map +1 -0
  80. package/dist/src/utils/datadog.d.ts +1 -0
  81. package/dist/src/utils/datadog.js +33 -0
  82. package/dist/src/utils/datadog.js.map +1 -0
  83. package/dist/src/utils/docker.d.ts +15 -0
  84. package/dist/src/utils/docker.js +73 -0
  85. package/dist/src/utils/docker.js.map +1 -0
  86. package/dist/src/utils/helm.d.ts +64 -0
  87. package/dist/src/utils/helm.js +159 -0
  88. package/dist/src/utils/helm.js.map +1 -0
  89. package/dist/src/utils/helm.mock.d.ts +85 -0
  90. package/dist/src/utils/helm.mock.js +100 -0
  91. package/dist/src/utils/helm.mock.js.map +1 -0
  92. package/dist/src/utils/lambda/aws-lambda.d.ts +47 -0
  93. package/dist/src/utils/lambda/aws-lambda.js +231 -0
  94. package/dist/src/utils/lambda/aws-lambda.js.map +1 -0
  95. package/dist/src/utils/lambda/lambda.d.ts +7 -0
  96. package/dist/src/utils/lambda/lambda.js +20 -0
  97. package/dist/src/utils/lambda/lambda.js.map +1 -0
  98. package/dist/src/utils/lambda/oci.d.ts +8 -0
  99. package/dist/src/utils/lambda/oci.js +22 -0
  100. package/dist/src/utils/lambda/oci.js.map +1 -0
  101. package/dist/src/utils/lambda/publish.d.ts +14 -0
  102. package/dist/src/utils/lambda/publish.js +44 -0
  103. package/dist/src/utils/lambda/publish.js.map +1 -0
  104. package/dist/src/utils/lambda/spacelift.d.ts +3 -0
  105. package/dist/src/utils/lambda/spacelift.js +55 -0
  106. package/dist/src/utils/lambda/spacelift.js.map +1 -0
  107. package/dist/src/utils/spacelift/lib/__generated__/fragment-masking.d.ts +19 -0
  108. package/dist/src/utils/spacelift/lib/__generated__/fragment-masking.js +22 -0
  109. package/dist/src/utils/spacelift/lib/__generated__/fragment-masking.js.map +1 -0
  110. package/dist/src/utils/spacelift/lib/__generated__/gql.d.ts +15 -0
  111. package/dist/src/utils/spacelift/lib/__generated__/gql.js +8 -0
  112. package/dist/src/utils/spacelift/lib/__generated__/gql.js.map +1 -0
  113. package/dist/src/utils/spacelift/lib/__generated__/graphql.d.ts +9426 -0
  114. package/dist/src/utils/spacelift/lib/__generated__/graphql.js +819 -0
  115. package/dist/src/utils/spacelift/lib/__generated__/graphql.js.map +1 -0
  116. package/dist/src/utils/spacelift/lib/__generated__/index.d.ts +2 -0
  117. package/dist/src/utils/spacelift/lib/__generated__/index.js +6 -0
  118. package/dist/src/utils/spacelift/lib/__generated__/index.js.map +1 -0
  119. package/dist/src/utils/spacelift/lib/graphql.service.d.ts +18 -0
  120. package/dist/src/utils/spacelift/lib/graphql.service.js +186 -0
  121. package/dist/src/utils/spacelift/lib/graphql.service.js.map +1 -0
  122. package/dist/src/utils/spacelift/lib/query/spacelift.queries.d.ts +34 -0
  123. package/dist/src/utils/spacelift/lib/query/spacelift.queries.js +48 -0
  124. package/dist/src/utils/spacelift/lib/query/spacelift.queries.js.map +1 -0
  125. package/dist/src/utils/spacelift/lib/spacelift.error.d.ts +43 -0
  126. package/dist/src/utils/spacelift/lib/spacelift.error.js +63 -0
  127. package/dist/src/utils/spacelift/lib/spacelift.error.js.map +1 -0
  128. package/dist/src/utils/spacelift/lib/spacelift.service.d.ts +16 -0
  129. package/dist/src/utils/spacelift/lib/spacelift.service.js +58 -0
  130. package/dist/src/utils/spacelift/lib/spacelift.service.js.map +1 -0
  131. package/dist/src/utils/spacelift/lib/utils.d.ts +4 -0
  132. package/dist/src/utils/spacelift/lib/utils.js +32 -0
  133. package/dist/src/utils/spacelift/lib/utils.js.map +1 -0
  134. package/executors.json +19 -0
  135. package/generators.json +9 -0
  136. package/package.json +60 -0
@@ -0,0 +1,159 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getHelmChartFile = getHelmChartFile;
4
+ exports.setupTeleportProxyHelmChartFile = setupTeleportProxyHelmChartFile;
5
+ exports.resetTeleportProxyHelmChartFile = resetTeleportProxyHelmChartFile;
6
+ exports.installHelmRepo = installHelmRepo;
7
+ exports.patchImageTag = patchImageTag;
8
+ exports.packageHelm = packageHelm;
9
+ exports.pushPackagedHelm = pushPackagedHelm;
10
+ exports.pushOciPackagedHelm = pushOciPackagedHelm;
11
+ const fs = require("node:fs");
12
+ const process = require("node:process");
13
+ const YAML = require("yaml");
14
+ const aws_auth_1 = require("./common/aws-auth");
15
+ const exec_1 = require("./common/exec");
16
+ const logger_1 = require("./common/logger");
17
+ const tshProxy = 'http://localhost';
18
+ /**
19
+ * Read & parse the Helm chart.yaml file
20
+ * @param helmFolderPath
21
+ */
22
+ async function getHelmChartFile(helmFolderPath) {
23
+ return YAML.parse(fs.readFileSync(`${helmFolderPath}/Chart.yaml`, 'utf8'));
24
+ }
25
+ /**
26
+ * Prepare the Chart.yaml config file for the Tsh proxy
27
+ * @param helmFolderPath
28
+ * @param tshPort
29
+ */
30
+ async function setupTeleportProxyHelmChartFile(helmFolderPath, tshPort) {
31
+ logger_1.consola.log(`Replacing charts.shared.payfit.tech -> localhost:${tshPort} for the Teleport proxy`);
32
+ let chartConfigStr = YAML.stringify(await getHelmChartFile(helmFolderPath));
33
+ chartConfigStr = chartConfigStr.replace(/(https?:\/\/)charts(\.shared)?\.payfit\.tech/gi, `${tshProxy}:${tshPort}`);
34
+ return fs.writeFileSync(`${helmFolderPath}/Chart.yaml`, chartConfigStr);
35
+ }
36
+ /**
37
+ * Revert the Tsh proxy config in the Chart.yaml config file
38
+ * @param helmFolderPath
39
+ * @param tshPort
40
+ */
41
+ async function resetTeleportProxyHelmChartFile(helmFolderPath, tshPort) {
42
+ let chartConfigStr = YAML.stringify(await getHelmChartFile(helmFolderPath));
43
+ chartConfigStr = chartConfigStr.replace(`${tshProxy}:${tshPort}`, 'https://charts.shared.payfit.tech');
44
+ return fs.writeFileSync(`${helmFolderPath}/Chart.yaml`, chartConfigStr);
45
+ }
46
+ /**
47
+ * Install all the helm repositories defined in the Chart config
48
+ * @param helmFolderPath
49
+ */
50
+ async function installHelmRepo(helmFolderPath) {
51
+ const chartConfig = await getHelmChartFile(helmFolderPath);
52
+ if (chartConfig.dependencies) {
53
+ for (let i = 0; i < chartConfig.dependencies.length; i++) {
54
+ const dep = chartConfig.dependencies[i];
55
+ const repoName = `tsh-${dep.name}-${dep.alias}`;
56
+ // check if the repository is our private payfit repo or a public one
57
+ if (dep.repository.includes(tshProxy)) {
58
+ // if it's our repo, we need the username and password to authenticate
59
+ if (!process.env.CHARTMUSEUM_USERNAME ||
60
+ !process.env.CHARTMUSEUM_PASSWORD)
61
+ throw new Error('Missing CHARTMUSEUM_USERNAME, CHARTMUSEUM_PASSWORD in environment!');
62
+ await (0, exec_1.exec)(`helm repo add --username '${process.env.CHARTMUSEUM_USERNAME}' --password '${process.env.CHARTMUSEUM_PASSWORD}' '${repoName}' '${dep.repository}' --force-update`);
63
+ }
64
+ else {
65
+ await (0, exec_1.exec)(`helm repo add '${repoName}' '${dep.repository}' --force-update`);
66
+ }
67
+ await (0, exec_1.exec)(`helm repo update ${repoName}`);
68
+ }
69
+ }
70
+ return (0, exec_1.exec)(`helm dependency update ${helmFolderPath}`);
71
+ }
72
+ /**
73
+ * Patch Docker image tag in values.yaml
74
+ * @param valuesConfigPath
75
+ * @param chartConfigPath
76
+ * @param version
77
+ */
78
+ async function patchImageTag(valuesConfigPath, chartConfigPath, version) {
79
+ if (fs.existsSync(valuesConfigPath)) {
80
+ logger_1.consola.log('Values files detected, trying to patch Docker image tag');
81
+ const values = YAML.parse(fs.readFileSync(valuesConfigPath, 'utf8'));
82
+ const chart = YAML.parse(fs.readFileSync(chartConfigPath, 'utf8'));
83
+ let shouldUpdateFile = false;
84
+ // Patch the global image tag
85
+ if (values.image?.tag) {
86
+ values.image.tag = version;
87
+ logger_1.consola.log(`Patched Docker global image tag`);
88
+ shouldUpdateFile = true;
89
+ }
90
+ // Patch the image tag for the deps service
91
+ if (chart.dependencies) {
92
+ for (const dep of chart.dependencies) {
93
+ if (values[dep.alias]) {
94
+ if (values[dep.alias]?.image?.tag) {
95
+ values[dep.alias].image.tag = version;
96
+ shouldUpdateFile = true;
97
+ logger_1.consola.log(`Patched Docker image tag for the service ${dep.alias} successfully`);
98
+ }
99
+ else {
100
+ logger_1.consola.warn(`Failed to find image.tag key for the service ${dep.alias}`);
101
+ }
102
+ if (values[dep.alias]?.dbMigration?.image?.tag) {
103
+ values[dep.alias].dbMigration.image.tag = version;
104
+ shouldUpdateFile = true;
105
+ logger_1.consola.log(`Patched Docker image tag for the dbMigration of the service ${dep.alias} successfully`);
106
+ }
107
+ }
108
+ else {
109
+ logger_1.consola.warn(`Failed to find the service key ${dep.alias} in the values.yaml file`);
110
+ }
111
+ }
112
+ }
113
+ if (shouldUpdateFile) {
114
+ fs.writeFileSync(valuesConfigPath, YAML.stringify(values), {
115
+ encoding: 'utf8',
116
+ });
117
+ }
118
+ }
119
+ else {
120
+ logger_1.consola.warn(`No values.yaml file detected at ${valuesConfigPath}, can't patch Docker image tag`);
121
+ }
122
+ }
123
+ /**
124
+ * Package the Helm chart
125
+ * @param helmFolderPath
126
+ * @param version
127
+ * @param destinationPath
128
+ */
129
+ async function packageHelm(helmFolderPath, version, destinationPath) {
130
+ return (0, exec_1.exec)(`helm package ${helmFolderPath} --version ${version} --app-version ${version} --destination ${destinationPath}`);
131
+ }
132
+ /**
133
+ * Push the packaged Helm chart in the chartmuseum
134
+ * @param packagedHelmChartFilePath
135
+ * @param packagedHelmChartName
136
+ * @param projectName
137
+ * @param branch
138
+ */
139
+ async function pushPackagedHelm(packagedHelmChartFilePath, packagedHelmChartName, projectName, branch) {
140
+ if (!process.env.CHARTMUSEUM_BUCKET_NAME)
141
+ throw new Error('Missing CHARTMUSEUM_BUCKET_NAME in environment!');
142
+ const profile = (0, aws_auth_1.getProfileName)() === 'default' ? '' : `--profile ${(0, aws_auth_1.getProfileName)()}`;
143
+ await (0, exec_1.exec)(`aws s3 cp ${profile} --sse AES256 ${packagedHelmChartFilePath} s3://${process.env.CHARTMUSEUM_BUCKET_NAME}/${projectName}/${branch}/`);
144
+ if (packagedHelmChartFilePath.includes('ephemeral')) {
145
+ await (0, exec_1.exec)(`aws s3api put-object-tagging ${profile} --bucket ${process.env.CHARTMUSEUM_BUCKET_NAME} --key ${projectName}/${branch}/${packagedHelmChartName} --tagging '{"TagSet": [{ "Key": "auto-purge", "Value": "true" }]}'`);
146
+ }
147
+ }
148
+ /**
149
+ * Push the packaged Helm chart to an OCI-compatible ECR repository
150
+ * @param packagedHelmChartFilePath
151
+ * @param ecrRegistry
152
+ */
153
+ async function pushOciPackagedHelm(packagedHelmChartFilePath, ecrRegistry) {
154
+ // Login to ECR
155
+ await (0, aws_auth_1.loginToEcr)(process.env.AWS_ECR_REGISTRY);
156
+ // Push the Helm chart to ECR using OCI format
157
+ return (0, exec_1.exec)(`helm push ${packagedHelmChartFilePath} oci://${ecrRegistry}`);
158
+ }
159
+ //# sourceMappingURL=helm.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"helm.js","sourceRoot":"","sources":["../../../src/utils/helm.ts"],"names":[],"mappings":";;AA8BA,4CAIC;AAOD,0EAaC;AAOD,0EAUC;AAMD,0CA4BC;AAQD,sCAuDC;AAQD,kCAQC;AASD,4CAmBC;AAOD,kDASC;AApOD,8BAA6B;AAC7B,wCAAuC;AAEvC,6BAA4B;AAE5B,gDAA8D;AAC9D,wCAAoC;AACpC,4CAAyC;AAEzC,MAAM,QAAQ,GAAG,kBAAkB,CAAA;AAiBnC;;;GAGG;AACI,KAAK,UAAU,gBAAgB,CACpC,cAAsB;IAEtB,OAAO,IAAI,CAAC,KAAK,CAAC,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f,MAAM,IAAA,qBAAU,EAAC,OAAO,CAAC,GAAG,CAAC,gBAAgB,CAAC,CAAA;IAE9C,8CAA8C;IAC9C,OAAO,IAAA,WAAI,EAAC,aAAa,yBAAyB,UAAU,WAAW,EAAE,CAAC,CAAA;AAC5E,CAAC"}
@@ -0,0 +1,85 @@
1
+ export declare const mockValuesConfigPath = "/tmp/values.yaml";
2
+ export declare const mockChartConfigPath = "/tmp/Chart.yaml";
3
+ export declare const mockVersion = "1.2.3";
4
+ export declare const mockChart1SvcConfig: {
5
+ dependencies: {
6
+ name: string;
7
+ alias: string;
8
+ repository: string;
9
+ }[];
10
+ };
11
+ export declare const mockChart2SvcConfig: {
12
+ dependencies: {
13
+ name: string;
14
+ alias: string;
15
+ repository: string;
16
+ }[];
17
+ };
18
+ export declare const mockChartPublicConfig: {
19
+ dependencies: {
20
+ name: string;
21
+ alias: string;
22
+ repository: string;
23
+ }[];
24
+ };
25
+ export declare const mockValues2SvcWithDbMigration: {
26
+ service1Alias: {
27
+ image: {
28
+ tag: string;
29
+ };
30
+ dbMigration: {
31
+ image: {
32
+ tag: string;
33
+ };
34
+ };
35
+ };
36
+ service2Alias: {
37
+ image: {
38
+ tag: string;
39
+ };
40
+ };
41
+ };
42
+ export declare const expectedValuesConfig2SvcWithDbMigration: {
43
+ service1Alias: {
44
+ image: {
45
+ tag: string;
46
+ };
47
+ dbMigration: {
48
+ image: {
49
+ tag: string;
50
+ };
51
+ };
52
+ };
53
+ service2Alias: {
54
+ image: {
55
+ tag: string;
56
+ };
57
+ };
58
+ };
59
+ export declare const mockValues1Svc: {
60
+ service1Alias: {
61
+ image: {
62
+ tag: string;
63
+ };
64
+ };
65
+ };
66
+ export declare const mockValuesGlobalTag: {
67
+ service1Alias: {
68
+ image: {
69
+ tag: string;
70
+ };
71
+ };
72
+ image: {
73
+ tag: string;
74
+ };
75
+ };
76
+ export declare const mockValuesWithoutImageTag: {
77
+ service1Alias: {
78
+ someOtherConfig: string;
79
+ };
80
+ };
81
+ export declare const mockValuesOnlyGlobalTag: {
82
+ image: {
83
+ tag: string;
84
+ };
85
+ };
@@ -0,0 +1,100 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.mockValuesOnlyGlobalTag = exports.mockValuesWithoutImageTag = exports.mockValuesGlobalTag = exports.mockValues1Svc = exports.expectedValuesConfig2SvcWithDbMigration = exports.mockValues2SvcWithDbMigration = exports.mockChartPublicConfig = exports.mockChart2SvcConfig = exports.mockChart1SvcConfig = exports.mockVersion = exports.mockChartConfigPath = exports.mockValuesConfigPath = void 0;
4
+ exports.mockValuesConfigPath = '/tmp/values.yaml';
5
+ exports.mockChartConfigPath = '/tmp/Chart.yaml';
6
+ exports.mockVersion = '1.2.3';
7
+ exports.mockChart1SvcConfig = {
8
+ dependencies: [
9
+ {
10
+ name: 'service1',
11
+ alias: 'service1Alias',
12
+ repository: 'http://localhost:8080',
13
+ },
14
+ ],
15
+ };
16
+ exports.mockChart2SvcConfig = {
17
+ dependencies: [
18
+ {
19
+ name: 'service1',
20
+ alias: 'service1Alias',
21
+ repository: 'http://localhost:8080',
22
+ },
23
+ {
24
+ name: 'service2',
25
+ alias: 'service2Alias',
26
+ repository: 'http://localhost:8080',
27
+ },
28
+ ],
29
+ };
30
+ exports.mockChartPublicConfig = {
31
+ dependencies: [
32
+ {
33
+ name: 'service1',
34
+ alias: 'service1Alias',
35
+ repository: 'https://public-repo.example.com',
36
+ },
37
+ ],
38
+ };
39
+ exports.mockValues2SvcWithDbMigration = {
40
+ service1Alias: {
41
+ image: {
42
+ tag: 'old-tag',
43
+ },
44
+ dbMigration: {
45
+ image: {
46
+ tag: 'old-tag',
47
+ },
48
+ },
49
+ },
50
+ service2Alias: {
51
+ image: {
52
+ tag: 'old-tag',
53
+ },
54
+ },
55
+ };
56
+ exports.expectedValuesConfig2SvcWithDbMigration = {
57
+ service1Alias: {
58
+ image: {
59
+ tag: exports.mockVersion,
60
+ },
61
+ dbMigration: {
62
+ image: {
63
+ tag: exports.mockVersion,
64
+ },
65
+ },
66
+ },
67
+ service2Alias: {
68
+ image: {
69
+ tag: exports.mockVersion,
70
+ },
71
+ },
72
+ };
73
+ exports.mockValues1Svc = {
74
+ service1Alias: {
75
+ image: {
76
+ tag: 'old-tag',
77
+ },
78
+ },
79
+ };
80
+ exports.mockValuesGlobalTag = {
81
+ service1Alias: {
82
+ image: {
83
+ tag: 'old-tag',
84
+ },
85
+ },
86
+ image: {
87
+ tag: 'old-global-tag',
88
+ },
89
+ };
90
+ exports.mockValuesWithoutImageTag = {
91
+ service1Alias: {
92
+ someOtherConfig: 'value',
93
+ },
94
+ };
95
+ exports.mockValuesOnlyGlobalTag = {
96
+ image: {
97
+ tag: 'old-global-tag',
98
+ },
99
+ };
100
+ //# sourceMappingURL=helm.mock.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"helm.mock.js","sourceRoot":"","sources":["../../../src/utils/helm.mock.ts"],"names":[],"mappings":";;;AAAa,QAAA,oBAAoB,GAAG,kBAAkB,CAAA;AACzC,QAAA,mBAAmB,GAAG,iBAAiB,CAAA;AACvC,QAAA,WAAW,GAAG,OAAO,CAAA;AAErB,QAAA,mBAAmB,GAAG;IACjC,YAAY,EAAE;QACZ;YACE,IAAI,EAAE,UAAU;YAChB,KAAK,EAAE,eAAe;YACtB,UAAU,EAAE,uBAAuB;SACpC;KACF;CACF,CAAA;AAEY,QAAA,mBAAmB,GAAG;IACjC,YAAY,EAAE;QACZ;YACE,IAAI,EAAE,UAAU;YAChB,KAAK,EAAE,eAAe;YACtB,UAAU,EAAE,uBAAuB;SACpC;QACD;YACE,IAAI,EAAE,UAAU;YAChB,KAAK,EAAE,eAAe;YACtB,UAAU,EAAE,uBAAuB;SACpC;KACF;CACF,CAAA;AAEY,QAAA,qBAAqB,GAAG;IACnC,YAAY,EAAE;QACZ;YACE,IAAI,EAAE,UAAU;YAChB,KAAK,EAAE,eAAe;YACtB,UAAU,EAAE,iCAAiC;SAC9C;KACF;CACF,CAAA;AAEY,QAAA,6BAA6B,GAAG;IAC3C,aAAa,EAAE;QACb,KAAK,EAAE;YACL,GAAG,EAAE,SAAS;SACf;QACD,WAAW,EAAE;YACX,KAAK,EAAE;gBACL,GAAG,EAAE,SAAS;aACf;SACF;KACF;IACD,aAAa,EAAE;QACb,KAAK,EAAE;YACL,GAAG,EAAE,SAAS;SACf;KACF;CACF,CAAA;AAEY,QAAA,uCAAuC,GAAG;IACrD,aAAa,EAAE;QACb,KAAK,EAAE;YACL,GAAG,EAAE,mBAAW;SACjB;QACD,WAAW,EAAE;YACX,KAAK,EAAE;gBACL,GAAG,EAAE,mBAAW;aACjB;SACF;KACF;IACD,aAAa,EAAE;QACb,KAAK,EAAE;YACL,GAAG,EAAE,mBAAW;SACjB;KACF;CACF,CAAA;AAEY,QAAA,cAAc,GAAG;IAC5B,aAAa,EAAE;QACb,KAAK,EAAE;YACL,GAAG,EAAE,SAAS;SACf;KACF;CACF,CAAA;AAEY,QAAA,mBAAmB,GAAG;IACjC,aAAa,EAAE;QACb,KAAK,EAAE;YACL,GAAG,EAAE,SAAS;SACf;KACF;IACD,KAAK,EAAE;QACL,GAAG,EAAE,gBAAgB;KACtB;CACF,CAAA;AAEY,QAAA,yBAAyB,GAAG;IACvC,aAAa,EAAE;QACb,eAAe,EAAE,OAAO;KACzB;CACF,CAAA;AAEY,QAAA,uBAAuB,GAAG;IACrC,KAAK,EAAE;QACL,GAAG,EAAE,gBAAgB;KACtB;CACF,CAAA"}
@@ -0,0 +1,47 @@
1
+ /**
2
+ * Extracts environment and AWS account ID from Spacelift stack ID.
3
+ *
4
+ * @param stackId - Spacelift stack identifier
5
+ * @returns Tuple of [environment, accountId]
6
+ */
7
+ export declare function retrieveAccoundId(stackId: string): [string, string];
8
+ /**
9
+ * Gets the latest version number of a Lambda function.
10
+ *
11
+ * @param lambdaARN - AWS Lambda function ARN
12
+ * @param envVars - AWS credentials environment variables
13
+ * @returns Latest version number
14
+ */
15
+ export declare function getLatestVersion(lambdaARN: string, envVars: Record<string, string>): Promise<string>;
16
+ /**
17
+ * Runs smoke tests on Lambda functions by invoking them with empty payload.
18
+ *
19
+ * @param stackId - Spacelift stack ID to determine environment
20
+ * @param lambdaFunctions - Array of Lambda function names to test
21
+ * @param lambdaHealthCheckPayload
22
+ */
23
+ export declare function runSmokeTests(stackId: string, lambdaFunctions: string[], lambdaHealthCheckPayload: string): Promise<void>;
24
+ /**
25
+ * Creates or updates a Lambda function alias to point to latest version.
26
+ *
27
+ * @param accountId - AWS account ID
28
+ * @param lambdaARN - Lambda function ARN
29
+ * @param alias - Alias name to create/update
30
+ * @param envVars - AWS credentials environment variables
31
+ */
32
+ export declare function createOrUpdateLambdaAlias(accountId: string, lambdaARN: string, alias: string, envVars: Record<string, string>): Promise<void>;
33
+ /**
34
+ * Sanitizes alias names for AWS Lambda compatibility (replaces dots with dashes).
35
+ *
36
+ * @param alias - Raw alias name
37
+ * @returns Sanitized alias name
38
+ */
39
+ export declare function sanitizeAliasName(alias: string): string;
40
+ /**
41
+ * Creates or updates aliases for multiple Lambda functions in parallel.
42
+ *
43
+ * @param stackId - Spacelift stack ID to determine environment
44
+ * @param lambdaFunctions - Array of Lambda function names
45
+ * @param alias - Alias name to create/update
46
+ */
47
+ export declare function createOrMoveAlias(stackId: string, lambdaFunctions: string[], alias: string): Promise<void>;
@@ -0,0 +1,231 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.retrieveAccoundId = retrieveAccoundId;
4
+ exports.getLatestVersion = getLatestVersion;
5
+ exports.runSmokeTests = runSmokeTests;
6
+ exports.createOrUpdateLambdaAlias = createOrUpdateLambdaAlias;
7
+ exports.sanitizeAliasName = sanitizeAliasName;
8
+ exports.createOrMoveAlias = createOrMoveAlias;
9
+ const devkit_1 = require("@nx/devkit");
10
+ const exec_1 = require("../common/exec");
11
+ const logger_1 = require("../common/logger");
12
+ const ACCOUNT_IDS = {
13
+ dev: '533547282673',
14
+ staging: '589883667243',
15
+ testing: '623580596988',
16
+ shared: '574592175410',
17
+ prod: '614948436281',
18
+ };
19
+ /**
20
+ * Extracts environment and AWS account ID from Spacelift stack ID.
21
+ *
22
+ * @param stackId - Spacelift stack identifier
23
+ * @returns Tuple of [environment, accountId]
24
+ */
25
+ function retrieveAccoundId(stackId) {
26
+ const environmentMatch = stackId.match(/-(dev|testing|prod|staging|shared)-/);
27
+ const environment = environmentMatch ? environmentMatch[1] : 'unknown';
28
+ return [environment, ACCOUNT_IDS[environment]];
29
+ }
30
+ /**
31
+ * Gets the latest version number of a Lambda function.
32
+ *
33
+ * @param lambdaARN - AWS Lambda function ARN
34
+ * @param envVars - AWS credentials environment variables
35
+ * @returns Latest version number
36
+ */
37
+ async function getLatestVersion(lambdaARN, envVars) {
38
+ logger_1.consola.log(`Retrieving latest version for function ${lambdaARN}`);
39
+ const latestVersionResult = await (0, exec_1.exec)(`aws lambda list-versions-by-function --function-name ${lambdaARN} --query 'Versions[?Version!=\`$LATEST\`] | [-1].Version' --output text`, { throwOnError: true, nodeOptions: { env: envVars } });
40
+ if (latestVersionResult.exitCode !== 0) {
41
+ logger_1.consola.error(`AWS Lambda list-versions-by-function failed: ${latestVersionResult.stderr}`);
42
+ throw new Error(`AWS Lambda list-versions-by-function failed: ${latestVersionResult.stderr}`);
43
+ }
44
+ // with pagination stdout looks like "49\n99\n109" we want to retieve the last version
45
+ return latestVersionResult.stdout.trim().split('\n').pop();
46
+ }
47
+ /**
48
+ * Runs smoke tests on Lambda functions by invoking them with empty payload.
49
+ *
50
+ * @param stackId - Spacelift stack ID to determine environment
51
+ * @param lambdaFunctions - Array of Lambda function names to test
52
+ * @param lambdaHealthCheckPayload
53
+ */
54
+ async function runSmokeTests(stackId, lambdaFunctions, lambdaHealthCheckPayload) {
55
+ const [environment, accountId] = retrieveAccoundId(stackId);
56
+ const credentials = await assumeEnvironmentSpecificRole(environment);
57
+ const envVars = getAssumedRoleEnvVars(credentials);
58
+ const smokeTestFunction = async (functionName) => {
59
+ const lambdaARN = `arn:aws:lambda:eu-west-3:${accountId}:function:${functionName}`;
60
+ const latestVersion = await getLatestVersion(lambdaARN, envVars);
61
+ const lambdaFullARN = `${lambdaARN}:${latestVersion}`;
62
+ try {
63
+ logger_1.consola.log(`Running smoke tests for ${functionName} in env ${environment}`);
64
+ const invokeResult = await (0, exec_1.exec)(`aws lambda invoke --function-name ${lambdaFullARN} --payload ${btoa(lambdaHealthCheckPayload)} /tmp/lambda-response.json`, { throwOnError: true, nodeOptions: { env: envVars } });
65
+ if (JSON.parse(invokeResult.stdout)['FunctionError']) {
66
+ const errorFile = (0, devkit_1.readJsonFile)('/tmp/lambda-response.json');
67
+ const errorMessage = errorFile.errorMessage;
68
+ const trace = errorFile.trace;
69
+ logger_1.consola.error(`AWS Lambda invoke failed for lambda ${functionName} : ${errorMessage}`, `Stack trace: ${trace}`);
70
+ throw new Error(`AWS Lambda invoke failed for lambda ${functionName}: ${errorMessage}`);
71
+ }
72
+ logger_1.consola.success(`Smoke test passed for function ${functionName} in ${environment}`);
73
+ }
74
+ catch (error) {
75
+ logger_1.consola.error(`Smoke test failed for function ${functionName} in ${environment}:`, error);
76
+ throw error;
77
+ }
78
+ };
79
+ // Run smoke tests in different envs in parallel
80
+ await Promise.all(lambdaFunctions.map(smokeTestFunction));
81
+ logger_1.consola.success(`All smoke tests passed in ${environment} environment`);
82
+ }
83
+ /**
84
+ * Creates or updates a Lambda function alias to point to latest version.
85
+ *
86
+ * @param accountId - AWS account ID
87
+ * @param lambdaARN - Lambda function ARN
88
+ * @param alias - Alias name to create/update
89
+ * @param envVars - AWS credentials environment variables
90
+ */
91
+ async function createOrUpdateLambdaAlias(accountId, lambdaARN, alias, envVars) {
92
+ const latestVersion = await getLatestVersion(lambdaARN, envVars);
93
+ // Check if alias already exists
94
+ logger_1.consola.log(`Checking if alias ${alias} exists for function ${lambdaARN}`);
95
+ const getAliasResult = await (0, exec_1.exec)(`aws lambda get-alias --function-name ${lambdaARN} --name ${alias}`, { throwOnError: false, nodeOptions: { env: envVars } });
96
+ const aliasExists = getAliasResult.exitCode === 0;
97
+ const aliasAction = aliasExists ? 'update-alias' : 'create-alias';
98
+ logger_1.consola.log(`${aliasExists ? 'Updating' : 'Creating'} alias ${alias} for function ${lambdaARN} with version ${latestVersion}`);
99
+ logger_1.consola.log(`Executing command aws lambda ${aliasAction} --function-name ${lambdaARN} --name ${alias} --function-version ${latestVersion}`);
100
+ const result = await (0, exec_1.exec)(`aws lambda ${aliasAction} --function-name ${lambdaARN} --name ${alias} --function-version ${latestVersion}`, {
101
+ throwOnError: true,
102
+ nodeOptions: { env: envVars },
103
+ });
104
+ const response = JSON.parse(result.stdout);
105
+ if (response.Name !== alias) {
106
+ throw new Error(`Lambda alias ${alias} ${aliasExists ? 'update' : 'creation'} failed for function ${lambdaARN} in ${accountId}. Response name should match alias`);
107
+ }
108
+ logger_1.consola.success(`Successfully ${aliasExists ? 'updated' : 'created'} alias ${alias} for function ${lambdaARN} with version ${latestVersion}`);
109
+ }
110
+ /**
111
+ * Assumes IAM role for environment-specific Lambda operations.
112
+ *
113
+ * @param environment - Target environment name
114
+ * @returns AWS temporary credentials
115
+ */
116
+ async function assumeEnvironmentSpecificRole(environment) {
117
+ const roleName = `invoke-lambda-nx-core`;
118
+ const accountId = ACCOUNT_IDS[environment];
119
+ const roleArn = `arn:aws:iam::${accountId}:role/${roleName}`;
120
+ logger_1.consola.log(`Assuming role ${roleName} for environment ${environment}`);
121
+ try {
122
+ const result = await (0, exec_1.exec)(`aws sts assume-role --role-arn ${roleArn} --role-session-name nx-core`, { throwOnError: true });
123
+ if (result.exitCode !== 0) {
124
+ logger_1.consola.error(`AWS STS assume-role failed: ${result.stderr}`);
125
+ throw new Error(`AWS STS assume-role failed: ${result.stderr}`);
126
+ }
127
+ if (!result.stdout) {
128
+ throw new Error('Empty response from AWS STS assume-role command');
129
+ }
130
+ let parsedResponse;
131
+ try {
132
+ parsedResponse = JSON.parse(result.stdout);
133
+ }
134
+ catch (parseError) {
135
+ logger_1.consola.error('Failed to parse AWS STS response:', result.stdout);
136
+ throw new Error(`Invalid JSON response from AWS STS: ${parseError.message}`);
137
+ }
138
+ if (!parsedResponse.Credentials) {
139
+ logger_1.consola.error('AWS STS response missing credentials:', parsedResponse);
140
+ throw new Error('AWS STS response does not contain credentials');
141
+ }
142
+ const credentials = parsedResponse.Credentials;
143
+ logger_1.consola.success(`Successfully assumed role ${roleName} for environment ${environment}`);
144
+ return {
145
+ accessKeyId: credentials.AccessKeyId,
146
+ secretAccessKey: credentials.SecretAccessKey,
147
+ sessionToken: credentials.SessionToken,
148
+ };
149
+ }
150
+ catch (error) {
151
+ logger_1.consola.error(`Failed to assume role ${roleName} for environment ${environment}`);
152
+ logger_1.consola.error(`Role ARN: ${roleArn}`);
153
+ logger_1.consola.error(`Account ID: ${accountId}`);
154
+ if (error.message?.includes('is not authorized to perform: sts:AssumeRole')) {
155
+ logger_1.consola.error(`❌ Authorization Error: Current AWS credentials are not authorized to assume the role '${roleName}'`);
156
+ logger_1.consola.info(`💡 Possible solutions:`);
157
+ logger_1.consola.info(` • Ensure your AWS credentials have the 'sts:AssumeRole' permission`);
158
+ logger_1.consola.info(` • Verify the role '${roleName}' exists in account ${accountId}`);
159
+ logger_1.consola.info(` • Check if the role's trust policy allows your current identity to assume it`);
160
+ logger_1.consola.info(` • Confirm you're using the correct AWS profile/credentials`);
161
+ }
162
+ else if (error.message?.includes('does not exist')) {
163
+ logger_1.consola.error(`❌ Role Not Found: The role '${roleName}' does not exist in account ${accountId}`);
164
+ logger_1.consola.info(`💡 Please ensure the role is created in the target AWS account`);
165
+ }
166
+ else if (error.message?.includes('Invalid identity token')) {
167
+ logger_1.consola.error(`❌ Token Error: AWS credentials are invalid or expired`);
168
+ logger_1.consola.info(`💡 Please refresh your AWS credentials`);
169
+ }
170
+ else {
171
+ logger_1.consola.error(`❌ Unexpected error: ${error.message}`);
172
+ if (error.stderr) {
173
+ logger_1.consola.error(`AWS CLI stderr: ${error.stderr}`);
174
+ }
175
+ }
176
+ throw new Error(`Role assumption failed for ${environment}: ${error.message}`);
177
+ }
178
+ }
179
+ /**
180
+ * Converts assumed role credentials to environment variables.
181
+ *
182
+ * @param credentials - AWS temporary credentials
183
+ * @returns Environment variables with AWS credentials
184
+ */
185
+ function getAssumedRoleEnvVars(credentials) {
186
+ // Only override the specific AWS credential environment variables
187
+ const baseEnv = { ...process.env };
188
+ baseEnv.AWS_ACCESS_KEY_ID = credentials.accessKeyId;
189
+ baseEnv.AWS_SECRET_ACCESS_KEY = credentials.secretAccessKey;
190
+ baseEnv.AWS_SESSION_TOKEN = credentials.sessionToken;
191
+ return baseEnv;
192
+ }
193
+ /**
194
+ * Sanitizes alias names for AWS Lambda compatibility (replaces dots with dashes).
195
+ *
196
+ * @param alias - Raw alias name
197
+ * @returns Sanitized alias name
198
+ */
199
+ function sanitizeAliasName(alias) {
200
+ // AWS Lambda alias names must satisfy: (?!^[0-9]+$)([a-zA-Z0-9-_]+)
201
+ // Replace dots with dashes and ensure it's not all numbers
202
+ return alias.replace(/\./g, '-');
203
+ }
204
+ /**
205
+ * Creates or updates aliases for multiple Lambda functions in parallel.
206
+ *
207
+ * @param stackId - Spacelift stack ID to determine environment
208
+ * @param lambdaFunctions - Array of Lambda function names
209
+ * @param alias - Alias name to create/update
210
+ */
211
+ async function createOrMoveAlias(stackId, lambdaFunctions, alias) {
212
+ const [environment, accountId] = retrieveAccoundId(stackId);
213
+ const credentials = await assumeEnvironmentSpecificRole(environment);
214
+ const envVars = getAssumedRoleEnvVars(credentials);
215
+ const sanitizedAlias = sanitizeAliasName(alias);
216
+ const addAliasFunction = async (functionName) => {
217
+ try {
218
+ logger_1.consola.log(`Add alias ${sanitizedAlias} for ${functionName} in env ${environment}`);
219
+ const lambdaARN = `arn:aws:lambda:eu-west-3:${accountId}:function:${functionName}`;
220
+ return createOrUpdateLambdaAlias(accountId, lambdaARN, sanitizedAlias, envVars);
221
+ }
222
+ catch (error) {
223
+ logger_1.consola.error(`Lambda alias ${sanitizedAlias} creation failed for function ${functionName} in ${environment}:`, error);
224
+ throw error;
225
+ }
226
+ };
227
+ // Run create alias in different envs in parallel
228
+ await Promise.all(lambdaFunctions.map(addAliasFunction));
229
+ logger_1.consola.success(`All alias created for functions in ${environment}`);
230
+ }
231
+ //# sourceMappingURL=aws-lambda.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"aws-lambda.js","sourceRoot":"","sources":["../../../../src/utils/lambda/aws-lambda.ts"],"names":[],"mappings":";;AAqBA,8CAKC;AASD,4CAoBC;AASD,sCAoDC;AAUD,8DA6CC;AAkID,8CAIC;AASD,8CAmCC;AA7VD,uCAAyC;AAEzC,yCAAqC;AACrC,6CAA0C;AAI1C,MAAM,WAAW,GAAgC;IAC/C,GAAG,EAAE,cAAc;IACnB,OAAO,EAAE,cAAc;IACvB,OAAO,EAAE,cAAc;IACvB,MAAM,EAAE,cAAc;IACtB,IAAI,EAAE,cAAc;CACrB,CAAA;AAED;;;;;GAKG;AACH,SAAgB,iBAAiB,CAAC,OAAe;IAC/C,MAAM,gBAAgB,GAAG,OAAO,CAAC,KAAK,CAAC,qCAAqC,CAAC,CAAA;IAC7E,MAAM,WAAW,GAAG,gBAAgB,CAAC,CAAC,CAAC,gBAAgB,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,CAAA;IAEtE,OAAO,CAAC,WAAW,EAAE,WAAW,CAAC,WAA0B,CAAC,CAAC,CAAA;AAC/D,CAAC;AAED;;;;;;GAMG;AACI,KAAK,UAAU,gBAAgB,CACpC,SAAiB,EACjB,OAA+B;IAE/B,gBAAO,CAAC,GAAG,CAAC,0CAA0C,SAAS,EAAE,CAAC,CAAA;IAClE,MAAM,mBAAmB,GAAG,MAAM,IAAA,WAAI,EACpC,wDAAwD,SAAS,yEAAyE,EAC1I,EAAE,YAAY,EAAE,IAAI,EAAE,WAAW,EAAE,EAAE,GAAG,EAAE,OAAO,EAAE,EAAE,CACtD,CAAA;IAED,IAAI,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T,aAAa,cAAc,QAAQ,YAAY,WAAW,WAAW,EAAE,CACxE,CAAA;YACD,MAAM,SAAS,GAAG,4BAA4B,SAAS,aAAa,YAAY,EAAE,CAAA;YAElF,OAAO,yBAAyB,CAC9B,SAAS,EACT,SAAS,EACT,cAAc,EACd,OAAO,CACR,CAAA;QACH,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,gBAAO,CAAC,KAAK,CACX,gBAAgB,cAAc,iCAAiC,YAAY,OAAO,WAAW,GAAG,EAChG,KAAK,CACN,CAAA;YACD,MAAM,KAAK,CAAA;QACb,CAAC;IACH,CAAC,CAAA;IAED,iDAAiD;IACjD,MAAM,OAAO,CAAC,GAAG,CAAC,eAAe,CAAC,GAAG,CAAC,gBAAgB,CAAC,CAAC,CAAA;IACxD,gBAAO,CAAC,OAAO,CAAC,sCAAsC,WAAW,EAAE,CAAC,CAAA;AACtE,CAAC"}
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Creates a ZIP archive of Lambda function code.
3
+ *
4
+ * @param source - Directory path containing Lambda code
5
+ * @param zipName - Name for the ZIP file
6
+ */
7
+ export declare const createZip: (source: string, zipName: string) => Promise<import("tinyexec").Output>;