@soft-artel/ci 1.2.15 → 1.3.15

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 (88) hide show
  1. package/.env +21 -0
  2. package/.eslintcache +1 -0
  3. package/.eslintignore +4 -0
  4. package/.eslintrc +246 -0
  5. package/.gitlab-ci.yml +12 -0
  6. package/_publish.sh +24 -0
  7. package/k8s/App.ts +200 -0
  8. package/k8s/DockerImage.ts +147 -0
  9. package/k8s/Node.ts +119 -0
  10. package/k8s-build.ts +175 -0
  11. package/k8s-deploy.ts +174 -0
  12. package/libs/Exception.ts +19 -0
  13. package/libs/Git.ts +199 -0
  14. package/libs/Gitlab.ts +86 -0
  15. package/libs/Jira.ts +239 -0
  16. package/libs/Project.ts +215 -0
  17. package/libs/Reporter.ts +181 -0
  18. package/libs/Shell.ts +119 -0
  19. package/libs/helpers.ts +114 -0
  20. package/libs/prototype.ts +313 -0
  21. package/package.json +1 -1
  22. package/tsconfig.json +24 -0
  23. package/upd_pkg.ts +21 -0
  24. package/xcode.ts +226 -0
  25. package/k8s/App.d.ts +0 -22
  26. package/k8s/App.d.ts.map +0 -1
  27. package/k8s/App.js +0 -150
  28. package/k8s/App.js.map +0 -1
  29. package/k8s/DockerImage.d.ts +0 -15
  30. package/k8s/DockerImage.d.ts.map +0 -1
  31. package/k8s/DockerImage.js +0 -112
  32. package/k8s/DockerImage.js.map +0 -1
  33. package/k8s/Node.d.ts +0 -17
  34. package/k8s/Node.d.ts.map +0 -1
  35. package/k8s/Node.js +0 -103
  36. package/k8s/Node.js.map +0 -1
  37. package/k8s-build.d.ts +0 -3
  38. package/k8s-build.d.ts.map +0 -1
  39. package/k8s-build.js +0 -125
  40. package/k8s-build.js.map +0 -1
  41. package/k8s-deploy.d.ts +0 -3
  42. package/k8s-deploy.d.ts.map +0 -1
  43. package/k8s-deploy.js +0 -128
  44. package/k8s-deploy.js.map +0 -1
  45. package/libs/Exception.d.ts +0 -5
  46. package/libs/Exception.d.ts.map +0 -1
  47. package/libs/Exception.js +0 -13
  48. package/libs/Exception.js.map +0 -1
  49. package/libs/Git.d.ts +0 -44
  50. package/libs/Git.d.ts.map +0 -1
  51. package/libs/Git.js +0 -160
  52. package/libs/Git.js.map +0 -1
  53. package/libs/Gitlab.d.ts +0 -12
  54. package/libs/Gitlab.d.ts.map +0 -1
  55. package/libs/Gitlab.js +0 -78
  56. package/libs/Gitlab.js.map +0 -1
  57. package/libs/Jira.d.ts +0 -31
  58. package/libs/Jira.d.ts.map +0 -1
  59. package/libs/Jira.js +0 -157
  60. package/libs/Jira.js.map +0 -1
  61. package/libs/Project.d.ts +0 -39
  62. package/libs/Project.d.ts.map +0 -1
  63. package/libs/Project.js +0 -177
  64. package/libs/Project.js.map +0 -1
  65. package/libs/Reporter.d.ts +0 -34
  66. package/libs/Reporter.d.ts.map +0 -1
  67. package/libs/Reporter.js +0 -129
  68. package/libs/Reporter.js.map +0 -1
  69. package/libs/Shell.d.ts +0 -39
  70. package/libs/Shell.d.ts.map +0 -1
  71. package/libs/Shell.js +0 -107
  72. package/libs/Shell.js.map +0 -1
  73. package/libs/helpers.d.ts +0 -29
  74. package/libs/helpers.d.ts.map +0 -1
  75. package/libs/helpers.js +0 -101
  76. package/libs/helpers.js.map +0 -1
  77. package/libs/prototype.d.ts +0 -9
  78. package/libs/prototype.d.ts.map +0 -1
  79. package/libs/prototype.js +0 -186
  80. package/libs/prototype.js.map +0 -1
  81. package/upd_pkg.d.ts +0 -3
  82. package/upd_pkg.d.ts.map +0 -1
  83. package/upd_pkg.js +0 -28
  84. package/upd_pkg.js.map +0 -1
  85. package/xcode.d.ts +0 -3
  86. package/xcode.d.ts.map +0 -1
  87. package/xcode.js +0 -163
  88. package/xcode.js.map +0 -1
