@certik/skynet 0.10.28 → 0.10.31

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/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.10.31
4
+
5
+ - `api` app bug fix
6
+
7
+ ## 0.10.30
8
+
9
+ - Changed `api` app deployment to service type for rolling updates
10
+
11
+ ## 0.10.29
12
+
13
+ - Added `serve.instances` parameter to `api` library to support multiple instances
14
+
3
15
  ## 0.10.28
4
16
 
5
17
  - Fixed `deploy` library aws region bug
package/api.js CHANGED
@@ -46,12 +46,29 @@ const apiKeyMiddleware = (key) => {
46
46
  return;
47
47
  }
48
48
 
49
- if (apiKey !== key) {
50
- inline.log("request has an invalid api key");
49
+ // key can be either a string or a map with multiple keys
50
+ if (typeof key === "string") {
51
+ if (apiKey !== key) {
52
+ inline.log("request has an invalid api key");
51
53
 
52
- res.status(400).send("invalid api key");
54
+ res.status(400).send("invalid api key");
53
55
 
54
- return;
56
+ return;
57
+ }
58
+
59
+ inline.log(`requested by valid key ${key.slice(0, 6)}`);
60
+ } else {
61
+ const name = key[apiKey];
62
+
63
+ if (!name) {
64
+ inline.log("request has an invalid api key");
65
+
66
+ res.status(400).send("invalid api key");
67
+
68
+ return;
69
+ }
70
+
71
+ inline.log(`requested by authorized user ${name}`);
55
72
  }
56
73
 
57
74
  next();
@@ -93,7 +110,9 @@ ${getSelectorDesc(selector)}
93
110
 
94
111
  const { verbose, ...selectorFlags } = cli.flags;
95
112
 
96
- await useLock({ name: getJobName(name, selectorFlags), ttl: 50, verbose });
113
+ if (!serve.instances || serve.instances === 1) {
114
+ await useLock({ name: getJobName(name, selectorFlags), ttl: 50, verbose });
115
+ }
97
116
 
98
117
  // for health check
99
118
  app.get("/", (req, res) => {
package/app.d.ts CHANGED
@@ -18,6 +18,7 @@ export type Serve = {
18
18
  apiKey: string;
19
19
  cpu: number;
20
20
  mem: number;
21
+ instances: number;
21
22
  }
22
23
 
23
24
  export type Consume = {
package/app.js CHANGED
@@ -655,7 +655,14 @@ function api({ name, routes, serve, beforeListen, env = {}, region = "us-east-1"
655
655
  selector,
656
656
  region,
657
657
  env,
658
- schedule: "@minutely",
658
+ type: "service",
659
+ restart: {
660
+ attempts: 3,
661
+ delay: "15s",
662
+ mode: "fail",
663
+ interval: "30m",
664
+ },
665
+ count: serve.instances,
659
666
  cpu: serve.cpu,
660
667
  mem: serve.mem,
661
668
  service: {
package/deploy.d.ts CHANGED
@@ -14,6 +14,8 @@ type CreateDeployBaseParams = {
14
14
  selector: Selector | undefined,
15
15
  env: Env | undefined,
16
16
  region: string | undefined,
17
+ type: string | undefined,
18
+ count: number | undefined,
17
19
  check: Check,
18
20
  }
19
21
 
package/deploy.js CHANGED
@@ -46,17 +46,19 @@ const genConfig = ({
46
46
  workingDirectory,
47
47
  cmd,
48
48
  cron,
49
+ count,
49
50
  restart,
50
51
  cpu,
51
52
  mem,
52
53
  service,
53
54
  additionalEnv = [],
55
+ type = "batch",
54
56
  region = "us-east-1",
55
57
  isProduction,
56
58
  }) => `job "${jobName}" {
57
59
  datacenters = ["${region}"]
58
60
 
59
- type = "batch"
61
+ type = "${type}"
60
62
 
61
63
  ${
62
64
  cron
@@ -79,6 +81,17 @@ const genConfig = ({
79
81
  }
80
82
 
81
83
  group "default" {
84
+ ${count && count > 1 ? `count = ${count}` : ""}
85
+ ${
86
+ count && count > 1
87
+ ? `# Rolling Update
88
+ update {
89
+ max_parallel = 1
90
+ min_healthy_time = "10s"
91
+ }`
92
+ : ""
93
+ }
94
+
82
95
  reschedule {
83
96
  attempts = 0
84
97
  unlimited = false
@@ -511,7 +524,9 @@ function createDeploy({
511
524
  bin = "bin/indexer",
512
525
  selector = {},
513
526
  region = "us-east-1",
527
+ type = "batch",
514
528
  env = {},
529
+ count,
515
530
  check,
516
531
  schedule,
517
532
  restart,
@@ -542,10 +557,12 @@ function createDeploy({
542
557
  const nomadJobDefinition = genConfig({
543
558
  jobName,
544
559
  cron: INTERVAL_ALIASES[cron] || cron,
560
+ count,
545
561
  restart,
546
562
  workingDirectory,
547
563
  additionalEnv: env,
548
564
  region,
565
+ type,
549
566
  cmd: `${bin} ${args}`,
550
567
  cpu,
551
568
  mem,
package/examples/api CHANGED
@@ -64,6 +64,7 @@ const app = api({
64
64
  apiKey: process.env.EXAMPLE_API_KEY,
65
65
  cpu: 600,
66
66
  mem: 200,
67
+ instances: 3, // run 3 instances
67
68
  },
68
69
  });
69
70
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@certik/skynet",
3
- "version": "0.10.28",
3
+ "version": "0.10.31",
4
4
  "description": "Skynet Shared JS library",
5
5
  "main": "index.js",
6
6
  "author": "CertiK Engineering",