@ossy/deployment-tools 0.0.52 → 0.0.54
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/jsdoc/AwsCredentialsService.html +166 -0
- package/jsdoc/AwsProfile.html +166 -0
- package/jsdoc/CaddyService.html +293 -0
- package/jsdoc/ContainerServer.html +265 -0
- package/jsdoc/DeploymentQueueService.html +166 -0
- package/jsdoc/DeploymentToolsService.html +166 -0
- package/jsdoc/DockerService.html +166 -0
- package/jsdoc/EstablishTrustStack.html +268 -0
- package/jsdoc/PlatformConfigService.html +166 -0
- package/jsdoc/PlatformDeploymentService.html +166 -0
- package/jsdoc/PlatformServerService.html +166 -0
- package/jsdoc/PlatformStack.html +166 -0
- package/jsdoc/PlatformTemplateService.html +502 -0
- package/jsdoc/RestApiService.html +166 -0
- package/jsdoc/aws-credentials_aws-credentials.js.html +138 -0
- package/jsdoc/config_platform-config.js.html +113 -0
- package/jsdoc/deploy_platform-deployment.js.html +155 -0
- package/jsdoc/deployment-queue_deployment-queue.js.html +132 -0
- package/jsdoc/fonts/OpenSans-Bold-webfont.eot +0 -0
- package/jsdoc/fonts/OpenSans-Bold-webfont.svg +1830 -0
- package/jsdoc/fonts/OpenSans-Bold-webfont.woff +0 -0
- package/jsdoc/fonts/OpenSans-BoldItalic-webfont.eot +0 -0
- package/jsdoc/fonts/OpenSans-BoldItalic-webfont.svg +1830 -0
- package/jsdoc/fonts/OpenSans-BoldItalic-webfont.woff +0 -0
- package/jsdoc/fonts/OpenSans-Italic-webfont.eot +0 -0
- package/jsdoc/fonts/OpenSans-Italic-webfont.svg +1830 -0
- package/jsdoc/fonts/OpenSans-Italic-webfont.woff +0 -0
- package/jsdoc/fonts/OpenSans-Light-webfont.eot +0 -0
- package/jsdoc/fonts/OpenSans-Light-webfont.svg +1831 -0
- package/jsdoc/fonts/OpenSans-Light-webfont.woff +0 -0
- package/jsdoc/fonts/OpenSans-LightItalic-webfont.eot +0 -0
- package/jsdoc/fonts/OpenSans-LightItalic-webfont.svg +1835 -0
- package/jsdoc/fonts/OpenSans-LightItalic-webfont.woff +0 -0
- package/jsdoc/fonts/OpenSans-Regular-webfont.eot +0 -0
- package/jsdoc/fonts/OpenSans-Regular-webfont.svg +1831 -0
- package/jsdoc/fonts/OpenSans-Regular-webfont.woff +0 -0
- package/jsdoc/global.html +800 -0
- package/jsdoc/index.html +65 -0
- package/jsdoc/infrastructure_container-server_aws-profile.js.html +76 -0
- package/jsdoc/infrastructure_container-server_caddy.service.js.html +123 -0
- package/jsdoc/infrastructure_container-server_container-server.js.html +229 -0
- package/jsdoc/infrastructure_container-server_deployment-tools.service.js.html +91 -0
- package/jsdoc/infrastructure_establish-trust-stack.js.html +119 -0
- package/jsdoc/infrastructure_platform-stack.js.html +107 -0
- package/jsdoc/scripts/linenumber.js +25 -0
- package/jsdoc/scripts/prettify/Apache-License-2.0.txt +202 -0
- package/jsdoc/scripts/prettify/lang-css.js +2 -0
- package/jsdoc/scripts/prettify/prettify.js +28 -0
- package/jsdoc/server_caddy.js.html +165 -0
- package/{src/server/docker.js → jsdoc/server_docker.js.html} +55 -1
- package/jsdoc/server_platform-server.js.html +91 -0
- package/jsdoc/server_rest-api.js.html +82 -0
- package/jsdoc/styles/jsdoc-default.css +358 -0
- package/jsdoc/styles/prettify-jsdoc.css +111 -0
- package/jsdoc/styles/prettify-tomorrow.css +132 -0
- package/jsdoc/template_platform-template.js.html +134 -0
- package/jsdoc.config.js +8 -12
- package/package.json +8 -7
- package/src/aws-credentials/aws-credentials.js +3 -0
- package/src/config/platform-config.js +9 -0
- package/src/deploy/platform-deployment.js +30 -0
- package/src/deployment-queue/deployment-queue.js +3 -0
- package/src/docker/docker-service.js +91 -0
- package/src/docker/docker-service.playground.js +17 -0
- package/src/docker/index.js +1 -0
- package/src/infrastructure/container-server/aws-profile.js +3 -0
- package/src/infrastructure/container-server/caddy.service.js +3 -0
- package/src/infrastructure/container-server/container-server.js +4 -0
- package/src/infrastructure/container-server/deployment-tools.service.js +3 -0
- package/src/infrastructure/establish-trust-stack.js +3 -0
- package/src/infrastructure/platform-stack.js +6 -2
- package/src/server/caddy.js +3 -0
- package/src/server/platform-server.js +6 -3
- package/src/server/rest-api.js +3 -0
- package/src/template/platform-template.js +24 -9
- package/src/types.js +0 -32
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="utf-8">
|
|
5
|
+
<title>JSDoc: Source: aws-credentials/aws-credentials.js</title>
|
|
6
|
+
|
|
7
|
+
<script src="scripts/prettify/prettify.js"> </script>
|
|
8
|
+
<script src="scripts/prettify/lang-css.js"> </script>
|
|
9
|
+
<!--[if lt IE 9]>
|
|
10
|
+
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
|
|
11
|
+
<![endif]-->
|
|
12
|
+
<link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
|
|
13
|
+
<link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css">
|
|
14
|
+
</head>
|
|
15
|
+
|
|
16
|
+
<body>
|
|
17
|
+
|
|
18
|
+
<div id="main">
|
|
19
|
+
|
|
20
|
+
<h1 class="page-title">Source: aws-credentials/aws-credentials.js</h1>
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
<section>
|
|
28
|
+
<article>
|
|
29
|
+
<pre class="prettyprint source linenums"><code>const core = require('@actions/core')
|
|
30
|
+
const { STSClient, AssumeRoleWithWebIdentityCommand } = require('@aws-sdk/client-sts')
|
|
31
|
+
|
|
32
|
+
const { logInfo, logError } = require('../log')
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* @class
|
|
36
|
+
*/
|
|
37
|
+
class AwsCredentialsService {
|
|
38
|
+
|
|
39
|
+
static resolveAwsCredentials(platformConfig) {
|
|
40
|
+
// If awsRoleToAssume is present, then we assume we run in a github workflow
|
|
41
|
+
// If awsRoleToAssume is not present, then we assume they are resolved localy by aws-sdk
|
|
42
|
+
if (!platformConfig.awsRoleToAssume) {
|
|
43
|
+
logInfo({ message: '[AwsCredentialsService] No aws role to assume was found, leaving auth logic to @aws-sdk package' })
|
|
44
|
+
return Promise.resolve(undefined)
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const stsClient = new STSClient({ region: platformConfig.awsRegion })
|
|
48
|
+
|
|
49
|
+
logInfo({ message: '[AwsCredentialsService] Fetching GitHub ID token' })
|
|
50
|
+
return core.getIDToken('sts.amazonaws.com')
|
|
51
|
+
.then(webIdentityToken => {
|
|
52
|
+
logInfo({ message: `[AwsCredentialsService] Attempting to resolve aws credentials by assuming the role: ${platformConfig.awsRoleToAssume}` })
|
|
53
|
+
return stsClient.send(new AssumeRoleWithWebIdentityCommand({
|
|
54
|
+
RoleArn: `arn:aws:iam::${platformConfig.awsAccountId}:role/${platformConfig.awsRoleToAssume}`,
|
|
55
|
+
RoleSessionName: 'GitHubActions',
|
|
56
|
+
DurationSeconds: 15 * 60,
|
|
57
|
+
WebIdentityToken: webIdentityToken
|
|
58
|
+
}))
|
|
59
|
+
})
|
|
60
|
+
.then(responseData => ({
|
|
61
|
+
// Don't ask
|
|
62
|
+
AccessKeyId: responseData.Credentials.AccessKeyId,
|
|
63
|
+
SessionToken: responseData.Credentials.SessionToken,
|
|
64
|
+
SecretAccessKey: responseData.Credentials.SecretAccessKey,
|
|
65
|
+
accessKeyId: responseData.Credentials.AccessKeyId,
|
|
66
|
+
sessionToken: responseData.Credentials.SessionToken,
|
|
67
|
+
secretAccessKey: responseData.Credentials.SecretAccessKey
|
|
68
|
+
}))
|
|
69
|
+
.then(x => AwsCredentialsService.exportCredentialsToGithubWorkflow({ ...x, awsRegion: platformConfig.awsRegion }))
|
|
70
|
+
.catch(error => {
|
|
71
|
+
logError({ message: '[AwsCredentialsService] Could not resolve temporary credentials', error })
|
|
72
|
+
return undefined
|
|
73
|
+
})
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
static exportCredentialsToGithubWorkflow(params) {
|
|
77
|
+
// Configure the AWS CLI and AWS SDKs using environment variables and set them as secrets.
|
|
78
|
+
// Setting the credentials as secrets masks them in Github Actions logs
|
|
79
|
+
const { accessKeyId, secretAccessKey, sessionToken, awsRegion } = params
|
|
80
|
+
|
|
81
|
+
// AWS_ACCESS_KEY_ID:
|
|
82
|
+
// Specifies an AWS access key associated with an IAM user or role
|
|
83
|
+
core.setSecret(accessKeyId)
|
|
84
|
+
core.exportVariable('AWS_ACCESS_KEY_ID', accessKeyId)
|
|
85
|
+
|
|
86
|
+
// AWS_SECRET_ACCESS_KEY:
|
|
87
|
+
// Specifies the secret key associated with the access key. This is essentially the "password" for the access key.
|
|
88
|
+
core.setSecret(secretAccessKey)
|
|
89
|
+
core.exportVariable('AWS_SECRET_ACCESS_KEY', secretAccessKey)
|
|
90
|
+
|
|
91
|
+
// AWS_SESSION_TOKEN:
|
|
92
|
+
// Specifies the session token value that is required if you are using temporary security credentials.
|
|
93
|
+
if (sessionToken) {
|
|
94
|
+
core.setSecret(sessionToken)
|
|
95
|
+
core.exportVariable('AWS_SESSION_TOKEN', sessionToken)
|
|
96
|
+
} else if (process.env.AWS_SESSION_TOKEN) {
|
|
97
|
+
// clear session token from previous credentials action
|
|
98
|
+
core.exportVariable('AWS_SESSION_TOKEN', '')
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
if (awsRegion) {
|
|
102
|
+
core.exportVariable('AWS_REGION', awsRegion)
|
|
103
|
+
} else if (process.env.AWS_REGION) {
|
|
104
|
+
// clear AWS_REGION from previous credentials action
|
|
105
|
+
core.exportVariable('AWS_REGION', '')
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
return params
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
module.exports = {
|
|
114
|
+
AwsCredentialsService
|
|
115
|
+
}
|
|
116
|
+
</code></pre>
|
|
117
|
+
</article>
|
|
118
|
+
</section>
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
</div>
|
|
124
|
+
|
|
125
|
+
<nav>
|
|
126
|
+
<h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="AwsCredentialsService.html">AwsCredentialsService</a></li><li><a href="AwsProfile.html">AwsProfile</a></li><li><a href="CaddyService.html">CaddyService</a></li><li><a href="ContainerServer.html">ContainerServer</a></li><li><a href="DeploymentQueueService.html">DeploymentQueueService</a></li><li><a href="DeploymentToolsService.html">DeploymentToolsService</a></li><li><a href="DockerService.html">DockerService</a></li><li><a href="EstablishTrustStack.html">EstablishTrustStack</a></li><li><a href="PlatformConfigService.html">PlatformConfigService</a></li><li><a href="PlatformDeploymentService.html">PlatformDeploymentService</a></li><li><a href="PlatformServerService.html">PlatformServerService</a></li><li><a href="PlatformStack.html">PlatformStack</a></li><li><a href="PlatformTemplateService.html">PlatformTemplateService</a></li><li><a href="RestApiService.html">RestApiService</a></li></ul><h3><a href="global.html">Global</a></h3>
|
|
127
|
+
</nav>
|
|
128
|
+
|
|
129
|
+
<br class="clear">
|
|
130
|
+
|
|
131
|
+
<footer>
|
|
132
|
+
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 3.6.11</a> on Sun Oct 23 2022 22:23:31 GMT+0200 (Central European Summer Time)
|
|
133
|
+
</footer>
|
|
134
|
+
|
|
135
|
+
<script> prettyPrint(); </script>
|
|
136
|
+
<script src="scripts/linenumber.js"> </script>
|
|
137
|
+
</body>
|
|
138
|
+
</html>
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="utf-8">
|
|
5
|
+
<title>JSDoc: Source: config/platform-config.js</title>
|
|
6
|
+
|
|
7
|
+
<script src="scripts/prettify/prettify.js"> </script>
|
|
8
|
+
<script src="scripts/prettify/lang-css.js"> </script>
|
|
9
|
+
<!--[if lt IE 9]>
|
|
10
|
+
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
|
|
11
|
+
<![endif]-->
|
|
12
|
+
<link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
|
|
13
|
+
<link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css">
|
|
14
|
+
</head>
|
|
15
|
+
|
|
16
|
+
<body>
|
|
17
|
+
|
|
18
|
+
<div id="main">
|
|
19
|
+
|
|
20
|
+
<h1 class="page-title">Source: config/platform-config.js</h1>
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
<section>
|
|
28
|
+
<article>
|
|
29
|
+
<pre class="prettyprint source linenums"><code>const SupportedRegions = {
|
|
30
|
+
North: 'eu-north-1'
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const SupportedEnvironments = {
|
|
34
|
+
LOCAL: 'local',
|
|
35
|
+
QA: 'qa',
|
|
36
|
+
TEST: 'test',
|
|
37
|
+
DEMO: 'demo',
|
|
38
|
+
PROD: 'prod'
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const SupportedDeploymentTypes = {
|
|
42
|
+
Container: 'CONTAINER'
|
|
43
|
+
// Static = 'STATIC'
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// export interface PlatformConfig extends Required<Omit<PlatformTemplate, 'awsRoleToAssume' | 'awsKeyPairName'>> {
|
|
47
|
+
// activeEnvironment: SupportedEnvironments;
|
|
48
|
+
// awsRoleToAssume?: string;
|
|
49
|
+
// awsKeyPairName?: string;
|
|
50
|
+
// }
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* @class
|
|
54
|
+
*/
|
|
55
|
+
class PlatformConfigService {
|
|
56
|
+
|
|
57
|
+
static from(template) {
|
|
58
|
+
|
|
59
|
+
const withDefaults = {
|
|
60
|
+
platformName: SupportedEnvironments.LOCAL,
|
|
61
|
+
domain: 'localhost',
|
|
62
|
+
activeEnvironment: SupportedEnvironments.LOCAL,
|
|
63
|
+
supportedDeploymentTypes: ['CONTAINER'],
|
|
64
|
+
ciSubDomain: 'ci',
|
|
65
|
+
ciInternalServerPort: 3000,
|
|
66
|
+
ciServerName: 'ci-client',
|
|
67
|
+
ciDockerNetworkName: 'deployment-tools',
|
|
68
|
+
awsRegion: SupportedRegions.North,
|
|
69
|
+
...template
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
const awsDeploymentSqsArn = `https://sqs.${withDefaults.awsRegion}.amazonaws.com/${withDefaults.awsAccountId}/${withDefaults.platformName}-${withDefaults.activeEnvironment}`
|
|
73
|
+
const awsRoleToAssume = process.env.CI ? 'github-ci-role' : undefined
|
|
74
|
+
|
|
75
|
+
return {
|
|
76
|
+
...withDefaults,
|
|
77
|
+
awsDeploymentSqsArn,
|
|
78
|
+
awsRoleToAssume
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
module.exports = {
|
|
86
|
+
PlatformConfigService,
|
|
87
|
+
SupportedRegions,
|
|
88
|
+
SupportedEnvironments,
|
|
89
|
+
SupportedDeploymentTypes
|
|
90
|
+
}
|
|
91
|
+
</code></pre>
|
|
92
|
+
</article>
|
|
93
|
+
</section>
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
</div>
|
|
99
|
+
|
|
100
|
+
<nav>
|
|
101
|
+
<h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="AwsCredentialsService.html">AwsCredentialsService</a></li><li><a href="AwsProfile.html">AwsProfile</a></li><li><a href="CaddyService.html">CaddyService</a></li><li><a href="ContainerServer.html">ContainerServer</a></li><li><a href="DeploymentQueueService.html">DeploymentQueueService</a></li><li><a href="DeploymentToolsService.html">DeploymentToolsService</a></li><li><a href="DockerService.html">DockerService</a></li><li><a href="EstablishTrustStack.html">EstablishTrustStack</a></li><li><a href="PlatformConfigService.html">PlatformConfigService</a></li><li><a href="PlatformDeploymentService.html">PlatformDeploymentService</a></li><li><a href="PlatformServerService.html">PlatformServerService</a></li><li><a href="PlatformStack.html">PlatformStack</a></li><li><a href="PlatformTemplateService.html">PlatformTemplateService</a></li><li><a href="RestApiService.html">RestApiService</a></li></ul><h3><a href="global.html">Global</a></h3>
|
|
102
|
+
</nav>
|
|
103
|
+
|
|
104
|
+
<br class="clear">
|
|
105
|
+
|
|
106
|
+
<footer>
|
|
107
|
+
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 3.6.11</a> on Sun Oct 23 2022 22:23:31 GMT+0200 (Central European Summer Time)
|
|
108
|
+
</footer>
|
|
109
|
+
|
|
110
|
+
<script> prettyPrint(); </script>
|
|
111
|
+
<script src="scripts/linenumber.js"> </script>
|
|
112
|
+
</body>
|
|
113
|
+
</html>
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="utf-8">
|
|
5
|
+
<title>JSDoc: Source: deploy/platform-deployment.js</title>
|
|
6
|
+
|
|
7
|
+
<script src="scripts/prettify/prettify.js"> </script>
|
|
8
|
+
<script src="scripts/prettify/lang-css.js"> </script>
|
|
9
|
+
<!--[if lt IE 9]>
|
|
10
|
+
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
|
|
11
|
+
<![endif]-->
|
|
12
|
+
<link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
|
|
13
|
+
<link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css">
|
|
14
|
+
</head>
|
|
15
|
+
|
|
16
|
+
<body>
|
|
17
|
+
|
|
18
|
+
<div id="main">
|
|
19
|
+
|
|
20
|
+
<h1 class="page-title">Source: deploy/platform-deployment.js</h1>
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
<section>
|
|
28
|
+
<article>
|
|
29
|
+
<pre class="prettyprint source linenums"><code>const { resolve } = require('path')
|
|
30
|
+
const { readFileSync } = require('fs')
|
|
31
|
+
const { PlatformTemplateService } = require('../template')
|
|
32
|
+
const { PlatformConfigService, SupportedDeploymentTypes } = require('../config')
|
|
33
|
+
const { DeploymentQueueService } = require('../deployment-queue')
|
|
34
|
+
const { logError } = require('../log')
|
|
35
|
+
|
|
36
|
+
// export interface DeploymentTemplate {
|
|
37
|
+
// type: SupportedDeploymentTypes;
|
|
38
|
+
// targetDeploymentPlatform: string;
|
|
39
|
+
// subdomain?: string;
|
|
40
|
+
// env?: {
|
|
41
|
+
// shared?: { [name: string]: string | number };
|
|
42
|
+
// prod?: { [name: string]: string | number };
|
|
43
|
+
// test?: { [name: string]: string | number };
|
|
44
|
+
// qa?: { [name: string]: string | number };
|
|
45
|
+
// }
|
|
46
|
+
// }
|
|
47
|
+
|
|
48
|
+
// export interface ContainerDeploymentTemplate extends DeploymentTemplate {
|
|
49
|
+
// type: SupportedDeploymentTypes.Container;
|
|
50
|
+
// dockerFile: string;
|
|
51
|
+
// dockerContext: string;
|
|
52
|
+
// image: string;
|
|
53
|
+
// hostPort: number;
|
|
54
|
+
// containerPort: number;
|
|
55
|
+
// registry: string;
|
|
56
|
+
// }
|
|
57
|
+
|
|
58
|
+
// export interface ContainerDeploymentRequest extends ContainerDeploymentTemplate {
|
|
59
|
+
// authentication?: string;
|
|
60
|
+
// username?: string;
|
|
61
|
+
// }
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* @class
|
|
65
|
+
*/
|
|
66
|
+
class PlatformDeploymentService {
|
|
67
|
+
|
|
68
|
+
static deploy({
|
|
69
|
+
username,
|
|
70
|
+
authentication,
|
|
71
|
+
targetEnvironment,
|
|
72
|
+
pathToPlatformTemplates,
|
|
73
|
+
pathToOssyFile
|
|
74
|
+
}) {
|
|
75
|
+
|
|
76
|
+
const platformConfigRequest = PlatformTemplateService.readFromFile(pathToPlatformTemplates)
|
|
77
|
+
.then(templates => templates.map(x => ({ ...x, activeEnvironment: targetEnvironment })))
|
|
78
|
+
.then(templates => templates.map(x => PlatformConfigService.from(x)))
|
|
79
|
+
|
|
80
|
+
const deploymentTemplatesRequest = PlatformDeploymentService.getDeploymentTemplates(pathToOssyFile)
|
|
81
|
+
|
|
82
|
+
return Promise.all([platformConfigRequest, deploymentTemplatesRequest])
|
|
83
|
+
.then(([platformConfigs, deploymentTemplates]) => {
|
|
84
|
+
deploymentTemplates.map(deploymentTemplate => {
|
|
85
|
+
|
|
86
|
+
const platformConfig = platformConfigs.find(config => config.platformName === deploymentTemplate.targetDeploymentPlatform)
|
|
87
|
+
|
|
88
|
+
if (!platformConfig) {
|
|
89
|
+
logError({ message: `[PlatformDeploymentService] Could not find a deployment platform with the name ${deploymentTemplate.targetDeploymentPlatform}` })
|
|
90
|
+
return Promise.reject()
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0'
|
|
94
|
+
|
|
95
|
+
if (deploymentTemplate.type !== SupportedDeploymentTypes.Container) {
|
|
96
|
+
logError({ message: `[PlatformDeploymentService] Unsupported deployment type of ${deploymentTemplate.type}` })
|
|
97
|
+
return Promise.reject()
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
const deploymentRequest = {
|
|
101
|
+
...deploymentTemplate,
|
|
102
|
+
env: PlatformDeploymentService.getEnvironmentVariables(targetEnvironment, deploymentTemplate),
|
|
103
|
+
username: username,
|
|
104
|
+
authentication: authentication
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
return DeploymentQueueService.sendDeploymentRequest(platformConfig, deploymentRequest)
|
|
108
|
+
|
|
109
|
+
})
|
|
110
|
+
})
|
|
111
|
+
.catch(error => logError({ message: '[PlatformDeploymentService] Could not send deployment request', error }))
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
static getDeploymentTemplates(pathToOssyFile) {
|
|
115
|
+
if (!pathToOssyFile) return logError({ message: '[PlatformDeploymentService] No path to ossy.json provided' })
|
|
116
|
+
const ossyfile = JSON.parse(readFileSync(resolve(pathToOssyFile), 'utf8'))
|
|
117
|
+
return Promise.resolve(ossyfile.deployments || [])
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
static getEnvironmentVariables(targetEnvironment, deploymentRequest) {
|
|
121
|
+
const envs = deploymentRequest.env || {}
|
|
122
|
+
return {
|
|
123
|
+
...(envs.shared || {}),
|
|
124
|
+
...(envs[targetEnvironment] || {})
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
module.exports = {
|
|
131
|
+
PlatformDeploymentService
|
|
132
|
+
}
|
|
133
|
+
</code></pre>
|
|
134
|
+
</article>
|
|
135
|
+
</section>
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
</div>
|
|
141
|
+
|
|
142
|
+
<nav>
|
|
143
|
+
<h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="AwsCredentialsService.html">AwsCredentialsService</a></li><li><a href="AwsProfile.html">AwsProfile</a></li><li><a href="CaddyService.html">CaddyService</a></li><li><a href="ContainerServer.html">ContainerServer</a></li><li><a href="DeploymentQueueService.html">DeploymentQueueService</a></li><li><a href="DeploymentToolsService.html">DeploymentToolsService</a></li><li><a href="DockerService.html">DockerService</a></li><li><a href="EstablishTrustStack.html">EstablishTrustStack</a></li><li><a href="PlatformConfigService.html">PlatformConfigService</a></li><li><a href="PlatformDeploymentService.html">PlatformDeploymentService</a></li><li><a href="PlatformServerService.html">PlatformServerService</a></li><li><a href="PlatformStack.html">PlatformStack</a></li><li><a href="PlatformTemplateService.html">PlatformTemplateService</a></li><li><a href="RestApiService.html">RestApiService</a></li></ul><h3><a href="global.html">Global</a></h3>
|
|
144
|
+
</nav>
|
|
145
|
+
|
|
146
|
+
<br class="clear">
|
|
147
|
+
|
|
148
|
+
<footer>
|
|
149
|
+
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 3.6.11</a> on Sun Oct 23 2022 22:23:31 GMT+0200 (Central European Summer Time)
|
|
150
|
+
</footer>
|
|
151
|
+
|
|
152
|
+
<script> prettyPrint(); </script>
|
|
153
|
+
<script src="scripts/linenumber.js"> </script>
|
|
154
|
+
</body>
|
|
155
|
+
</html>
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="utf-8">
|
|
5
|
+
<title>JSDoc: Source: deployment-queue/deployment-queue.js</title>
|
|
6
|
+
|
|
7
|
+
<script src="scripts/prettify/prettify.js"> </script>
|
|
8
|
+
<script src="scripts/prettify/lang-css.js"> </script>
|
|
9
|
+
<!--[if lt IE 9]>
|
|
10
|
+
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
|
|
11
|
+
<![endif]-->
|
|
12
|
+
<link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
|
|
13
|
+
<link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css">
|
|
14
|
+
</head>
|
|
15
|
+
|
|
16
|
+
<body>
|
|
17
|
+
|
|
18
|
+
<div id="main">
|
|
19
|
+
|
|
20
|
+
<h1 class="page-title">Source: deployment-queue/deployment-queue.js</h1>
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
<section>
|
|
28
|
+
<article>
|
|
29
|
+
<pre class="prettyprint source linenums"><code>const {
|
|
30
|
+
SQSClient,
|
|
31
|
+
SendMessageCommand,
|
|
32
|
+
DeleteMessageCommand,
|
|
33
|
+
ReceiveMessageCommand
|
|
34
|
+
} = require('@aws-sdk/client-sqs')
|
|
35
|
+
const { AwsCredentialsService } = require('../aws-credentials')
|
|
36
|
+
const { logInfo, logError, logDebug } = require('../log')
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* @class
|
|
40
|
+
*/
|
|
41
|
+
class DeploymentQueueService {
|
|
42
|
+
|
|
43
|
+
static sendDeploymentRequest(platformConfig, deploymentRequest) {
|
|
44
|
+
logInfo({ message: '[DeploymentQueueService] Starting deployment sequence' })
|
|
45
|
+
return DeploymentQueueService.createAwsSqsClient(platformConfig)
|
|
46
|
+
.then(sqsClient => {
|
|
47
|
+
|
|
48
|
+
const sendMessageParams = {
|
|
49
|
+
QueueUrl: platformConfig.awsDeploymentSqsArn,
|
|
50
|
+
MessageBody: JSON.stringify(deploymentRequest)
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
logDebug({ message: '[DeploymentQueueService] SendMessageCommand params', data: sendMessageParams })
|
|
54
|
+
const command = new SendMessageCommand(sendMessageParams)
|
|
55
|
+
|
|
56
|
+
return sqsClient.send(command)
|
|
57
|
+
.then(() => logInfo({ message: '[DeploymentQueueService] Deployment request sent' }))
|
|
58
|
+
.catch(error => logError({ message: '[DeploymentQueueService] Could not send deployment request', error }))
|
|
59
|
+
})
|
|
60
|
+
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
static pollForDeploymentRequests(platformConfig, handleDeploymentRequest) {
|
|
64
|
+
logInfo({ message: '[DeploymentQueueService] Starting polling for deployment requests' })
|
|
65
|
+
DeploymentQueueService.createAwsSqsClient(platformConfig).then(sqsClient => {
|
|
66
|
+
const FIVE_MINUTES = 3000
|
|
67
|
+
|
|
68
|
+
setInterval(() => {
|
|
69
|
+
|
|
70
|
+
const receiveMessageCommand = new ReceiveMessageCommand({ QueueUrl: platformConfig.awsDeploymentSqsArn })
|
|
71
|
+
|
|
72
|
+
sqsClient.send(receiveMessageCommand)
|
|
73
|
+
.then(data => data.Messages.map(message => {
|
|
74
|
+
|
|
75
|
+
logInfo({ message: '[DeploymentQueueService] Received deployment request' })
|
|
76
|
+
|
|
77
|
+
handleDeploymentRequest(JSON.parse(message.Body))
|
|
78
|
+
.then(() => {
|
|
79
|
+
|
|
80
|
+
const deleteMessageCommand = new DeleteMessageCommand({
|
|
81
|
+
QueueUrl: platformConfig.awsDeploymentSqsArn,
|
|
82
|
+
ReceiptHandle: message.ReceiptHandle
|
|
83
|
+
})
|
|
84
|
+
|
|
85
|
+
sqsClient.send(deleteMessageCommand)
|
|
86
|
+
.then(() => logInfo({ message: '[DeploymentQueueService] Removing deployment request from queue' }))
|
|
87
|
+
.catch(error => logError({ message: '[DeploymentQueueService] Could not delete message from queue', error }))
|
|
88
|
+
})
|
|
89
|
+
|
|
90
|
+
}))
|
|
91
|
+
.catch(error => logError({ message: '[ContainerManagerServer] Could not handle incoming deployment request', error }))
|
|
92
|
+
}, FIVE_MINUTES)
|
|
93
|
+
|
|
94
|
+
})
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
static createAwsSqsClient(platformConfig) {
|
|
98
|
+
return AwsCredentialsService.resolveAwsCredentials(platformConfig)
|
|
99
|
+
.then(awsCredentials => new SQSClient({
|
|
100
|
+
region: platformConfig.awsRegion,
|
|
101
|
+
credentials: awsCredentials
|
|
102
|
+
}))
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
module.exports = {
|
|
108
|
+
DeploymentQueueService
|
|
109
|
+
}
|
|
110
|
+
</code></pre>
|
|
111
|
+
</article>
|
|
112
|
+
</section>
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
</div>
|
|
118
|
+
|
|
119
|
+
<nav>
|
|
120
|
+
<h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="AwsCredentialsService.html">AwsCredentialsService</a></li><li><a href="AwsProfile.html">AwsProfile</a></li><li><a href="CaddyService.html">CaddyService</a></li><li><a href="ContainerServer.html">ContainerServer</a></li><li><a href="DeploymentQueueService.html">DeploymentQueueService</a></li><li><a href="DeploymentToolsService.html">DeploymentToolsService</a></li><li><a href="DockerService.html">DockerService</a></li><li><a href="EstablishTrustStack.html">EstablishTrustStack</a></li><li><a href="PlatformConfigService.html">PlatformConfigService</a></li><li><a href="PlatformDeploymentService.html">PlatformDeploymentService</a></li><li><a href="PlatformServerService.html">PlatformServerService</a></li><li><a href="PlatformStack.html">PlatformStack</a></li><li><a href="PlatformTemplateService.html">PlatformTemplateService</a></li><li><a href="RestApiService.html">RestApiService</a></li></ul><h3><a href="global.html">Global</a></h3>
|
|
121
|
+
</nav>
|
|
122
|
+
|
|
123
|
+
<br class="clear">
|
|
124
|
+
|
|
125
|
+
<footer>
|
|
126
|
+
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 3.6.11</a> on Sun Oct 23 2022 22:23:31 GMT+0200 (Central European Summer Time)
|
|
127
|
+
</footer>
|
|
128
|
+
|
|
129
|
+
<script> prettyPrint(); </script>
|
|
130
|
+
<script src="scripts/linenumber.js"> </script>
|
|
131
|
+
</body>
|
|
132
|
+
</html>
|
|
Binary file
|