@certik/skynet 0.10.27 → 0.10.30

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,6 +1,14 @@
1
1
  # Changelog
2
2
 
3
- ## 0.10.27
3
+ ## 0.10.30
4
+
5
+ - Changed `api` app deployment to service type for rolling updates
6
+
7
+ ## 0.10.29
8
+
9
+ - Added `serve.instances` parameter to `api` library to support multiple instances
10
+
11
+ ## 0.10.28
4
12
 
5
13
  - Fixed `deploy` library aws region bug
6
14
 
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.count || serve.count === 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
@@ -170,7 +183,6 @@ EOH
170
183
  # available to the task when it runs.
171
184
  env {
172
185
  SKYNET_ENVIRONMENT="${isProduction ? "prd" : "dev"}"
173
- AWS_REGION="${region}"
174
186
  }
175
187
 
176
188
  # Specify the maximum resources required to run the task,
@@ -512,7 +524,9 @@ function createDeploy({
512
524
  bin = "bin/indexer",
513
525
  selector = {},
514
526
  region = "us-east-1",
527
+ type = "batch",
515
528
  env = {},
529
+ count,
516
530
  check,
517
531
  schedule,
518
532
  restart,
@@ -543,10 +557,12 @@ function createDeploy({
543
557
  const nomadJobDefinition = genConfig({
544
558
  jobName,
545
559
  cron: INTERVAL_ALIASES[cron] || cron,
560
+ count,
546
561
  restart,
547
562
  workingDirectory,
548
563
  additionalEnv: env,
549
564
  region,
565
+ type,
550
566
  cmd: `${bin} ${args}`,
551
567
  cpu,
552
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.27",
3
+ "version": "0.10.30",
4
4
  "description": "Skynet Shared JS library",
5
5
  "main": "index.js",
6
6
  "author": "CertiK Engineering",