@ossy/deployment-tools 0.0.85 → 0.0.89
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/README.md +7 -0
- package/cdk.context.json +8 -0
- package/package.json +2 -1
- package/src/aws-credentials/cli.js +0 -1
- package/src/caddy/caddy-config.js +47 -43
- package/src/caddy/caddy.js +87 -2
- package/src/caddy/caddy.playground.js +31 -0
- package/src/deploy/platform-deployment.js +0 -9
- package/src/docker/docker-service.js +22 -5
- package/src/docker/docker-service.playground.js +0 -3
- package/src/index.cli.js +0 -1
- package/src/infrastructure/cli.js +1 -2
- package/src/infrastructure/deployment-target-stack.js +31 -7
- package/src/server/platform-server.js +19 -17
- package/src/server/platform-server.playground.js +0 -0
- package/src/template/deployment-template.js +0 -1
- package/src/cms/cli.js +0 -55
- package/src/ossy.json +0 -14
package/README.md
CHANGED
|
@@ -42,3 +42,10 @@ The `cdk.json` file tells the CDK Toolkit how to execute your app.
|
|
|
42
42
|
* `cdk deploy` deploy this stack to your default AWS account/region
|
|
43
43
|
* `cdk diff` compare deployed stack with current state
|
|
44
44
|
* `cdk synth` emits the synthesized CloudFormation template
|
|
45
|
+
|
|
46
|
+
## Useful commands
|
|
47
|
+
|
|
48
|
+
```
|
|
49
|
+
// journalctl -u deployment-tools.service
|
|
50
|
+
// docker logs
|
|
51
|
+
```
|
package/cdk.context.json
CHANGED
|
@@ -76,5 +76,13 @@
|
|
|
76
76
|
"hosted-zone:account=858451553223:domainName=oskarssylwan.com:region=eu-north-1": {
|
|
77
77
|
"Id": "/hostedzone/Z07488011P8FXGWA11LTS",
|
|
78
78
|
"Name": "oskarssylwan.com."
|
|
79
|
+
},
|
|
80
|
+
"hosted-zone:account=858451553223:domainName=plexus-sanitas.com:region=eu-north-1": {
|
|
81
|
+
"Id": "/hostedzone/Z0222639MQIJ8EOL9VAG",
|
|
82
|
+
"Name": "plexus-sanitas.com."
|
|
83
|
+
},
|
|
84
|
+
"hosted-zone:account=858451553223:domainName=tepit.se:region=eu-north-1": {
|
|
85
|
+
"Id": "/hostedzone/Z07859112SU1GH5SKMUXD",
|
|
86
|
+
"Name": "tepit.se."
|
|
79
87
|
}
|
|
80
88
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ossy/deployment-tools",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.89",
|
|
4
4
|
"description": "Collection of scripts and tools to aid deployment of containers and static files to Amazon Web Services through GitHub Actions",
|
|
5
5
|
"source": "./src/index.js",
|
|
6
6
|
"main": "./src/index.js",
|
|
@@ -22,6 +22,7 @@
|
|
|
22
22
|
"aws-cdk-lib": "^2.73.0",
|
|
23
23
|
"constructs": "^10.1.304",
|
|
24
24
|
"express": "^4.18.1",
|
|
25
|
+
"get-port": "^7.1.0",
|
|
25
26
|
"glob": "^9.3.2",
|
|
26
27
|
"nanoid": "^3.3.4",
|
|
27
28
|
"node-fetch": "^2.6.7"
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
const { DeploymentTemplateService } = require('../template')
|
|
2
|
-
|
|
3
1
|
const Matchers = {
|
|
4
2
|
host: host => ({ host: [host] }),
|
|
5
3
|
path: path => ({ path: [path] })
|
|
@@ -21,60 +19,66 @@ const Handlers = {
|
|
|
21
19
|
*/
|
|
22
20
|
class CaddyConfigService {
|
|
23
21
|
|
|
24
|
-
static
|
|
25
|
-
|
|
26
|
-
const containerDeployments = DeploymentTemplateService
|
|
27
|
-
.getContainerDeployments(deploymentTemplates)
|
|
28
|
-
|
|
22
|
+
static createServer() {
|
|
29
23
|
return {
|
|
30
24
|
apps: {
|
|
25
|
+
tls: CaddyConfigService.tlsIssuers(),
|
|
31
26
|
http: {
|
|
32
27
|
servers: {
|
|
33
28
|
'deployment-tools': {
|
|
34
|
-
listen: [':
|
|
35
|
-
routes:
|
|
36
|
-
match: [Matchers.host(deploymentTemplate.domain)],
|
|
37
|
-
handle: [Handlers.subroute([{ handle: [Handlers.reverseProxy(deploymentTemplate.hostPort)]}])]
|
|
38
|
-
}))
|
|
29
|
+
listen: [':443'],
|
|
30
|
+
routes: []
|
|
39
31
|
}
|
|
40
32
|
}
|
|
41
33
|
},
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
static createProxyConfig(containerDeploymentTemplate) {
|
|
39
|
+
return {
|
|
40
|
+
'@id': containerDeploymentTemplate.domain,
|
|
41
|
+
match: [Matchers.host(containerDeploymentTemplate.domain)],
|
|
42
|
+
handle: [Handlers.subroute([{ handle: [Handlers.reverseProxy(containerDeploymentTemplate.hostPort)]}])]
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
static tlsIssuers() {
|
|
47
|
+
// add tls automation to the server config under apps.tls property
|
|
48
|
+
return {
|
|
49
|
+
automation: {
|
|
50
|
+
policies: [
|
|
51
|
+
{
|
|
52
|
+
subjects: [],
|
|
53
|
+
issuers:[
|
|
54
|
+
{
|
|
55
|
+
challenges: {
|
|
56
|
+
dns:{
|
|
57
|
+
provider: {
|
|
58
|
+
'max_retries': 10,
|
|
59
|
+
name: 'route53',
|
|
60
|
+
'aws_profile': 'ci-client'
|
|
56
61
|
}
|
|
57
|
-
}
|
|
58
|
-
module: 'acme'
|
|
62
|
+
}
|
|
59
63
|
},
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
64
|
+
module: 'acme'
|
|
65
|
+
},
|
|
66
|
+
{
|
|
67
|
+
challenges:{
|
|
68
|
+
dns:{
|
|
69
|
+
provider:{
|
|
70
|
+
'max_retries': 10,
|
|
71
|
+
name: 'route53'
|
|
67
72
|
}
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
73
|
+
}
|
|
74
|
+
},
|
|
75
|
+
module: 'zerossl'
|
|
76
|
+
}
|
|
77
|
+
]
|
|
78
|
+
}
|
|
79
|
+
]
|
|
75
80
|
}
|
|
76
81
|
}
|
|
77
|
-
}
|
|
78
82
|
}
|
|
79
83
|
|
|
80
84
|
}
|
package/src/caddy/caddy.js
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
const fetch = require('node-fetch')
|
|
2
|
+
const { logError, logInfo } = require('../log')
|
|
2
3
|
const { CaddyConfigService } = require('./caddy-config')
|
|
3
|
-
const { logInfo, logError, logDebug } = require('../log')
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* @class
|
|
7
7
|
*/
|
|
8
8
|
class CaddyService {
|
|
9
9
|
|
|
10
|
-
static
|
|
10
|
+
static loadServerConfig() {
|
|
11
|
+
const config = CaddyConfigService.createServer()
|
|
11
12
|
return fetch('http://localhost:2019/load', {
|
|
12
13
|
method: 'POST',
|
|
13
14
|
headers: { 'Content-Type': 'application/json' },
|
|
@@ -17,6 +18,90 @@ class CaddyService {
|
|
|
17
18
|
.catch(error => logError({ message: '[CaddyService] Could not apply default caddy config', error }))
|
|
18
19
|
}
|
|
19
20
|
|
|
21
|
+
static apply(containerDeploymentTemplate) {
|
|
22
|
+
return CaddyService.applyProxyConfig(containerDeploymentTemplate)
|
|
23
|
+
.then(() => CaddyService.applyTlsSubject(containerDeploymentTemplate))
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
static getConfig() {
|
|
27
|
+
return fetch('http://localhost:2019/config/', {
|
|
28
|
+
method: 'GET',
|
|
29
|
+
headers: { 'Content-Type': 'application/json' }
|
|
30
|
+
}).then(response => response.json())
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
static getTlsSubjects() {
|
|
34
|
+
return fetch('http://localhost:2019/config/apps/tls/automation/policies/0/subjects', {
|
|
35
|
+
method: 'GET',
|
|
36
|
+
headers: { 'Content-Type': 'application/json' }
|
|
37
|
+
})
|
|
38
|
+
.then(response => response.json())
|
|
39
|
+
.catch(error => logError({ message: '[CaddyService] Could not get tls subjects', error }))
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
static applyTlsSubject(containerDeploymentTemplate) {
|
|
43
|
+
return CaddyService.getTlsSubjects()
|
|
44
|
+
.then(tlsSubjects => {
|
|
45
|
+
const subjectExists = tlsSubjects.includes(containerDeploymentTemplate.domain)
|
|
46
|
+
return subjectExists
|
|
47
|
+
? Promise.resolve()
|
|
48
|
+
: CaddyService.addTlsSubject(containerDeploymentTemplate)
|
|
49
|
+
})
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
static addTlsSubject(containerDeploymentTemplate) {
|
|
53
|
+
return fetch('http://localhost:2019/config/apps/tls/automation/policies/0/subjects', {
|
|
54
|
+
method: 'POST',
|
|
55
|
+
headers: { 'Content-Type': 'application/json' },
|
|
56
|
+
body: JSON.stringify(containerDeploymentTemplate.domain)
|
|
57
|
+
})
|
|
58
|
+
.then(response => response?.error && logError({ message: '[CaddyService] Could not add tls subject', error }))
|
|
59
|
+
.catch(error => logError({ message: '[CaddyService] Could not add tls subject', error }))
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
static getProxyConfig(containerDeploymentTemplate) {
|
|
63
|
+
return fetch(`http://localhost:2019/id/${containerDeploymentTemplate.domain}`, {
|
|
64
|
+
method: 'GET',
|
|
65
|
+
headers: { 'Content-Type': 'application/json' }
|
|
66
|
+
})
|
|
67
|
+
.then(response => response.json())
|
|
68
|
+
.then(response => (!response || response?.error) ? Promise.reject() : response)
|
|
69
|
+
.catch(error => {
|
|
70
|
+
logInfo({ message: `[CaddyService] Could not find a proxy for ${containerDeploymentTemplate.domain}`, error })
|
|
71
|
+
return undefined
|
|
72
|
+
})
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
static applyProxyConfig(containerDeploymentTemplate) {
|
|
76
|
+
return CaddyService.getProxyConfig(containerDeploymentTemplate)
|
|
77
|
+
.then(proxyConfig => {
|
|
78
|
+
proxyConfig
|
|
79
|
+
? CaddyService.replaceProxyConfig(containerDeploymentTemplate)
|
|
80
|
+
: CaddyService.addProxyConfig(containerDeploymentTemplate)
|
|
81
|
+
})
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
static addProxyConfig(containerDeploymentTemplate) {
|
|
85
|
+
const proxyConfig = CaddyConfigService.createProxyConfig(containerDeploymentTemplate)
|
|
86
|
+
return fetch('http://localhost:2019/config/apps/http/servers/deployment-tools/routes', {
|
|
87
|
+
method: 'POST',
|
|
88
|
+
headers: { 'Content-Type': 'application/json' },
|
|
89
|
+
body: JSON.stringify(proxyConfig)
|
|
90
|
+
})
|
|
91
|
+
.then(response => response?.error && logError({ message: '[CaddyService] Could not add proxy config', error }))
|
|
92
|
+
.catch(error => logError({ message: '[CaddyService] Could not add proxy config', error }))
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
static replaceProxyConfig(containerDeploymentTemplate) {
|
|
96
|
+
const proxyConfig = CaddyConfigService.createProxyConfig(containerDeploymentTemplate)
|
|
97
|
+
return fetch(`http://localhost:2019/id/${containerDeploymentTemplate.domain}`, {
|
|
98
|
+
method: 'POST',
|
|
99
|
+
headers: { 'Content-Type': 'application/json' },
|
|
100
|
+
body: JSON.stringify(proxyConfig)
|
|
101
|
+
})
|
|
102
|
+
.then(response => response?.error && logError({ message: '[CaddyService] Could not add proxy config', error }))
|
|
103
|
+
.catch(error => logError({ message: '[CaddyService] Could not add proxy config', error }))
|
|
104
|
+
}
|
|
20
105
|
|
|
21
106
|
}
|
|
22
107
|
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
const { CaddyService } = require('./caddy')
|
|
2
|
+
|
|
3
|
+
const containerDeploymentTemplate = {
|
|
4
|
+
"domain": "peter.ossy.se",
|
|
5
|
+
"image": "ossy-se/website-alex",
|
|
6
|
+
"targetDeploymentPlatform": "ossybot",
|
|
7
|
+
"type": "CONTAINER",
|
|
8
|
+
"hostPort": "3016"
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
// CaddyService.getProxyForDomain('alex.ossy.se')
|
|
13
|
+
// .then(x => console.log(JSON.stringify(x, null, 2)))
|
|
14
|
+
|
|
15
|
+
// CaddyService.getProxyForDomain('ossy.se')
|
|
16
|
+
// .then(x => console.log(JSON.stringify(x, null, 2)))
|
|
17
|
+
|
|
18
|
+
// OnStartup
|
|
19
|
+
// CaddyService.loadServerConfig()
|
|
20
|
+
|
|
21
|
+
// Get config
|
|
22
|
+
CaddyService.getConfig()
|
|
23
|
+
.then(x => console.log(JSON.stringify(x, null, 2)))
|
|
24
|
+
// .then(() => CaddyService.applyProxyConfig(containerDeploymentTemplate))
|
|
25
|
+
// .then(() => CaddyService.getConfig())
|
|
26
|
+
// .then(x => console.log(JSON.stringify(x, null, 2)))
|
|
27
|
+
|
|
28
|
+
// CaddyService.getTlsSubjects()
|
|
29
|
+
// .then(x => console.log(JSON.stringify(x, null, 2)))
|
|
30
|
+
|
|
31
|
+
// CaddyService.apply(containerDeploymentTemplate)
|
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
const { readFileSync } = require('fs')
|
|
2
|
-
const { resolve } = require('path')
|
|
3
1
|
const { PlatformTemplateService, DeploymentTemplateService } = require('../template')
|
|
4
2
|
const { PlatformConfigService, SupportedDeploymentTypes } = require('../config')
|
|
5
3
|
const { DeploymentQueueService } = require('../deployment-queue')
|
|
6
|
-
const { CaddyConfigService } = require('../caddy')
|
|
7
4
|
const { logError } = require('../log')
|
|
8
5
|
|
|
9
6
|
/**
|
|
@@ -45,13 +42,10 @@ class PlatformDeploymentService {
|
|
|
45
42
|
|
|
46
43
|
if (deploymentTemplate.type === SupportedDeploymentTypes.Container) {
|
|
47
44
|
|
|
48
|
-
const caddyConfig = CaddyConfigService.createConfig(platformConfig, deploymentTemplatesForTargetPlatform)
|
|
49
|
-
|
|
50
45
|
const deploymentRequest = {
|
|
51
46
|
...deploymentTemplate,
|
|
52
47
|
username: username,
|
|
53
48
|
authentication: authentication,
|
|
54
|
-
caddyConfig
|
|
55
49
|
}
|
|
56
50
|
|
|
57
51
|
return DeploymentQueueService.sendDeploymentRequest(platformConfig, deploymentRequest)
|
|
@@ -97,13 +91,10 @@ class PlatformDeploymentService {
|
|
|
97
91
|
return deploymentTemplatesForTargetPlatform.map(deploymentTemplate => {
|
|
98
92
|
if (deploymentTemplate.type === SupportedDeploymentTypes.Container) {
|
|
99
93
|
|
|
100
|
-
const caddyConfig = CaddyConfigService.createConfig(platformConfig, deploymentTemplatesForTargetPlatform)
|
|
101
|
-
|
|
102
94
|
const deploymentRequest = {
|
|
103
95
|
...deploymentTemplate,
|
|
104
96
|
username: username,
|
|
105
97
|
authentication: authentication,
|
|
106
|
-
caddyConfig
|
|
107
98
|
}
|
|
108
99
|
|
|
109
100
|
return DeploymentQueueService.sendDeploymentRequest(platformConfig, deploymentRequest)
|
|
@@ -27,7 +27,7 @@ class DockerService {
|
|
|
27
27
|
|
|
28
28
|
static stopContainer(deploymentRequest) {
|
|
29
29
|
logInfo({ message: `[DockerService] Stopping container for ${deploymentRequest.domain}` })
|
|
30
|
-
return exec(`docker stop
|
|
30
|
+
return exec(`docker stop c-${deploymentRequest.domain}`)
|
|
31
31
|
.catch(() => {}) // no worries if container isn't there
|
|
32
32
|
}
|
|
33
33
|
|
|
@@ -46,12 +46,18 @@ class DockerService {
|
|
|
46
46
|
.catch(logErrorAndReject(`[DockerService] Could pull image ${image}:latest`))
|
|
47
47
|
}
|
|
48
48
|
|
|
49
|
-
static startContainer(platformConfig, { image, containerPort,
|
|
49
|
+
static startContainer(platformConfig, { image, containerPort, registry, env, domain }) {
|
|
50
50
|
const imageUrl = !!registry ? `${registry}/${image}` : image
|
|
51
51
|
const envsAsString = Object.entries(env || {}).reduce((envs, [name, value]) => `${envs} --env ${name}="${value}"`, '')
|
|
52
|
-
|
|
53
|
-
return
|
|
54
|
-
.
|
|
52
|
+
|
|
53
|
+
return DockerService.getUnusedPort()
|
|
54
|
+
.then(hostPort => {
|
|
55
|
+
logInfo({ message: `[DockerService] Starting container for ${domain} with port mapping ${hostPort}:${containerPort} and source ${imageUrl}` })
|
|
56
|
+
return exec(`docker run -d -p ${hostPort}:${containerPort} --name=c-${domain} --network=${platformConfig.ciDockerNetworkName} --network-alias=c-${domain} --rm ${envsAsString} ${imageUrl}`)
|
|
57
|
+
.then(() => ({ hostPort }))
|
|
58
|
+
.catch(logErrorAndReject(`[DockerService] Could not start container ${image}`))
|
|
59
|
+
})
|
|
60
|
+
|
|
55
61
|
}
|
|
56
62
|
|
|
57
63
|
static resolveCredentials({ registry, username, authentication }) {
|
|
@@ -78,6 +84,17 @@ class DockerService {
|
|
|
78
84
|
.then(() => DockerService.startContainer(platformConfig, deploymentRequest))
|
|
79
85
|
}
|
|
80
86
|
|
|
87
|
+
static getUnusedPort() {
|
|
88
|
+
// get-port is written in es6, so we need to import it like this
|
|
89
|
+
return import('get-port')
|
|
90
|
+
.then(module => {
|
|
91
|
+
const getPort = module.default;
|
|
92
|
+
const portNumbers = module.portNumbers;
|
|
93
|
+
|
|
94
|
+
return getPort({ port: portNumbers(3000, 3200) })
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
|
|
81
98
|
}
|
|
82
99
|
|
|
83
100
|
module.exports = {
|
package/src/index.cli.js
CHANGED
|
@@ -8,7 +8,6 @@ const loadHandler = {
|
|
|
8
8
|
deployment: () => require('./deploy/cli.js'),
|
|
9
9
|
template: () => require('./template/cli.js'),
|
|
10
10
|
server: () => require('./server/cli.js'),
|
|
11
|
-
cms: () => require('./cms/cli.js')
|
|
12
11
|
}[handlerName]
|
|
13
12
|
|
|
14
13
|
!!loadHandler && loadHandler().handler(restArgs)
|
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
/* eslint-disable no-new */
|
|
3
|
-
const { App
|
|
3
|
+
const { App } = require('aws-cdk-lib')
|
|
4
4
|
const { TrustCiStack } = require('./trust-ci-stack')
|
|
5
5
|
const { DeploymentTargetStack } = require('./deployment-target-stack')
|
|
6
6
|
const { DnsStack } = require('./dns-stack')
|
|
7
7
|
const { PlatformTemplateService, DeploymentTemplateService } = require('../template')
|
|
8
8
|
const { PlatformConfigService } = require('../config')
|
|
9
|
-
const { PlatformDeploymentService } = require('../deploy')
|
|
10
9
|
|
|
11
10
|
Promise.all([
|
|
12
11
|
DeploymentTemplateService.readFromFiles(process.env.DEPLOYMENTS),
|
|
@@ -3,6 +3,8 @@ const { nanoid } = require('nanoid')
|
|
|
3
3
|
const { CfnOutput, Stack, Duration, RemovalPolicy } = require('aws-cdk-lib')
|
|
4
4
|
const { HostedZone, ARecord, RecordTarget } = require('aws-cdk-lib/aws-route53')
|
|
5
5
|
const { Bucket, BucketEncryption, BlockPublicAccess } = require('aws-cdk-lib/aws-s3')
|
|
6
|
+
const { Distribution, PriceClass } = require('aws-cdk-lib/aws-cloudfront')
|
|
7
|
+
const { S3Origin } = require('aws-cdk-lib/aws-cloudfront-origins')
|
|
6
8
|
const { ContainerDeploymentTarget } = require('./container-deployment-target')
|
|
7
9
|
|
|
8
10
|
/**
|
|
@@ -16,17 +18,33 @@ class DeploymentTargetStack extends Stack {
|
|
|
16
18
|
throw ('[DeploymentTargetStack] No template provided')
|
|
17
19
|
}
|
|
18
20
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
+
// create a bucket name before running cdk deploy and put it in config
|
|
22
|
+
// so that it won't change when updating resources
|
|
23
|
+
// const bucketId = nanoid().toLowerCase().replaceAll('_', '').replaceAll('-', '')
|
|
24
|
+
// const bucketName = `${props.config.platformName}-${bucketId}`
|
|
21
25
|
|
|
22
|
-
// TODO:
|
|
26
|
+
// TODO: Check if the bucket already exists and use it
|
|
27
|
+
// instead of having the whole deployment fail
|
|
23
28
|
const staticDeploymentTarget =
|
|
24
29
|
new Bucket(this, 'StaticDeploymentTarget', {
|
|
25
|
-
bucketName:
|
|
30
|
+
bucketName: props.config.awsStaticBucketName,
|
|
26
31
|
blockPublicAccess: BlockPublicAccess.BLOCK_ALL,
|
|
27
|
-
encryption: BucketEncryption.
|
|
28
|
-
removalPolicy: RemovalPolicy.
|
|
29
|
-
autoDeleteObjects:
|
|
32
|
+
encryption: BucketEncryption.UNENCRYPTED,
|
|
33
|
+
removalPolicy: RemovalPolicy.RETAIN,
|
|
34
|
+
autoDeleteObjects: false,
|
|
35
|
+
cors: [{
|
|
36
|
+
allowedHeaders: ['*'],
|
|
37
|
+
allowedMethods: ['GET', 'PUT', 'POST' ],
|
|
38
|
+
allowedOrigins: [ '*' ],
|
|
39
|
+
exposeHeaders: []
|
|
40
|
+
}]
|
|
41
|
+
})
|
|
42
|
+
|
|
43
|
+
const mediaCDN = new Distribution(this, 'Media', {
|
|
44
|
+
defaultBehavior: {
|
|
45
|
+
origin: new S3Origin(staticDeploymentTarget, { originPath: '/media' }),
|
|
46
|
+
},
|
|
47
|
+
priceClass: PriceClass.PRICE_CLASS_100
|
|
30
48
|
})
|
|
31
49
|
|
|
32
50
|
const containerDeploymentTarget =
|
|
@@ -39,6 +57,12 @@ class DeploymentTargetStack extends Stack {
|
|
|
39
57
|
this.staticDeploymentTargetBucketName = staticDeploymentTarget.bucketName
|
|
40
58
|
this.staticDeploymentTargetBucketArn = staticDeploymentTarget.bucketArn
|
|
41
59
|
|
|
60
|
+
new CfnOutput(this, 'MediaCDNDomainName', {
|
|
61
|
+
value: mediaCDN.domainName,
|
|
62
|
+
description: 'Domain name of CDN distribution',
|
|
63
|
+
exportName: 'MediaCDNDomainName'
|
|
64
|
+
})
|
|
65
|
+
|
|
42
66
|
new CfnOutput(this, 'ContainerDeploymentTargetPublicIp', {
|
|
43
67
|
value: containerDeploymentTarget.instancePublicIp,
|
|
44
68
|
description: 'Public ip of the ec2 instance',
|
|
@@ -1,33 +1,35 @@
|
|
|
1
1
|
const { CaddyService } = require('../caddy')
|
|
2
2
|
const { DockerService } = require('../docker')
|
|
3
|
-
|
|
4
3
|
const { PlatformTemplateService } = require('../template')
|
|
5
4
|
const { PlatformConfigService } = require('../config')
|
|
6
5
|
const { DeploymentQueueService } = require('../deployment-queue')
|
|
7
6
|
const { logError } = require('../log')
|
|
8
7
|
|
|
9
|
-
// journalctl -u deployment-tools.service
|
|
10
|
-
// docker logs
|
|
11
8
|
/**
|
|
12
9
|
* @class
|
|
13
10
|
*/
|
|
14
11
|
class PlatformServerService {
|
|
15
12
|
|
|
16
13
|
static start(platformTemplatesFilePath) {
|
|
17
|
-
PlatformTemplateService
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
14
|
+
PlatformTemplateService
|
|
15
|
+
.readFromFile(platformTemplatesFilePath)
|
|
16
|
+
.then(([firstPlatformTemplateFound]) => {
|
|
17
|
+
const platformConfig = PlatformConfigService.from(firstPlatformTemplateFound)
|
|
18
|
+
|
|
19
|
+
DockerService.createDockerNetworkForContainerManagerServer(platformConfig)
|
|
20
|
+
.then(() => DockerService.startDefaultContainers(platformConfig))
|
|
21
|
+
|
|
22
|
+
CaddyService.loadServerConfig()
|
|
23
|
+
|
|
24
|
+
DeploymentQueueService.pollForDeploymentRequests(
|
|
25
|
+
platformConfig,
|
|
26
|
+
deploymentRequest => {
|
|
27
|
+
DockerService.deploy(platformConfig, deploymentRequest)
|
|
28
|
+
.then(({ hostPort }) => CaddyService.apply({ ...deploymentRequest, hostPort }))
|
|
29
|
+
|
|
30
|
+
return Promise.resolve()
|
|
31
|
+
}
|
|
32
|
+
)
|
|
31
33
|
|
|
32
34
|
})
|
|
33
35
|
.catch(error => logError({ message: '[PlatformServerService] Could not start the platform server', error }))
|
|
File without changes
|
package/src/cms/cli.js
DELETED
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
const { resolve } = require('path')
|
|
3
|
-
const { readFileSync } = require('fs')
|
|
4
|
-
const arg = require('arg')
|
|
5
|
-
const fetch = require('node-fetch')
|
|
6
|
-
const { logInfo, logError } = require('../log')
|
|
7
|
-
|
|
8
|
-
const config = {
|
|
9
|
-
apiUrl: 'https://api.ossy.se/api/v0'
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
const getTokenPayload = token =>
|
|
13
|
-
JSON.parse(Buffer.from(token.split('.')[1], 'base64').toString())
|
|
14
|
-
|
|
15
|
-
const importResourceTemplates = options => {
|
|
16
|
-
|
|
17
|
-
const parsedArgs = arg({
|
|
18
|
-
'--authentication': String,
|
|
19
|
-
'--a': '--authentication',
|
|
20
|
-
|
|
21
|
-
'--ossy-file': String,
|
|
22
|
-
'-o': '--ossy-file',
|
|
23
|
-
}, { argv: options })
|
|
24
|
-
|
|
25
|
-
logInfo({ message: '[CMS] reading files' })
|
|
26
|
-
const token = parsedArgs['--authentication']
|
|
27
|
-
const tokenPayload = getTokenPayload(token)
|
|
28
|
-
const ossyfile = JSON.parse(readFileSync(resolve(parsedArgs['--ossy-file']), 'utf8'))
|
|
29
|
-
|
|
30
|
-
if (!token) return logError({ message: '[CMS] No token provided with --authentication'})
|
|
31
|
-
if (!ossyfile?.workspaceId) return logError({ message: '[CMS] No workspaceId provided in ossy.json'})
|
|
32
|
-
if (!ossyfile?.resourceTemplates) return logError({ message: '[CMS] No resource templates provided in ossy.json'})
|
|
33
|
-
|
|
34
|
-
logInfo({ message: '[CMS] uploading resource templates' })
|
|
35
|
-
|
|
36
|
-
const endpoint = `${config.apiUrl}/workspaces/${ossyfile.workspaceId}/resource-templates`
|
|
37
|
-
|
|
38
|
-
const fetchOptions = {
|
|
39
|
-
method: 'POST',
|
|
40
|
-
headers: { 'Authorization': token, 'Content-Type': 'application/json' },
|
|
41
|
-
body: JSON.stringify(ossyfile.resourceTemplates)
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
fetch(endpoint, fetchOptions)
|
|
45
|
-
.then(() => logInfo({ message: '[CMS] Done' }))
|
|
46
|
-
.catch(error => logError({ message: '[CMS] Error', error }))
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
module.exports = {
|
|
50
|
-
handler: ([command, ...options]) => {
|
|
51
|
-
!!command
|
|
52
|
-
? { 'import-resource-templates': importResourceTemplates }[command](options)
|
|
53
|
-
: logError({ message: '[CMS] No command provided' })
|
|
54
|
-
}
|
|
55
|
-
}
|