@ossy/deployment-tools 0.0.5 → 0.0.8

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/dist/index.js CHANGED
@@ -28393,9 +28393,16 @@ function fixResponseChunkedTransferBadEnding(request, errorCallback) {
28393
28393
  });
28394
28394
  }
28395
28395
 
28396
+ ;// CONCATENATED MODULE: ./src/config.js
28397
+ const domain = process.env.DEPLOYMENT_TOOLS_DOMAIN || 'localhost'
28398
+ const environmentName = process.env.DEPLOYMENT_TOOLS_ENVIRONMENT_NAME || 'dev'
28399
+ const ciSubDomain = process.env.DEPLOYMENT_TOOLS_CI_SUB_DOMAIN || 'ci'
28400
+ const port = process.env.DEPLOYMENT_TOOLS_PORT || 3000
28401
+
28396
28402
  ;// CONCATENATED MODULE: ./src/caddy-client.js
28397
28403
 
28398
28404
 
28405
+
28399
28406
  const Matchers = {
28400
28407
  host: host => ({ host: [host] }),
28401
28408
  path: path => ({ path: [path] })
@@ -28412,64 +28419,6 @@ const Handlers = {
28412
28419
  })
28413
28420
  }
28414
28421
 
28415
- const createRouteConfig = ({ domain, path, upstreamPort }) => ({
28416
- match: [Matchers.host(domain)],
28417
- handle: [
28418
- {
28419
- handler: 'subroute',
28420
- routes: [
28421
- { handle: [Handlers.reverseProxy(upstreamPort)]}
28422
- ]
28423
- }
28424
- ],
28425
- terminal: true
28426
- })
28427
-
28428
- const multipleDomansAndSubroutes = () => ({
28429
- apps: {
28430
- http: {
28431
- servers: {
28432
- 'ci-client': {
28433
- listen: [
28434
- ':443'
28435
- ],
28436
- routes: [
28437
- {
28438
- match: [Matchers.host('admin.localhost')],
28439
- handle: [
28440
- Handlers.subroute([{ handle: [Handlers.reverseProxy(3000)] }])
28441
- ],
28442
- terminal: true
28443
- },
28444
- {
28445
- match: [Matchers.host('cms.localhost')],
28446
- handle: [
28447
- Handlers.subroute([{ handle: [Handlers.reverseProxy(3005)] }])
28448
- ],
28449
- terminal: true
28450
- },
28451
- {
28452
- match: [Matchers.host('localhost')],
28453
- handle: [
28454
- Handlers.subroute([
28455
- {
28456
- handle: [Handlers.reverseProxy(3001)],
28457
- match: [Matchers.path('/api/*')]
28458
- },
28459
- { handle: [Handlers.reverseProxy(3000)] }
28460
- ])
28461
- ],
28462
- terminal: true
28463
- }
28464
- ]
28465
- }
28466
- }
28467
- }
28468
- }
28469
- })
28470
-
28471
- // curl localhost:2019/id/msg
28472
-
28473
28422
  class CaddyClient {
28474
28423
 
28475
28424
  constructor(serverName = 'ci-client') {
@@ -28477,16 +28426,15 @@ class CaddyClient {
28477
28426
  }
28478
28427
 
28479
28428
  deploy({ domain, targetPort }) {
28480
- return fetch(`http://localhost:2019/config/apps/http/servers/${this.serverName}/routes`, {
28429
+ return fetch(`http://localhost:2019/config/apps/http/servers/${this.serverName}/routes/0/handle`, {
28481
28430
  method: 'POST',
28482
28431
  headers: { 'Content-Type': 'application/json' },
28483
- body: JSON.stringify({
28484
- match: [Matchers.host(domain)],
28485
- handle: [
28486
- Handlers.subroute([{ handle: [Handlers.reverseProxy(targetPort)] }])
28487
- ],
28488
- terminal: true
28489
- })
28432
+ body: JSON.stringify( Handlers.subroute([
28433
+ {
28434
+ match: [Matchers.host(domain)],
28435
+ handle: [Handlers.subroute([{ handle: [Handlers.reverseProxy(targetPort)]}])]
28436
+ }
28437
+ ]))
28490
28438
  })
28491
28439
  }
28492
28440
 
@@ -28500,7 +28448,13 @@ class CaddyClient {
28500
28448
  servers: {
28501
28449
  [this.serverName]: {
28502
28450
  listen: [':443'],
28503
- routes: []
28451
+ routes: [
28452
+ {
28453
+ match: [Matchers.host(`*.${environmentName}.${domain}`)],
28454
+ handle: [],
28455
+ terminal: true
28456
+ }
28457
+ ]
28504
28458
  }
28505
28459
  }
28506
28460
  }
@@ -28650,11 +28604,6 @@ ${this.startContainer({ image, containerPort, hostPort, registry, env })}`
28650
28604
 
28651
28605
  const createDockerClient = () => new DockerClient()
28652
28606
 
28653
- ;// CONCATENATED MODULE: ./src/config.js
28654
- const domain = process.env.DEPLOYMENT_TOOLS_DOMAIN || 'localhost'
28655
- const subdomain = process.env.DEPLOYMENT_TOOLS_SUBDOMAIN || 'local-dev.ci'
28656
- const port = process.env.DEPLOYMENT_TOOLS_PORT || 3000
28657
-
28658
28607
  ;// CONCATENATED MODULE: ./src/container-manager-server.js
28659
28608
 
28660
28609
 
@@ -28676,7 +28625,7 @@ class ContainerManagerServer {
28676
28625
 
28677
28626
  this.caddyClient.applyDefaultServerConfig()
28678
28627
  .then(() => this.caddyClient.deploy({
28679
- domain: `${subdomain}.${domain}`,
28628
+ domain: `${ciSubDomain}.${environmentName}.${domain}`,
28680
28629
  targetPort: port
28681
28630
  }))
28682
28631
 
@@ -28834,7 +28783,11 @@ class ContainerManagerCommands {
28834
28783
 
28835
28784
  console.log('body', body)
28836
28785
 
28837
- fetch(`http://${targetEnvironment}.ci.${platform.domain}/deploy`, {
28786
+ const ciUrl = targetEnvironment === 'prod'
28787
+ ? `http://${platform.ciSubDomain}.${platform.domain}/deploy`
28788
+ : `http://${platform.ciSubDomain}.${targetEnvironment}.${platform.domain}/deploy`
28789
+
28790
+ fetch(ciUrl, {
28838
28791
  method: 'POST',
28839
28792
  headers: { 'Content-Type': 'application/json' },
28840
28793
  body: JSON.stringify(body)
@@ -28876,7 +28829,8 @@ After=network.target
28876
28829
 
28877
28830
  [Service]
28878
28831
  Environment=DEPLOYMENT_TOOLS_DOMAIN=${domain}
28879
- Environment=DEPLOYMENT_TOOLS_SUBDOMAIN=${subdomain}
28832
+ Environment=DEPLOYMENT_TOOLS_ENVIRONMENT_NAME=${environmentName}
28833
+ Environment=DEPLOYMENT_TOOLS_CI_SUB_DOMAIN=${ciSubDomain}
28880
28834
  Environment=DEPLOYMENT_TOOLS_PORT=${port}
28881
28835
  User=root
28882
28836
  ExecStart=npx @ossy/deployment-tools start-container-manager
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ossy/deployment-tools",
3
- "version": "0.0.5",
3
+ "version": "0.0.8",
4
4
  "description": "Collection of scripts and tools to aid deployment of containers and static files",
5
5
  "main": "dist/index.js",
6
6
  "type": "module",
package/src/Caddyfile CHANGED
@@ -1,22 +1,10 @@
1
- localhost {
2
- reverse_proxy /api/* {
3
- to localhost:3001
4
- }
1
+ *.qa.ossy.com {
5
2
 
6
- reverse_proxy * {
7
- to localhost:3000
8
- }
3
+ @foo host ci.qa.example.com
4
+ handle @foo {
5
+ reverse_proxy * {
6
+ to localhost:3005
7
+ }
8
+ }
9
9
 
10
10
  }
11
-
12
- cms.localhost {
13
- reverse_proxy * {
14
- to localhost:3005
15
- }
16
- }
17
-
18
- admin.localhost {
19
- reverse_proxy * {
20
- to localhost:3000
21
- }
22
- }
@@ -1,4 +1,5 @@
1
1
  import fetch from 'node-fetch'
2
+ import * as config from './config.js'
2
3
 
3
4
  const Matchers = {
4
5
  host: host => ({ host: [host] }),
@@ -16,64 +17,6 @@ const Handlers = {
16
17
  })
17
18
  }
18
19
 
19
- const createRouteConfig = ({ domain, path, upstreamPort }) => ({
20
- match: [Matchers.host(domain)],
21
- handle: [
22
- {
23
- handler: 'subroute',
24
- routes: [
25
- { handle: [Handlers.reverseProxy(upstreamPort)]}
26
- ]
27
- }
28
- ],
29
- terminal: true
30
- })
31
-
32
- const multipleDomansAndSubroutes = () => ({
33
- apps: {
34
- http: {
35
- servers: {
36
- 'ci-client': {
37
- listen: [
38
- ':443'
39
- ],
40
- routes: [
41
- {
42
- match: [Matchers.host('admin.localhost')],
43
- handle: [
44
- Handlers.subroute([{ handle: [Handlers.reverseProxy(3000)] }])
45
- ],
46
- terminal: true
47
- },
48
- {
49
- match: [Matchers.host('cms.localhost')],
50
- handle: [
51
- Handlers.subroute([{ handle: [Handlers.reverseProxy(3005)] }])
52
- ],
53
- terminal: true
54
- },
55
- {
56
- match: [Matchers.host('localhost')],
57
- handle: [
58
- Handlers.subroute([
59
- {
60
- handle: [Handlers.reverseProxy(3001)],
61
- match: [Matchers.path('/api/*')]
62
- },
63
- { handle: [Handlers.reverseProxy(3000)] }
64
- ])
65
- ],
66
- terminal: true
67
- }
68
- ]
69
- }
70
- }
71
- }
72
- }
73
- })
74
-
75
- // curl localhost:2019/id/msg
76
-
77
20
  class CaddyClient {
78
21
 
79
22
  constructor(serverName = 'ci-client') {
@@ -81,16 +24,15 @@ class CaddyClient {
81
24
  }
82
25
 
83
26
  deploy({ domain, targetPort }) {
84
- return fetch(`http://localhost:2019/config/apps/http/servers/${this.serverName}/routes`, {
27
+ return fetch(`http://localhost:2019/config/apps/http/servers/${this.serverName}/routes/0/handle`, {
85
28
  method: 'POST',
86
29
  headers: { 'Content-Type': 'application/json' },
87
- body: JSON.stringify({
88
- match: [Matchers.host(domain)],
89
- handle: [
90
- Handlers.subroute([{ handle: [Handlers.reverseProxy(targetPort)] }])
91
- ],
92
- terminal: true
93
- })
30
+ body: JSON.stringify( Handlers.subroute([
31
+ {
32
+ match: [Matchers.host(domain)],
33
+ handle: [Handlers.subroute([{ handle: [Handlers.reverseProxy(targetPort)]}])]
34
+ }
35
+ ]))
94
36
  })
95
37
  }
96
38
 
@@ -104,7 +46,13 @@ class CaddyClient {
104
46
  servers: {
105
47
  [this.serverName]: {
106
48
  listen: [':443'],
107
- routes: []
49
+ routes: [
50
+ {
51
+ match: [Matchers.host(`*.${config.environmentName}.${config.domain}`)],
52
+ handle: [],
53
+ terminal: true
54
+ }
55
+ ]
108
56
  }
109
57
  }
110
58
  }
package/src/config.js CHANGED
@@ -1,3 +1,4 @@
1
1
  export const domain = process.env.DEPLOYMENT_TOOLS_DOMAIN || 'localhost'
2
- export const subdomain = process.env.DEPLOYMENT_TOOLS_SUBDOMAIN || 'local-dev.ci'
2
+ export const environmentName = process.env.DEPLOYMENT_TOOLS_ENVIRONMENT_NAME || 'dev'
3
+ export const ciSubDomain = process.env.DEPLOYMENT_TOOLS_CI_SUB_DOMAIN || 'ci'
3
4
  export const port = process.env.DEPLOYMENT_TOOLS_PORT || 3000
@@ -101,7 +101,11 @@ export class ContainerManagerCommands {
101
101
 
102
102
  console.log('body', body)
103
103
 
104
- fetch(`http://${targetEnvironment}.ci.${platform.domain}/deploy`, {
104
+ const ciUrl = targetEnvironment === 'prod'
105
+ ? `http://${platform.ciSubDomain}.${platform.domain}/deploy`
106
+ : `http://${platform.ciSubDomain}.${targetEnvironment}.${platform.domain}/deploy`
107
+
108
+ fetch(ciUrl, {
105
109
  method: 'POST',
106
110
  headers: { 'Content-Type': 'application/json' },
107
111
  body: JSON.stringify(body)
@@ -18,7 +18,7 @@ export class ContainerManagerServer {
18
18
 
19
19
  this.caddyClient.applyDefaultServerConfig()
20
20
  .then(() => this.caddyClient.deploy({
21
- domain: `${config.subdomain}.${config.domain}`,
21
+ domain: `${config.ciSubDomain}.${config.environmentName}.${config.domain}`,
22
22
  targetPort: config.port
23
23
  }))
24
24
 
package/src/index.js CHANGED
@@ -28,7 +28,8 @@ After=network.target
28
28
 
29
29
  [Service]
30
30
  Environment=DEPLOYMENT_TOOLS_DOMAIN=${config.domain}
31
- Environment=DEPLOYMENT_TOOLS_SUBDOMAIN=${config.subdomain}
31
+ Environment=DEPLOYMENT_TOOLS_ENVIRONMENT_NAME=${config.environmentName}
32
+ Environment=DEPLOYMENT_TOOLS_CI_SUB_DOMAIN=${config.ciSubDomain}
32
33
  Environment=DEPLOYMENT_TOOLS_PORT=${config.port}
33
34
  User=root
34
35
  ExecStart=npx @ossy/deployment-tools start-container-manager