package/.env ADDED
@@ -0,0 +1,21 @@
1
+ GITLAB_PASS=6e8beec72b4a70da5f3c474d379a988b
2
+ GITLAB_API_TOKEN=glpat-6zU_zXo2YNpNzLbPmqW4
3
+
4
+ CI_REGISTRY=docker.gitlab.soft-artel.com
5
+ CI_REGISTRY_USER=gitlab
6
+ CI_REGISTRY_PASSWORD=6e8beec72b4a70da5f3c474d379a988b
7
+
8
+ CI_STAGES=["alpha","prod"]
9
+ REPORTER={"token":"476910302:AAFnYmMiPDaVnnwlaMhHP0Rl9MATtiwLha8","chat_id":49385041}
10
+
11
+ CI_COMMIT_REF_NAME=dev-new-ci
12
+
13
+ CI_PROJECT_ID=593
14
+ CI_PROJECT_NAME=api
15
+ CI_PROJECT_NAMESPACE=onlc
16
+ CI_PROJECT_PATH=onlc/api
17
+ CI_PROJECT_URL=https://gitlab.soft-artel.com/onlc/api
18
+ CI_PROJECT_DIR=~/dev/onlc/api
19
+
20
+ CI_REGISTRY_IMAGE=docker.gitlab.soft-artel.com/onlc/api
21
+ K8S_ALPHA_CONFIG=~/dev/onlc/cluster/_alpha/k8s-config
package/.eslintcache ADDED
@@ -0,0 +1 @@
1
+ [{"/Users/nailine/dev/soft-artel/ci/k8s/App.ts":"1","/Users/nailine/dev/soft-artel/ci/k8s/DockerImage.ts":"2","/Users/nailine/dev/soft-artel/ci/k8s/Node.ts":"3","/Users/nailine/dev/soft-artel/ci/libs/Exception.ts":"4","/Users/nailine/dev/soft-artel/ci/libs/Git.ts":"5","/Users/nailine/dev/soft-artel/ci/libs/Gitlab.ts":"6","/Users/nailine/dev/soft-artel/ci/libs/Jira.ts":"7","/Users/nailine/dev/soft-artel/ci/libs/Project.ts":"8","/Users/nailine/dev/soft-artel/ci/libs/Reporter.ts":"9","/Users/nailine/dev/soft-artel/ci/libs/Shell.ts":"10","/Users/nailine/dev/soft-artel/ci/libs/helpers.ts":"11","/Users/nailine/dev/soft-artel/ci/sa-ci-k8s.ts":"12","/Users/nailine/dev/soft-artel/ci/sa-ci-xcode.ts":"13","/Users/nailine/dev/soft-artel/ci/upd_pkg.ts":"14","/Users/nailine/dev/soft-artel/ci/libs/prototype.ts":"15"},{"size":4698,"mtime":1652861430718,"results":"16","hashOfConfig":"17"},{"size":3793,"mtime":1652966777654,"results":"18","hashOfConfig":"17"},{"size":3665,"mtime":1652966777654,"results":"19","hashOfConfig":"17"},{"size":440,"mtime":1651661936152,"results":"20","hashOfConfig":"17"},{"size":4647,"mtime":1652832751376,"results":"21","hashOfConfig":"17"},{"size":2248,"mtime":1652832760383,"results":"22","hashOfConfig":"17"},{"size":6116,"mtime":1652686877487,"results":"23","hashOfConfig":"17"},{"size":5033,"mtime":1652966777655,"results":"24","hashOfConfig":"17"},{"size":4567,"mtime":1652966777656,"results":"25","hashOfConfig":"17"},{"size":2518,"mtime":1652686877488,"results":"26","hashOfConfig":"17"},{"size":2460,"mtime":1652686877488,"results":"27","hashOfConfig":"17"},{"size":7217,"mtime":1652966845329,"results":"28","hashOfConfig":"17"},{"size":6723,"mtime":1652795720765,"results":"29","hashOfConfig":"17"},{"size":561,"mtime":1651661936151,"results":"30","hashOfConfig":"17"},{"size":6248,"mtime":1651661936151,"results":"31","hashOfConfig":"17"},{"filePath":"32","messages":"33","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},"13qgkga",{"filePath":"34","messages":"35","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"36","messages":"37","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"38","messages":"39","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"40","messages":"41","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"42","messages":"43","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"44","messages":"45","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"46","messages":"47","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"48","messages":"49","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"50","messages":"51","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"52","messages":"53","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"54","messages":"55","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"56","messages":"57","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"58","messages":"59","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"60","messages":"61","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},"/Users/nailine/dev/soft-artel/ci/k8s/App.ts",[],"/Users/nailine/dev/soft-artel/ci/k8s/DockerImage.ts",[],"/Users/nailine/dev/soft-artel/ci/k8s/Node.ts",[],"/Users/nailine/dev/soft-artel/ci/libs/Exception.ts",[],"/Users/nailine/dev/soft-artel/ci/libs/Git.ts",[],"/Users/nailine/dev/soft-artel/ci/libs/Gitlab.ts",[],"/Users/nailine/dev/soft-artel/ci/libs/Jira.ts",[],"/Users/nailine/dev/soft-artel/ci/libs/Project.ts",[],"/Users/nailine/dev/soft-artel/ci/libs/Reporter.ts",[],"/Users/nailine/dev/soft-artel/ci/libs/Shell.ts",[],"/Users/nailine/dev/soft-artel/ci/libs/helpers.ts",[],"/Users/nailine/dev/soft-artel/ci/sa-ci-k8s.ts",[],"/Users/nailine/dev/soft-artel/ci/sa-ci-xcode.ts",[],"/Users/nailine/dev/soft-artel/ci/upd_pkg.ts",[],"/Users/nailine/dev/soft-artel/ci/libs/prototype.ts",[]]
package/.eslintignore ADDED
@@ -0,0 +1,4 @@
1
+ /node_modules
2
+ /_publish
3
+ /static
4
+ /_doc
package/.eslintrc ADDED
@@ -0,0 +1,246 @@
1
+ {
2
+ "env": { "es6": true, "node": true, "mocha": true, "browser": false },
3
+ "parser": "@typescript-eslint/parser",
4
+ "plugins": ["@typescript-eslint", "prettier", "import"],
5
+ "extends": ["plugin:@typescript-eslint/recommended", "plugin:prettier/recommended"],
6
+ "ignorePatterns": ["node_modules/", "dist/"],
7
+ "parserOptions": {
8
+ "project": "tsconfig.json",
9
+ "sourceType": "module"
10
+ },
11
+ "rules": {
12
+ // @typescript-eslint
13
+ "@typescript-eslint/member-delimiter-style": [
14
+ "error",
15
+ {
16
+ "multiline": { "delimiter": "semi", "requireLast": true },
17
+ "singleline": { "delimiter": "semi", "requireLast": false }
18
+ }
19
+ ],
20
+ "@typescript-eslint/adjacent-overload-signatures": "error",
21
+ "@typescript-eslint/array-type": "error",
22
+ "@typescript-eslint/ban-types": "error",
23
+ "@typescript-eslint/brace-style": "error",
24
+ "@typescript-eslint/explicit-module-boundary-types": "off",
25
+ // "@typescript-eslint/camelcase": ["error", { "properties": "never", "allow": ["^[A-Za-z][a-zA-Za-z]+_[A-Za-z]+$"] }],
26
+ // "@typescript-eslint/class-name-casing": "error",
27
+ "@typescript-eslint/comma-spacing": "error",
28
+ "@typescript-eslint/consistent-type-assertions": "error",
29
+ "@typescript-eslint/consistent-type-definitions": ["error", "interface"],
30
+ "@typescript-eslint/default-param-last": "error",
31
+ "@typescript-eslint/func-call-spacing": "error",
32
+ // "@typescript-eslint/interface-name-prefix": ["error", { "prefixWithI": "never" }],
33
+ // "@typescript-eslint/member-naming": "error",
34
+ // "@typescript-eslint/naming-convention": "error",
35
+ "@typescript-eslint/no-array-constructor": "error",
36
+ "@typescript-eslint/no-dupe-class-members": "error",
37
+ "@typescript-eslint/no-extra-non-null-assertion": "error",
38
+ "@typescript-eslint/no-extra-semi": "error",
39
+ "@typescript-eslint/no-for-in-array": "error",
40
+ "@typescript-eslint/no-misused-new": "error",
41
+ "@typescript-eslint/no-namespace": "error",
42
+ "@typescript-eslint/no-non-null-asserted-optional-chain": "error",
43
+ "@typescript-eslint/no-require-imports": "error",
44
+ "@typescript-eslint/no-this-alias": "error",
45
+ "@typescript-eslint/no-unnecessary-type-assertion": "error",
46
+ "@typescript-eslint/no-unused-expressions": ["error", { "allowTernary": true }],
47
+ "@typescript-eslint/no-use-before-define": "off",
48
+ "@typescript-eslint/no-var-requires": "error",
49
+ "@typescript-eslint/prefer-as-const": "error",
50
+ "@typescript-eslint/prefer-for-of": "error",
51
+ "@typescript-eslint/prefer-function-type": "error",
52
+ "@typescript-eslint/prefer-includes": "error",
53
+ "@typescript-eslint/prefer-namespace-keyword": "error",
54
+ "@typescript-eslint/prefer-optional-chain": "error",
55
+ "@typescript-eslint/prefer-regexp-exec": "error",
56
+ "@typescript-eslint/prefer-string-starts-ends-with": "error",
57
+ "@typescript-eslint/quotes": ["error", "single", { "avoidEscape": true, "allowTemplateLiterals": true }],
58
+ "@typescript-eslint/require-await": "error",
59
+ "@typescript-eslint/semi": ["error", "always"],
60
+ "@typescript-eslint/space-before-function-paren": ["error", { "asyncArrow": "always", "anonymous": "never", "named": "never" }],
61
+ "@typescript-eslint/triple-slash-reference": "error",
62
+ "@typescript-eslint/type-annotation-spacing": "error",
63
+
64
+ // @typescript-eslint:warn
65
+ "@typescript-eslint/indent": [
66
+ "warn",
67
+ "tab",
68
+ {
69
+ "SwitchCase": 1,
70
+ "FunctionDeclaration": { "parameters": "first" },
71
+ "FunctionExpression": { "parameters": "first" }
72
+ }
73
+ ],
74
+ "@typescript-eslint/member-ordering": [
75
+ "warn",
76
+ {
77
+ "default": [
78
+
79
+
80
+
81
+ "abstract-field",
82
+ "static-field",
83
+ "instance-field",
84
+ "abstract-method",
85
+ "static-method",
86
+ "constructor",
87
+ "instance-method"
88
+ ]
89
+ }
90
+ ],
91
+
92
+ // @typescript-eslint:off
93
+ "@typescript-eslint/await-thenable": "off",
94
+ "@typescript-eslint/ban-ts-ignore": "off",
95
+ "@typescript-eslint/explicit-function-return-type": "off",
96
+ "@typescript-eslint/explicit-member-accessibility": ["off", { "accessibility": "explicit" }],
97
+ "@typescript-eslint/no-empty-function": "off",
98
+ "@typescript-eslint/no-empty-interface": "off",
99
+ "@typescript-eslint/no-explicit-any": "off",
100
+ "@typescript-eslint/no-inferrable-types": ["off", { "ignoreProperties": true }],
101
+ "@typescript-eslint/no-misused-promises": "off",
102
+ "@typescript-eslint/no-unused-vars": "error",
103
+ "@typescript-eslint/unbound-method": "off",
104
+ "@typescript-eslint/unified-signatures": "off",
105
+ "@typescript-eslint/no-non-null-assertion": "off",
106
+
107
+ // import
108
+ "import/no-deprecated": "error",
109
+ "import/no-extraneous-dependencies": "error",
110
+ "import/order": [
111
+ "error",
112
+ {
113
+ "groups": [
114
+ ["builtin", "external", "internal", "unknown"],
115
+ ["parent", "sibling", "index"]
116
+ ],
117
+ "newlines-between": "always"
118
+ }
119
+ ],
120
+
121
+ // prefer-arrow
122
+ "prefer-arrow/prefer-arrow-functions": "off",
123
+
124
+ // eslint
125
+ "arrow-body-style": "error",
126
+ "comma-dangle": ["error", "always-multiline"],
127
+ "constructor-super": "error",
128
+ "curly": ["error", "multi-line"],
129
+ "dot-notation": "error",
130
+ "eol-last": "error",
131
+ "eqeqeq": "error",
132
+ "guard-for-in": "error",
133
+ "linebreak-style": ["error", "unix"],
134
+ "max-len": [
135
+ "error",
136
+ {
137
+ "code": 200,
138
+ "comments": 160,
139
+ "tabWidth": 2,
140
+ "ignoreComments": true,
141
+ "ignoreStrings": true,
142
+ "ignoreRegExpLiterals": true,
143
+ "ignoreTrailingComments": true,
144
+ "ignoreTemplateLiterals": true
145
+ }
146
+ ],
147
+ "new-parens": "error",
148
+ "no-caller": "error",
149
+ "no-cond-assign": "error",
150
+ "no-debugger": "error",
151
+ "no-duplicate-case": "error",
152
+ "no-duplicate-imports": "error",
153
+ "no-eval": "error",
154
+ "no-extra-bind": "error",
155
+ "no-fallthrough": "error",
156
+ "no-multiple-empty-lines": "error",
157
+ "no-new-func": "error",
158
+ "no-new-wrappers": "error",
159
+ "no-restricted-imports": ["error", "rxjs/Rx"],
160
+ "no-return-await": "error",
161
+ "no-sparse-arrays": "error",
162
+ "no-throw-literal": "error",
163
+ "no-trailing-spaces": [
164
+ "error",{
165
+ "skipBlankLines": true
166
+ }
167
+ ],
168
+ "no-undef-init": "error",
169
+ "no-unsafe-finally": "error",
170
+ "no-unused-expressions": "error",
171
+ "no-unused-labels": "error",
172
+ "no-var": "error",
173
+ "object-shorthand": "error",
174
+ "prefer-const": "error",
175
+ "prefer-object-spread": "error",
176
+ "prefer-rest-params": "error",
177
+ "prefer-spread": "error",
178
+ "quote-props": ["error", "consistent-as-needed"],
179
+ "radix": "error",
180
+ "space-in-parens": "error",
181
+ "spaced-comment": "error",
182
+ "unicode-bom": ["error", "never"],
183
+ "use-isnan": "error",
184
+
185
+ // eslint:warn
186
+ "no-restricted-globals": "warn",
187
+ "object-curly-newline": [
188
+ "warn",
189
+ {
190
+ "ObjectExpression": { "multiline": true, "minProperties": 4, "consistent": true },
191
+ "ImportDeclaration": { "multiline": true, "consistent": true },
192
+ "ExportDeclaration": { "multiline": true, "minProperties": 2, "consistent": true }
193
+ }
194
+ ],
195
+
196
+
197
+ // prettier
198
+ "prettier/prettier": "off",
199
+ "semi": "off",
200
+ // "prettier/prettier": [
201
+ // "warn",
202
+ // {
203
+ // "endOfLine": "lf",
204
+ // "printWidth": 140,
205
+ // "semi": true,
206
+ // "singleQuote": true,
207
+ // "tabWidth": 2,
208
+ // "trailingComma": "all",
209
+ // "useTabs": true,
210
+ // "bracketSpacing": true,
211
+ // "proseWrap": "never"
212
+ // }
213
+ // ],
214
+
215
+ // eslint:off
216
+ "array-element-newline": ["off", { "multiline": true, "minItems": 1 }],
217
+ "arrow-parens": ["off", "as-needed"],
218
+ "camelcase": "off",
219
+ "complexity": "off",
220
+ "id-blacklist": "off",
221
+ "id-match": "off",
222
+ "max-classes-per-file": "off",
223
+ "no-array-constructor": "off",
224
+ "no-bitwise": "off",
225
+ "no-console": "error",
226
+ "no-empty-function": "off",
227
+ "no-empty": "error",
228
+ "no-invalid-this": "off",
229
+ "no-shadow": ["off", { "hoist": "all" }],
230
+ "no-underscore-dangle": "off",
231
+ "no-unused-vars": "off",
232
+ "no-use-before-define": "off",
233
+ "one-var": ["off", "never"],
234
+ "require-await": "off",
235
+ "space-before-function-paren": [
236
+ "off",
237
+ {
238
+ "anonymous": "never",
239
+ "asyncArrow": "always",
240
+ "named": "never"
241
+ }
242
+ ],
243
+ "valid-typeof": "off",
244
+ "no-implicit-coercion": "error"
245
+ }
246
+ }
package/.gitlab-ci.yml ADDED
@@ -0,0 +1,12 @@
1
+ stages:
2
+ - package
3
+
4
+ public_sa-ci:
5
+ stage: package
6
+ only:
7
+ - release
8
+ script:
9
+ - 'npm publish'
10
+ - 'npm update -g sa-ci'
11
+ tags:
12
+ - ci-server
package/_publish.sh ADDED
@@ -0,0 +1,24 @@
1
+ #!/bin/bash
2
+ echo "Current: v$(cat ./package.json | grep version | grep -o '[0-9\.]\+')"
3
+
4
+ rm -rf _publish
5
+ tsc -p tsconfig.json
6
+ cp package.json _publish/
7
+
8
+ echo "Build succseed!"
9
+
10
+ cd _publish
11
+ node upd_pkg.js
12
+ PUBLISH_VERSION=$(cat ./package.json | grep version | grep -o '[0-9\.]\+')
13
+ echo "New version: v${PUBLISH_VERSION}"
14
+
15
+ npm version $PUBLISH_VERSION
16
+ npm publish
17
+ echo "v${PUBLISH_VERSION} published!"
18
+
19
+ cd ..
20
+ git commit -a -m "v${PUBLISH_VERSION} published!"
21
+ git push
22
+ git push origin HEAD:master
23
+
24
+ echo "\n\n\nv${PUBLISH_VERSION} published succseed!"
package/k8s/App.ts ADDED
@@ -0,0 +1,200 @@
1
+ import '../libs/prototype';
2
+
3
+ import Mustache from 'mustache';
4
+ import yaml from 'js-yaml';
5
+ import { promises as asyncFs } from 'fs';
6
+
7
+ import Shell from '../libs/Shell';
8
+ import { log } from '../libs/helpers';
9
+ import { Project } from '../libs/Project';
10
+ import { Exception } from '../libs/Exception';
11
+ import { DockerImage } from './DockerImage';
12
+
13
+ // ================================================================================================
14
+
15
+ export interface Config {
16
+
17
+ appFile: string;
18
+
19
+ sharedPaths?: string[];
20
+ ignorePaths?: string[];
21
+
22
+ }
23
+
24
+ // ================================================================================================
25
+
26
+ export class App{
27
+
28
+ group = '';
29
+ app = '';
30
+
31
+ name = '';
32
+ path = '';
33
+
34
+ $pathComp: string[] = [ './' ];
35
+
36
+ // ----------
37
+
38
+ constructor(path: string = ''){
39
+ const pathComp = path.split('/');
40
+
41
+ if(pathComp.length > 1){
42
+
43
+ this.group = pathComp[0];
44
+ this.app = pathComp[1];
45
+ this.name = `${this.group}-${this.app}`;
46
+ this.path = path;
47
+
48
+ this.$pathComp.push(`./${ this.group }/`);
49
+ this.$pathComp.push(`./${ this.path }/`);
50
+
51
+ }else{
52
+ this.app = path;
53
+ this.name = path;
54
+ this.path = '';
55
+ }
56
+ }
57
+
58
+ // ----------
59
+
60
+ async writeManifest(prj: Project, image: DockerImage){
61
+
62
+ const k8s_tpl_fileName = 'k8s_tpl.yaml';
63
+ const k8s_spec_fileName = 'k8s_spec.json';
64
+
65
+ // 1. Находим шаблон манифеста для app и специфицации ресурсов
66
+
67
+ let k8s_tpl = '';
68
+ const k8s_spec: Record<string, any> = {};
69
+
70
+ for (const path of this.$pathComp) {
71
+
72
+ const k8s_tplFile = await Shell.cat(path + k8s_tpl_fileName, {silent: log.debug, ignoreError:true });
73
+ k8s_tpl = k8s_tplFile && k8s_tplFile !== '' ? k8s_tplFile : k8s_tpl;
74
+
75
+ const k8s_specFile = await Shell.cat(path + k8s_spec_fileName, {silent: log.debug, ignoreError:true });
76
+ if(k8s_specFile && k8s_specFile !== ''){
77
+ try {
78
+ const sObj = JSON.parse(k8s_specFile) as Record<string, any>;
79
+ k8s_spec.mergeFrom(sObj, true);
80
+ } catch(e){
81
+ log.error(e);
82
+ }
83
+ }
84
+ }
85
+
86
+ if(k8s_tpl.length < 10){
87
+ throw new Exception(`No K8s template [${k8s_tpl_fileName}] found for app:${ this.name }`, this.$pathComp);
88
+ }
89
+
90
+ log.dbg(`${this.name} k8s specs`, k8s_spec);
91
+
92
+ // 4.2. Ходим по стейджам, формируем и сохраняем манифесты
93
+
94
+ for (const stage of prj.$stages) {
95
+
96
+ const k8s_data: Record<string, any> = {};
97
+
98
+ k8s_data.stage = stage;
99
+ k8s_data.app = this;
100
+ k8s_data.image = image;
101
+ k8s_data.prj = prj;
102
+ k8s_data.spec = k8s_spec[ stage ] || {};
103
+
104
+ if(!k8s_data.spec.replicas){
105
+ k8s_data.spec.replicas = 1;
106
+ }
107
+
108
+ // k8s_data.spec.volumeMounts = k8s_data.spec.volumes;
109
+ const manifest = Mustache.render(k8s_tpl, k8s_data);
110
+
111
+ yaml.loadAll(manifest); // Test yaml
112
+
113
+ await Shell.mkdir(`${ prj.rootPath}/_k8s/${stage}`, {ignoreError: false});
114
+ await asyncFs.writeFile(`${ prj.rootPath}/_k8s/${stage}/${this.name}.yml`, manifest);
115
+
116
+ log.dbg(`[${stage}] ${this.name} writed -> ${ prj.rootPath}/_k8s/${stage}/${this.name}.yml `);
117
+
118
+ }
119
+ }
120
+
121
+ }
122
+
123
+ // ================================================================================================
124
+
125
+ export async function getApps(prj: Project, config: Config, updatedPaths: string[], maxdepth: number = 3, ignore: string[] = ['*/_*', '*/\.*', '*/node_modules*']): Promise<{ apps: Record<string, App>; updated: string[] | undefined }>{
126
+
127
+ Shell.cd(prj.rootPath);
128
+ const appsPaths = await Shell.find(prj.rootPath, config.appFile, maxdepth, ignore);
129
+
130
+ const ignorePaths = [ ...config.ignorePaths || [], ...config.sharedPaths || [] ];
131
+
132
+ const apps: Record<string, App> = {};
133
+ const watchPaths: Record<string, string> = {};
134
+
135
+ for(const file of appsPaths.sort()) {
136
+ const path = file.replace(prj.rootPath+'/', '').replace('/' + config.appFile, '');
137
+
138
+ let skip = false;
139
+ for(const i_path of ignorePaths){
140
+ if(path.includes(i_path)){
141
+ skip = true;
142
+ break;
143
+ }
144
+ }
145
+ if(path === '' || skip){
146
+ continue;
147
+ }
148
+
149
+ const app = new App(path);
150
+
151
+ if(app.name === config.appFile){
152
+ app.name = prj.name;
153
+ app.app = prj.name;
154
+ app.group = '';
155
+ app.path = '';
156
+ }
157
+
158
+ apps[ app.name ] = app;
159
+ watchPaths[ app.path ] = app.name;
160
+ }
161
+
162
+ log.dbg(`Find apps by ${config.appFile}`, Object.keys(apps).sort());
163
+
164
+ const sharedPaths = config.sharedPaths || [];
165
+
166
+ sharedPaths.push('package.json');
167
+ sharedPaths.push('k8s_spec.json');
168
+ sharedPaths.push('k8s_tpl.yaml');
169
+ sharedPaths.push('dockerfile');
170
+
171
+ const watchPathsArr = Object.keys(watchPaths);
172
+
173
+ let appsChanged: Record<string, App> = {};
174
+
175
+ for (const file of updatedPaths) {
176
+
177
+ let allApps = false;
178
+ for(const i_path of sharedPaths){
179
+ if(file.includes(i_path)){
180
+ allApps = true;
181
+ break;
182
+ }
183
+ }
184
+ if(allApps){
185
+ appsChanged = apps;
186
+ break;
187
+ }
188
+
189
+ for(const testPath of watchPathsArr){
190
+ const appName = watchPaths[ testPath ];
191
+ if((RegExp(testPath).exec(file)) && apps[ appName ] && appsChanged[ appName ] === undefined){
192
+ appsChanged[ appName ] = apps[ appName ];
193
+ }
194
+ }
195
+ }
196
+
197
+ const changed = Object.keys(appsChanged);
198
+ return { apps, updated: changed.length > 0 ? changed : undefined };
199
+
200
+ }
@@ -0,0 +1,147 @@
1
+ import fs from 'fs';
2
+
3
+ import { log, md5, resolvePath } from '../libs/helpers';
4
+ import Shell from '../libs/Shell';
5
+
6
+ const ENV = process.env;
7
+
8
+ // ========================================================
9
+
10
+ type DockerImagePrebuildAction = (img: DockerImage) => void;
11
+ const PREBUILD: Record<string, DockerImagePrebuildAction> = {};
12
+
13
+ export class DockerImage{
14
+
15
+ path = '';
16
+ key = '';
17
+
18
+ srcImage = '';
19
+
20
+ tag = '';
21
+ fullTag = '';
22
+
23
+ $prebuild_typed?: DockerImagePrebuildAction = undefined;
24
+
25
+ // -----------
26
+
27
+ constructor(path: string, ver: string, build: number){
28
+ this.path = resolvePath(path);
29
+
30
+ const dockerfile = fs.readFileSync(this.path + '/dockerfile', 'utf8');
31
+ this.key = md5(dockerfile);
32
+
33
+ const dockerImage = /FROM (.+)/.exec(dockerfile);
34
+ if(!dockerImage || dockerImage.length < 2){
35
+ throw new Error(`Wrong dockerfile format:\n${dockerfile}`);
36
+ }
37
+
38
+ this.srcImage = dockerImage[1];
39
+
40
+ const dockerName = /#[ ]?IMAGE NAME (.+)/.exec(dockerfile);
41
+ const name = dockerName && dockerName.length > 1 ? dockerName[1] : ENV.CI_PROJECT_NAME || this.key;
42
+
43
+ // api-v1.2:#321
44
+ this.tag = `${name}-v${ver}:${build}`;
45
+ this.fullTag = `${ ENV.CI_REGISTRY_IMAGE }/${ this.tag }`;
46
+
47
+ const dockerType = /#[ ]?IMAGE TYPE (.+)/.exec(dockerfile);
48
+ const type = dockerType && dockerType.length > 1 ? dockerType[1].toLowerCase() : this.srcImage.split(':')[0].toLowerCase();
49
+
50
+ this.$prebuild_typed = PREBUILD[ type ];
51
+ }
52
+
53
+ // -----------
54
+
55
+ async prebuild(){
56
+ if(!this.$prebuild_typed){
57
+ throw new Error(`No prebuild action for ${ this.tag }`);
58
+ }
59
+ await this.$prebuild_typed(this);
60
+ }
61
+
62
+ async build(){
63
+ Shell.cd(this.path);
64
+ log.info(`Build docker image: ${ this.tag }`);
65
+
66
+ await Shell.exec(`docker build --platform amd64 -t ${ this.fullTag } -f ${ this.path }/dockerfile ${ this.path }/.`);
67
+ }
68
+
69
+ async push(){
70
+ await Shell.execRepeat(`docker login -u ${ ENV.CI_REGISTRY_USER } -p ${ ENV.CI_REGISTRY_PASSWORD } ${ ENV.CI_REGISTRY }`);
71
+
72
+ log.info(`Push docker image: ${ this.tag } to registry`);
73
+ await Shell.execRepeat(`docker push ${ this.fullTag }`);
74
+
75
+ log.dbg(`Clear local docker image: ${ this.tag }`);
76
+ await Shell.exec(`docker rmi -f ${ this.fullTag }`);
77
+ }
78
+ }
79
+
80
+ // ========================================================
81
+
82
+ PREBUILD.nginx = async (img: DockerImage) => {
83
+ Shell.cd(img.path);
84
+
85
+ const mounts = { '/etc/nginx':`${ img.path }/nginx` };
86
+
87
+ log.info(`Test nginx configs`);
88
+ await run(img.srcImage, 'nginx -t', mounts);
89
+ await run('yandex/gixy', 'yandex/gixy /etc/nginx/nginx.conf', mounts);
90
+
91
+ log.info(`Nginx config file:`)
92
+ log.info( await Shell.cat(`${ img.path }/nginx/nginx.conf`) )
93
+
94
+ };
95
+
96
+ // ------------
97
+
98
+ PREBUILD.gateway = async (img: DockerImage) => {
99
+ Shell.cd(img.path);
100
+
101
+ const mounts = { '/etc/nginx':`${ img.path }/nginx`, '/etc/certs':`${ img.path }/certs` };
102
+
103
+ log.info(`Test gateway nginx configs`);
104
+ await run(img.srcImage, 'nginx -t', mounts);
105
+ await run('yandex/gixy', 'yandex/gixy /etc/nginx/nginx.conf', mounts);
106
+
107
+ log.info(`Nginx config file:`);
108
+ log.info(await Shell.cat(`${ img.path }/nginx/nginx.conf`))
109
+
110
+ };
111
+
112
+ // ------------
113
+
114
+ PREBUILD.spa = async (img: DockerImage) => {
115
+ Shell.cd(img.path);
116
+ await PREBUILD.nginx(img);
117
+ log.info(`Test and Distrib WEB SPA sources`);
118
+
119
+ // ? надо ли собирать веб внутри контейнера?!
120
+ // const mounts = { '/etc/nginx':`${ img.path }/nginx` }
121
+ // await run( img.srcImage, 'nginx -t', mounts );
122
+
123
+ await Shell.exec(`npm run distrib`);
124
+ };
125
+
126
+ // ------------
127
+
128
+ PREBUILD.node = async (img: DockerImage) => {
129
+ Shell.cd(img.path);
130
+ log.info(`Test and Distrib Node sources`);
131
+ await Shell.exec(`npm run distrib`);
132
+ };
133
+
134
+ // ========================================================
135
+
136
+ async function run(srcImage: string, cmd: string, mnt?: Record<string, string>){
137
+ let extCmd = `docker run --rm`;
138
+
139
+ for (const path in mnt) {
140
+ if(mnt.hasOwnProperty(path)) {
141
+ extCmd += ` -v ${mnt[path]}:${path}`;
142
+ }
143
+ }
144
+
145
+ extCmd += ` ${ srcImage } ${ cmd }`;
146
+ await Shell.exec(`${ extCmd }`);
147
+ }