@ossy/deployment-tools 0.0.45 → 0.0.46
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 +30 -4
- package/cdk.context.json +37 -0
- package/cdk.json +40 -0
- package/package.json +17 -6
- package/src/aws-credentials/aws-credentials.js +74 -0
- package/src/aws-credentials/cli.js +28 -0
- package/src/aws-credentials/index.js +1 -0
- package/src/config/index.js +1 -0
- package/src/{platform-config.js → config/platform-config.js} +20 -2
- package/src/{cli-commands/deploy-handler.js → deploy/cli.js} +9 -7
- package/src/deploy/platform-deployment.js +74 -0
- package/src/{deployment-queue-client.js → deployment-queue/deployment-queue.js} +15 -15
- package/src/deployment-queue/index.js +1 -0
- package/src/index.js +2 -6
- package/src/infrastructure/cli.js +30 -0
- package/src/infrastructure/container-server/aws-profile.js +22 -0
- package/src/infrastructure/container-server/caddy.service.js +69 -0
- package/src/infrastructure/container-server/container-server.js +175 -0
- package/src/infrastructure/container-server/deployment-tools.service.js +37 -0
- package/src/infrastructure/container-server/index.js +3 -0
- package/src/infrastructure/container-server/user-data-commands.js +32 -0
- package/src/infrastructure/establish-trust-stack.js +65 -0
- package/src/infrastructure/platform-stack.js +53 -0
- package/src/{caddy-client.js → server/caddy.js} +9 -9
- package/src/server/cli.js +34 -0
- package/src/{docker-client.js → server/docker.js} +11 -10
- package/src/server/platform-server.js +37 -0
- package/src/{ci-rest-api.js → server/rest-api.js} +4 -4
- package/src/template/cli.js +22 -0
- package/src/template/index.js +1 -0
- package/src/{platform-template.js → template/platform-template.js} +2 -1
- package/src/types.js +0 -39
- package/src/aws-credentials-client.js +0 -47
- package/src/cli-commands/index.js +0 -27
- package/src/cli-commands/start-handler.js +0 -28
- package/src/cli-commands/status-handler.js +0 -11
- package/src/cli-commands/stop-handler.js +0 -11
- package/src/platform-cli.js +0 -7
- package/src/platform-client.js +0 -99
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
const core = require('@actions/core')
|
|
2
|
-
const { STSClient, AssumeRoleWithWebIdentityCommand } = require('@aws-sdk/client-sts')
|
|
3
|
-
const { logInfo, logError } = require('./log')
|
|
4
|
-
|
|
5
|
-
class AwsCredentialsClient {
|
|
6
|
-
|
|
7
|
-
static resolveAwsCredentials(platformConfig) {
|
|
8
|
-
// If awsRoleToAssume is present, then we assume we run in a github workflow
|
|
9
|
-
// If awsRoleToAssume is not present, then we assume they are resolved localy by aws-sdk
|
|
10
|
-
if (!platformConfig.awsRoleToAssume) {
|
|
11
|
-
logInfo({ message: '[AwsCredentialsClient] No aws role to assume was found, leaving auth logic to @aws-sdk package' })
|
|
12
|
-
return Promise.resolve(undefined)
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
const stsClient = new STSClient({ region: platformConfig.awsRegion })
|
|
16
|
-
|
|
17
|
-
logInfo({ message: '[AwsCredentialsClient] Fetching GitHub ID token' })
|
|
18
|
-
return core.getIDToken('sts.amazonaws.com')
|
|
19
|
-
.then(webIdentityToken => {
|
|
20
|
-
logInfo({ message: `[AwsCredentialsClient] Attempting to resolve aws credentials by assuming the role: ${platformConfig.awsRoleToAssume}` })
|
|
21
|
-
return stsClient.send(new AssumeRoleWithWebIdentityCommand({
|
|
22
|
-
RoleArn: `arn:aws:iam::${platformConfig.awsAccountId}:role/${platformConfig.awsRoleToAssume}`,
|
|
23
|
-
RoleSessionName: 'GitHubActions',
|
|
24
|
-
DurationSeconds: 15 * 60,
|
|
25
|
-
WebIdentityToken: webIdentityToken
|
|
26
|
-
}))
|
|
27
|
-
})
|
|
28
|
-
.then(responseData => ({
|
|
29
|
-
// Don't ask
|
|
30
|
-
AccessKeyId: responseData.Credentials.AccessKeyId,
|
|
31
|
-
SessionToken: responseData.Credentials.SessionToken,
|
|
32
|
-
SecretAccessKey: responseData.Credentials.SecretAccessKey,
|
|
33
|
-
accessKeyId: responseData.Credentials.AccessKeyId,
|
|
34
|
-
sessionToken: responseData.Credentials.SessionToken,
|
|
35
|
-
secretAccessKey: responseData.Credentials.SecretAccessKey
|
|
36
|
-
}))
|
|
37
|
-
.catch(error => {
|
|
38
|
-
logError({ message: '[AwsCredentialsClient] Could not resolve temporary credentials', error })
|
|
39
|
-
return undefined
|
|
40
|
-
})
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
module.exports = {
|
|
46
|
-
AwsCredentialsClient
|
|
47
|
-
}
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
const { logError } = require('../log')
|
|
2
|
-
const { startHandler } = require('./start-handler')
|
|
3
|
-
const { stopHandler } = require('./stop-handler')
|
|
4
|
-
const { statusHandler } = require('./status-handler')
|
|
5
|
-
const { deployHandler } = require('./deploy-handler')
|
|
6
|
-
|
|
7
|
-
const runCliCommand = ({ name, args }) => {
|
|
8
|
-
|
|
9
|
-
if (!name) return logError({ message: 'No command provided' })
|
|
10
|
-
|
|
11
|
-
const commandHandler = {
|
|
12
|
-
start: startHandler,
|
|
13
|
-
stop: stopHandler,
|
|
14
|
-
status: statusHandler,
|
|
15
|
-
deploy: deployHandler
|
|
16
|
-
}[name]
|
|
17
|
-
|
|
18
|
-
if (!commandHandler) {
|
|
19
|
-
return logError({ message: 'Command not implemented, did you spell it correctly?' })
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
commandHandler(args)
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
module.exports = {
|
|
26
|
-
runCliCommand
|
|
27
|
-
}
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
const arg = require('arg')
|
|
2
|
-
const { platform } = require('os')
|
|
3
|
-
const { logInfo, logError } = require('../log')
|
|
4
|
-
const { PlatformClient } = require('../platform-client')
|
|
5
|
-
|
|
6
|
-
const startHandler = cliArgs => {
|
|
7
|
-
logInfo({ message: 'Running start command' })
|
|
8
|
-
|
|
9
|
-
const Platforms = {
|
|
10
|
-
windows: 'win32',
|
|
11
|
-
mac: 'darwin'
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
if ([Platforms.windows].includes(platform())) {
|
|
15
|
-
return logError({ message: 'Deployment tools do not support this os' })
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
const parsedArgs = arg({
|
|
19
|
-
'--platforms': String,
|
|
20
|
-
'-p': '--platforms'
|
|
21
|
-
}, { argv: cliArgs })
|
|
22
|
-
|
|
23
|
-
PlatformClient.start(parsedArgs['--platforms'])
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
module.exports = {
|
|
27
|
-
startHandler
|
|
28
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
const { exec } = require('child_process')
|
|
2
|
-
const { logInfo } = require('../log')
|
|
3
|
-
|
|
4
|
-
const statusHandler = () => {
|
|
5
|
-
logInfo({ message: 'Running status command' })
|
|
6
|
-
exec('systemctl status deployment-tools.service')
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
module.exports = {
|
|
10
|
-
statusHandler
|
|
11
|
-
}
|
package/src/platform-cli.js
DELETED
package/src/platform-client.js
DELETED
|
@@ -1,99 +0,0 @@
|
|
|
1
|
-
const { resolve } = require('path')
|
|
2
|
-
const { readFileSync } = require('fs')
|
|
3
|
-
const { SupportedDeploymentTypes } = require('./types')
|
|
4
|
-
const { PlatformTemplateService } = require('./platform-template')
|
|
5
|
-
const { PlatformConfigService } = require('./platform-config')
|
|
6
|
-
const { CaddyClient } = require('./caddy-client')
|
|
7
|
-
const { DockerClient } = require('./docker-client')
|
|
8
|
-
const { DeploymentQueueClient } = require('./deployment-queue-client')
|
|
9
|
-
const { CiRestApi } = require('./ci-rest-api')
|
|
10
|
-
const { logError } = require('./log')
|
|
11
|
-
|
|
12
|
-
// journalctl -u service-name.service
|
|
13
|
-
class PlatformClient {
|
|
14
|
-
|
|
15
|
-
static start(platformTemplatesFilePath) {
|
|
16
|
-
PlatformTemplateService.readFromFile(platformTemplatesFilePath).then(([firstPlatformTemplateFound]) => {
|
|
17
|
-
const platformConfig = PlatformConfigService.from(firstPlatformTemplateFound)
|
|
18
|
-
|
|
19
|
-
CiRestApi.start(platformConfig)
|
|
20
|
-
CaddyClient.applyDefaultServerConfig(platformConfig)
|
|
21
|
-
|
|
22
|
-
DeploymentQueueClient.pollForDeploymentRequests(
|
|
23
|
-
platformConfig,
|
|
24
|
-
deploymentRequest => {
|
|
25
|
-
DockerClient.deploy(platformConfig, deploymentRequest)
|
|
26
|
-
CaddyClient.deploy(platformConfig, deploymentRequest)
|
|
27
|
-
return Promise.resolve()
|
|
28
|
-
}
|
|
29
|
-
)
|
|
30
|
-
|
|
31
|
-
})
|
|
32
|
-
.catch(error => logError({ message: '[PlatformClient] Could not start the deployment platform', error }))
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
//eslint-disable-next-line max-params
|
|
36
|
-
static deploy({
|
|
37
|
-
username,
|
|
38
|
-
authentication,
|
|
39
|
-
targetEnvironment,
|
|
40
|
-
pathToPlatformTemplates,
|
|
41
|
-
pathToOssyFile
|
|
42
|
-
}) {
|
|
43
|
-
|
|
44
|
-
const platformConfigRequest = PlatformTemplateService.readFromFile(pathToPlatformTemplates)
|
|
45
|
-
.then(templates => templates.map(x => ({ ...x, activeEnvironment: targetEnvironment })))
|
|
46
|
-
.then(templates => templates.map(x => PlatformConfigService.from(x)))
|
|
47
|
-
|
|
48
|
-
const deploymentTemplatesRequest = PlatformClient.getDeploymentTemplates(pathToOssyFile)
|
|
49
|
-
|
|
50
|
-
return Promise.all([platformConfigRequest, deploymentTemplatesRequest])
|
|
51
|
-
.then(([platformConfigs, deploymentTemplates]) => {
|
|
52
|
-
deploymentTemplates.map(deploymentTemplate => {
|
|
53
|
-
|
|
54
|
-
const platformConfig = platformConfigs.find(config => config.platformName === deploymentTemplate.targetDeploymentPlatform)
|
|
55
|
-
|
|
56
|
-
if (!platformConfig) {
|
|
57
|
-
logError({ message: `[PlatformClient] Could not find a deployment platform with the name ${deploymentTemplate.targetDeploymentPlatform}` })
|
|
58
|
-
return Promise.reject()
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0'
|
|
62
|
-
|
|
63
|
-
if (deploymentTemplate.type !== SupportedDeploymentTypes.Container) {
|
|
64
|
-
logError({ message: `[PlatformClient] Unsupported deployment type of ${deploymentTemplate.type}` })
|
|
65
|
-
return Promise.reject()
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
const deploymentRequest = {
|
|
69
|
-
...deploymentTemplate,
|
|
70
|
-
env: PlatformClient.getEnvironmentVariables(targetEnvironment, deploymentTemplate),
|
|
71
|
-
username: username,
|
|
72
|
-
authentication: authentication
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
return DeploymentQueueClient.sendDeploymentRequest(platformConfig, deploymentRequest)
|
|
76
|
-
|
|
77
|
-
})
|
|
78
|
-
})
|
|
79
|
-
.catch(error => logError({ message: '[PlatformClient] Could not send deployment request', error }))
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
static getDeploymentTemplates(pathToOssyFile) {
|
|
83
|
-
const ossyfile = JSON.parse(readFileSync(resolve(pathToOssyFile), 'utf8'))
|
|
84
|
-
return Promise.resolve(ossyfile.deployments || [])
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
static getEnvironmentVariables(targetEnvironment, deploymentRequest) {
|
|
88
|
-
const envs = deploymentRequest.env || {}
|
|
89
|
-
return {
|
|
90
|
-
...(envs.shared || {}),
|
|
91
|
-
...(envs[targetEnvironment] || {})
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
module.exports = {
|
|
98
|
-
PlatformClient
|
|
99
|
-
}
|