@catladder/cli 1.18.0 → 1.19.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -16,7 +16,7 @@
16
16
  "catladder": "./bin/catladder"
17
17
  },
18
18
  "dependencies": {
19
- "@catladder/pipeline": "1.18.0",
19
+ "@catladder/pipeline": "1.19.1",
20
20
  "@kubernetes/client-node": "^0.16.2",
21
21
  "child-process-promise": "^2.2.1",
22
22
  "command-exists-promise": "^2.0.2",
@@ -55,5 +55,5 @@
55
55
  "eslint": "^8.7.0",
56
56
  "typescript": "^4.5.4"
57
57
  },
58
- "version": "1.18.0"
58
+ "version": "1.19.1"
59
59
  }
@@ -152,22 +152,25 @@ const doItFor = async (
152
152
  if (hasBitwarden()) {
153
153
  // add cloud sql secret if needed.
154
154
  // TODO: this is legacy, in the future we want to have one service account per app
155
-
156
- const context = await getPipelineContextByChoice(env, componentName);
157
- if (
158
- context.componentConfig.deploy &&
159
- context.componentConfig.deploy.values?.cloudsql?.enabled
160
- ) {
161
- await upsertAllVariables(
162
- instance,
163
- {
164
- cloudsqlProxyCredentials: await readPass(
165
- GOOGLE_CLOUD_SQL_PASS_PATH
166
- ),
167
- },
168
- env,
169
- componentName
170
- );
155
+ try {
156
+ const context = await getPipelineContextByChoice(env, componentName);
157
+ if (
158
+ context.componentConfig.deploy &&
159
+ context.componentConfig.deploy.values?.cloudsql?.enabled
160
+ ) {
161
+ await upsertAllVariables(
162
+ instance,
163
+ {
164
+ cloudsqlProxyCredentials: await readPass(
165
+ GOOGLE_CLOUD_SQL_PASS_PATH
166
+ ),
167
+ },
168
+ env,
169
+ componentName
170
+ );
171
+ }
172
+ } catch (e) {
173
+ // ignore atm
171
174
  }
172
175
  }
173
176
  instance.log("✅ " + env + ":" + componentName);
@@ -24,10 +24,8 @@ import commandPortForward from "./commandPortForward";
24
24
  import commandTriggerCronjob from "./commandTriggerCronjob";
25
25
 
26
26
  import commandOpenGrafanaPod from "./commandOpenGrafanaPod";
27
- import commandReloadConfig from "./commandReloadConfig";
28
27
 
29
28
  export default async (vorpal: Vorpal) => {
30
- commandReloadConfig(vorpal);
31
29
  commandSetup(vorpal);
32
30
 
33
31
  commandEnvVars(vorpal);
@@ -4,7 +4,6 @@ import { writeFile } from "fs-extra";
4
4
  import { dump } from "js-yaml";
5
5
  import { format } from "prettier";
6
6
  import { CommandInstance } from "vorpal";
7
- import { reloadConfig } from "../../../config/getProjectConfig";
8
7
  import { getGitRoot } from "../../../utils/projects";
9
8
 
10
9
  export const writeConfig = async (
@@ -67,7 +66,6 @@ export const writeConfig = async (
67
66
  );
68
67
  await exec("git add " + file);
69
68
  }
70
- await reloadConfig();
71
69
  vorpal.log("done!");
72
70
  vorpal.log("");
73
71
  };
package/src/catenv.ts CHANGED
@@ -1,4 +1,7 @@
1
1
  import catenv from "./apps/catenv/catenv";
2
2
  import { $ } from "zx";
3
3
  $.verbose = false;
4
- catenv();
4
+ catenv().then(() => {
5
+ // we have to exit manually, because we have some file watches
6
+ process.exit();
7
+ });
@@ -4,29 +4,41 @@ import {
4
4
  getEnvironment as _getEnvironment,
5
5
  createContext,
6
6
  getSecretVarName,
7
+ Config,
7
8
  } from "@catladder/pipeline";
8
9
 
9
- import { Command, CommandInstance } from "vorpal";
10
+ import { CommandInstance } from "vorpal";
10
11
  import { getAllVariables, getVariableValueByRawName } from "../utils/gitlab";
11
- import memoizee from "memoizee";
12
+
12
13
  import { getGitRoot } from "../utils/projects";
13
14
  import { readYaml } from "../utils/files";
14
- // currently cant change
15
-
16
- export const getProjectConfig = memoizee(
17
- async () => {
18
- try {
19
- const gitRoot = await getGitRoot();
20
- return readConfigSync(gitRoot);
21
- } catch (e) {
22
- // ignore
23
- return null;
24
- }
25
- },
26
- { promise: true }
27
- );
28
-
29
- export const reloadConfig = () => getProjectConfig.clear();
15
+ import { watch } from "fs";
16
+
17
+ let currentConfig: Config = null;
18
+
19
+ // reload the config on change
20
+ const reloadConfigAndObserve = async () => {
21
+ const gitRoot = await getGitRoot();
22
+ const result = readConfigSync(gitRoot);
23
+ if (!result) {
24
+ // can't do anything, there is no config
25
+ return;
26
+ }
27
+ const { config, path } = result;
28
+ const watcher = watch(path, () => {
29
+ watcher.close();
30
+ reloadConfigAndObserve();
31
+ });
32
+ currentConfig = config;
33
+ };
34
+
35
+ export const getProjectConfig = async () => {
36
+ if (!currentConfig) {
37
+ // initially
38
+ await reloadConfigAndObserve();
39
+ }
40
+ return currentConfig;
41
+ };
30
42
 
31
43
  export const getGitlabCiFilePath = async () => {
32
44
  const gitRoot = await getGitRoot();
@@ -99,6 +111,7 @@ export const getAllPipelineContexts = async () => {
99
111
 
100
112
  export const getEnvironment = async (env: string, componentName: string) => {
101
113
  const config = await getProjectConfig();
114
+
102
115
  return _getEnvironment(config, componentName, env);
103
116
  };
104
117
 
@@ -1,3 +0,0 @@
1
- import Vorpal from "vorpal";
2
- declare const _default: (vorpal: Vorpal) => Promise<Vorpal.Command>;
3
- export default _default;
@@ -1,62 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- var __generator = (this && this.__generator) || function (thisArg, body) {
12
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
- function verb(n) { return function (v) { return step([n, v]); }; }
15
- function step(op) {
16
- if (f) throw new TypeError("Generator is already executing.");
17
- while (_) try {
18
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
- if (y = 0, t) op = [op[0] & 2, t.value];
20
- switch (op[0]) {
21
- case 0: case 1: t = op; break;
22
- case 4: _.label++; return { value: op[1], done: false };
23
- case 5: _.label++; y = op[1]; op = [0]; continue;
24
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
- default:
26
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
- if (t[2]) _.ops.pop();
31
- _.trys.pop(); continue;
32
- }
33
- op = body.call(thisArg, _);
34
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
- }
37
- };
38
- exports.__esModule = true;
39
- var getProjectConfig_1 = require("../../../../config/getProjectConfig");
40
- var showProjectBanner_1 = require("./utils/showProjectBanner");
41
- exports["default"] = (function (vorpal) { return __awaiter(void 0, void 0, void 0, function () {
42
- return __generator(this, function (_a) {
43
- return [2 /*return*/, vorpal
44
- .command("project-reload-config", "reloads the config")
45
- .action(function () {
46
- return __awaiter(this, void 0, void 0, function () {
47
- return __generator(this, function (_a) {
48
- switch (_a.label) {
49
- case 0: return [4 /*yield*/, (0, getProjectConfig_1.reloadConfig)()];
50
- case 1:
51
- _a.sent();
52
- return [4 /*yield*/, (0, showProjectBanner_1.showProjectBanner)(vorpal)];
53
- case 2:
54
- _a.sent();
55
- return [2 /*return*/];
56
- }
57
- });
58
- });
59
- })];
60
- });
61
- }); });
62
- //# sourceMappingURL=commandReloadConfig.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"commandReloadConfig.js","sourceRoot":"","sources":["../../../../../src/apps/cli/commands/project/commandReloadConfig.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,wEAAmE;AACnE,+DAA8D;AAE9D,sBAAe,UAAO,MAAc;;QAClC,sBAAA,MAAM;iBACH,OAAO,CAAC,uBAAuB,EAAE,oBAAoB,CAAC;iBAEtD,MAAM,CAAC;;;;oCACN,qBAAM,IAAA,+BAAY,GAAE,EAAA;;gCAApB,SAAoB,CAAC;gCACrB,qBAAM,IAAA,qCAAiB,EAAC,MAAM,CAAC,EAAA;;gCAA/B,SAA+B,CAAC;;;;;aACjC,CAAC,EAAA;;KAAA,EAAC"}
@@ -1,12 +0,0 @@
1
- import Vorpal from "vorpal";
2
- import { reloadConfig } from "../../../../config/getProjectConfig";
3
- import { showProjectBanner } from "./utils/showProjectBanner";
4
-
5
- export default async (vorpal: Vorpal) =>
6
- vorpal
7
- .command("project-reload-config", "reloads the config")
8
-
9
- .action(async function () {
10
- await reloadConfig();
11
- await showProjectBanner(vorpal);
12
- });