@geode/opengeodeweb-front 10.29.0-rc.3 → 10.29.0-rc.5

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.
@@ -13,6 +13,7 @@ import { executablePath } from "./path.js";
13
13
 
14
14
  const MILLISECONDS_PER_SECOND = 1000;
15
15
  const DEFAULT_TIMEOUT_SECONDS = 45;
16
+ const MAX_PORT_RETRIES = 1;
16
17
 
17
18
  async function runScript(
18
19
  execPath,
@@ -51,7 +52,11 @@ async function runScript(
51
52
  }
52
53
  }
53
54
 
54
- async function runBack(execName, execPath, args = {}) {
55
+ function isPortInUseError(errorMessage) {
56
+ return /EADDRINUSE|address already in use|port already in use/iu.test(errorMessage);
57
+ }
58
+
59
+ async function runBack(execName, execPath, args = {}, attempts = 0) {
55
60
  const { projectFolderPath } = args;
56
61
  if (!projectFolderPath) {
57
62
  throw new Error("projectFolderPath is required");
@@ -60,44 +65,68 @@ async function runBack(execName, execPath, args = {}) {
60
65
  if (!uploadFolderPath) {
61
66
  uploadFolderPath = path.join(projectFolderPath, "uploads");
62
67
  }
63
- const port = await getAvailablePort();
64
- const backArgs = [
65
- "--port",
66
- String(port),
67
- "--project_folder_path",
68
- projectFolderPath,
69
- "--upload_folder_path",
70
- uploadFolderPath,
71
- "--allowed_origins",
72
- "http://localhost:*",
73
- "--timeout",
74
- "0",
75
- ];
76
- if (process.env.NODE_ENV === "development" || !process.env.NODE_ENV) {
77
- backArgs.push("--debug");
68
+ try {
69
+ const port = await getAvailablePort();
70
+ const backArgs = [
71
+ "--port",
72
+ String(port),
73
+ "--project_folder_path",
74
+ projectFolderPath,
75
+ "--upload_folder_path",
76
+ uploadFolderPath,
77
+ "--allowed_origins",
78
+ "http://localhost:*",
79
+ "--timeout",
80
+ "0",
81
+ ];
82
+ if (process.env.NODE_ENV === "development" || !process.env.NODE_ENV) {
83
+ backArgs.push("--debug");
84
+ }
85
+ console.log("runBack", execPath, execName, backArgs);
86
+ await runScript(execPath, execName, backArgs, "Serving Flask app");
87
+ return port;
88
+ } catch (error) {
89
+ if (!isPortInUseError(error)) {
90
+ console.log("runBack error", error);
91
+ throw error;
92
+ }
93
+ if (attempts <= MAX_PORT_RETRIES) {
94
+ console.log("Retrying runBack on conflicting port", port);
95
+ const port = await runBack(execName, execPath, args, attempts + 1);
96
+ return port;
97
+ }
78
98
  }
79
- console.log("runBack", execPath, execName, backArgs);
80
- await runScript(execPath, execName, backArgs, "Serving Flask app");
81
- return port;
82
99
  }
83
100
 
84
- async function runViewer(execName, execPath, args = {}) {
101
+ async function runViewer(execName, execPath, args = {}, attempts = 0) {
85
102
  const { projectFolderPath } = args;
86
103
  if (!projectFolderPath) {
87
104
  throw new Error("projectFolderPath is required");
88
105
  }
89
- const port = await getAvailablePort();
90
- const viewerArgs = [
91
- "--port",
92
- String(port),
93
- "--project_folder_path",
94
- projectFolderPath,
95
- "--timeout",
96
- "0",
97
- ];
98
- console.log("runViewer", execPath, execName, viewerArgs);
99
- await runScript(execPath, execName, viewerArgs, "Starting factory");
100
- return port;
106
+ try {
107
+ const port = await getAvailablePort();
108
+ const viewerArgs = [
109
+ "--port",
110
+ String(port),
111
+ "--project_folder_path",
112
+ projectFolderPath,
113
+ "--timeout",
114
+ "0",
115
+ ];
116
+ console.log("runViewer", execPath, execName, viewerArgs);
117
+ await runScript(execPath, execName, viewerArgs, "Starting factory");
118
+ return port;
119
+ } catch (error) {
120
+ if (!isPortInUseError(error)) {
121
+ console.log("runBack error", error);
122
+ throw error;
123
+ }
124
+ if (attempts <= MAX_PORT_RETRIES) {
125
+ console.log("Retrying runViewer on conflicting port", port);
126
+ const port = await runViewer(execName, execPath, args, attempts + 1);
127
+ return port;
128
+ }
129
+ }
101
130
  }
102
131
 
103
132
  function addMicroserviceMetadatas(projectFolderPath, serviceObj) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@geode/opengeodeweb-front",
3
- "version": "10.29.0-rc.3",
3
+ "version": "10.29.0-rc.5",
4
4
  "description": "OpenSource Vue/Nuxt/Pinia/Vuetify framework for web applications",
5
5
  "homepage": "https://github.com/Geode-solutions/OpenGeodeWeb-Front",
6
6
  "bugs": {
@@ -6,7 +6,7 @@ import { GoogleAuth } from "google-auth-library";
6
6
  import { ServicesClient } from "@google-cloud/run";
7
7
 
8
8
  // Local imports
9
- import { artifactImages, requestConfig } from "@ogw_server/utils/cloud";
9
+ import { artifactImage, requestConfig } from "@ogw_server/utils/cloud";
10
10
 
11
11
  export default defineEventHandler(async (event) => {
12
12
  try {
@@ -23,8 +23,8 @@ export default defineEventHandler(async (event) => {
23
23
  scopes: ["https://www.googleapis.com/auth/cloud-platform"],
24
24
  });
25
25
  const authClient = await auth.getClient();
26
- const [routerImage, backImage, viewerImage] = await artifactImages(parent, authClient);
27
- const request = requestConfig(parent, routerImage, backImage, viewerImage, email, projectName);
26
+ const image = await artifactImage(parent, authClient);
27
+ const request = requestConfig(parent, image, email, projectName);
28
28
  console.log({ request });
29
29
  const runClient = new ServicesClient({ authClient });
30
30
  const [operation] = await runClient.createService(request);
@@ -5,11 +5,16 @@ import { google } from "googleapis";
5
5
 
6
6
  // Local imports
7
7
 
8
- async function artifactImage(registry, parent, repo) {
8
+ async function artifactImage(parent, authClient) {
9
+ const projectName = process.env.PROJECT;
10
+ const registry = google.artifactregistry({
11
+ version: "v1",
12
+ auth: authClient,
13
+ });
9
14
  const branch = process.env.NETLIFY_BRANCH;
10
15
  const [_, projectId] = parent.split("/");
11
16
  const repository = `${parent}/repositories/github/packages/`;
12
- const name = `${repository}${repo}/tags/${branch}`;
17
+ const name = `${repository}${projectName}/tags/${branch}`;
13
18
  console.log({ name });
14
19
  const response = await registry.projects.locations.repositories.packages.tags.get({
15
20
  name,
@@ -17,24 +22,11 @@ async function artifactImage(registry, parent, repo) {
17
22
  console.log({ response });
18
23
  const digest = response.data.version.split("/").pop();
19
24
  const artifactRegistry = `europe-west9-docker.pkg.dev/${projectId}/github`;
20
- const image = `${artifactRegistry}/${repo}@${digest}`;
21
- console.log("Found image for", repo, image);
25
+ const image = `${artifactRegistry}/${projectName}@${digest}`;
26
+ console.log("Found image for", projectName, image);
22
27
  return image;
23
28
  }
24
29
 
25
- function artifactImages(parent, authClient) {
26
- const projectName = process.env.PROJECT;
27
- const registry = google.artifactregistry({
28
- version: "v1",
29
- auth: authClient,
30
- });
31
- return Promise.all([
32
- artifactImage(registry, parent, "opengeodeweb-router"),
33
- artifactImage(registry, parent, `${projectName}-back`),
34
- artifactImage(registry, parent, `${projectName}-viewer`),
35
- ]);
36
- }
37
-
38
30
  function sanitizeLabelValue(label) {
39
31
  console.log("label", label);
40
32
  const maxLabelLength = 63;
@@ -44,47 +36,32 @@ function sanitizeLabelValue(label) {
44
36
  .slice(0, maxLabelLength);
45
37
  }
46
38
 
47
- // oxlint-disable-next-line max-lines-per-function
48
- function requestConfig(parent, routerImage, backImage, viewerImage, email, projectName) {
39
+ function requestConfig(parent, image, email, projectName) {
49
40
  const resources = {
50
41
  limits: {
51
42
  cpu: "1000m",
52
43
  memory: "1Gi",
53
44
  },
54
45
  };
55
- const volumeMounts = {
56
- name: "project",
57
- mountPath: "/project",
46
+ const labels = {
47
+ user: sanitizeLabelValue(email),
48
+ project: sanitizeLabelValue(projectName),
58
49
  };
59
50
  return {
60
51
  parent,
61
52
  service: {
62
53
  ingress: "INGRESS_TRAFFIC_ALL",
63
54
  invokerIamDisabled: true,
64
- labels: {
65
- user: sanitizeLabelValue(email),
66
- project: sanitizeLabelValue(projectName),
67
- },
55
+ labels,
68
56
  scaling: {
69
57
  scalingMode: "MANUAL",
70
58
  manualInstanceCount: 1,
71
59
  },
72
60
  template: {
73
- labels: {
74
- user: sanitizeLabelValue(email),
75
- project: sanitizeLabelValue(projectId),
76
- },
77
- volumes: [
78
- {
79
- name: "project",
80
- emptyDir: {
81
- medium: "MEMORY",
82
- },
83
- },
84
- ],
61
+ labels,
85
62
  containers: [
86
63
  {
87
- image: routerImage,
64
+ image,
88
65
  ports: [
89
66
  {
90
67
  containerPort: 80,
@@ -106,20 +83,10 @@ function requestConfig(parent, routerImage, backImage, viewerImage, email, proje
106
83
  failureThreshold: 30,
107
84
  },
108
85
  },
109
- {
110
- image: backImage,
111
- resources,
112
- volumeMounts: [volumeMounts],
113
- },
114
- {
115
- image: viewerImage,
116
- resources,
117
- volumeMounts: [volumeMounts],
118
- },
119
86
  ],
120
87
  },
121
88
  },
122
89
  };
123
90
  }
124
91
 
125
- export { artifactImages, requestConfig };
92
+ export { artifactImage, requestConfig };