@ossy/deployment-tools 1.17.4 → 1.17.6

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.
Files changed (78) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/README.md +86 -86
  3. package/package.json +3 -7
  4. package/src/index.cli.js +0 -2
  5. package/src/infrastructure/cli.js +0 -5
  6. package/src/infrastructure/container-deployment-target/caddy.service.js +28 -10
  7. package/src/infrastructure/container-deployment-target/container-deployment-target.js +10 -24
  8. package/src/infrastructure/container-deployment-target/ossy-api.service.js +43 -0
  9. package/src/infrastructure/container-deployment-target/ossy-runtime.service.js +37 -0
  10. package/src/infrastructure/container-deployment-target/user-data-commands.js +1 -1
  11. package/jsdoc/AwsCredentialsService.html +0 -166
  12. package/jsdoc/AwsProfile.html +0 -166
  13. package/jsdoc/CaddyService.html +0 -293
  14. package/jsdoc/ContainerServer.html +0 -265
  15. package/jsdoc/DeploymentQueueService.html +0 -166
  16. package/jsdoc/DeploymentToolsService.html +0 -166
  17. package/jsdoc/DockerService.html +0 -166
  18. package/jsdoc/EstablishTrustStack.html +0 -268
  19. package/jsdoc/PlatformConfigService.html +0 -166
  20. package/jsdoc/PlatformDeploymentService.html +0 -166
  21. package/jsdoc/PlatformServerService.html +0 -166
  22. package/jsdoc/PlatformStack.html +0 -166
  23. package/jsdoc/PlatformTemplateService.html +0 -502
  24. package/jsdoc/RestApiService.html +0 -166
  25. package/jsdoc/aws-credentials_aws-credentials.js.html +0 -138
  26. package/jsdoc/config_platform-config.js.html +0 -113
  27. package/jsdoc/deploy_platform-deployment.js.html +0 -155
  28. package/jsdoc/deployment-queue_deployment-queue.js.html +0 -132
  29. package/jsdoc/fonts/OpenSans-Bold-webfont.eot +0 -0
  30. package/jsdoc/fonts/OpenSans-Bold-webfont.svg +0 -1830
  31. package/jsdoc/fonts/OpenSans-Bold-webfont.woff +0 -0
  32. package/jsdoc/fonts/OpenSans-BoldItalic-webfont.eot +0 -0
  33. package/jsdoc/fonts/OpenSans-BoldItalic-webfont.svg +0 -1830
  34. package/jsdoc/fonts/OpenSans-BoldItalic-webfont.woff +0 -0
  35. package/jsdoc/fonts/OpenSans-Italic-webfont.eot +0 -0
  36. package/jsdoc/fonts/OpenSans-Italic-webfont.svg +0 -1830
  37. package/jsdoc/fonts/OpenSans-Italic-webfont.woff +0 -0
  38. package/jsdoc/fonts/OpenSans-Light-webfont.eot +0 -0
  39. package/jsdoc/fonts/OpenSans-Light-webfont.svg +0 -1831
  40. package/jsdoc/fonts/OpenSans-Light-webfont.woff +0 -0
  41. package/jsdoc/fonts/OpenSans-LightItalic-webfont.eot +0 -0
  42. package/jsdoc/fonts/OpenSans-LightItalic-webfont.svg +0 -1835
  43. package/jsdoc/fonts/OpenSans-LightItalic-webfont.woff +0 -0
  44. package/jsdoc/fonts/OpenSans-Regular-webfont.eot +0 -0
  45. package/jsdoc/fonts/OpenSans-Regular-webfont.svg +0 -1831
  46. package/jsdoc/fonts/OpenSans-Regular-webfont.woff +0 -0
  47. package/jsdoc/global.html +0 -800
  48. package/jsdoc/index.html +0 -65
  49. package/jsdoc/infrastructure_container-server_aws-profile.js.html +0 -76
  50. package/jsdoc/infrastructure_container-server_caddy.service.js.html +0 -123
  51. package/jsdoc/infrastructure_container-server_container-server.js.html +0 -229
  52. package/jsdoc/infrastructure_container-server_deployment-tools.service.js.html +0 -91
  53. package/jsdoc/infrastructure_establish-trust-stack.js.html +0 -119
  54. package/jsdoc/infrastructure_platform-stack.js.html +0 -107
  55. package/jsdoc/scripts/linenumber.js +0 -25
  56. package/jsdoc/scripts/prettify/Apache-License-2.0.txt +0 -202
  57. package/jsdoc/scripts/prettify/lang-css.js +0 -2
  58. package/jsdoc/scripts/prettify/prettify.js +0 -28
  59. package/jsdoc/server_caddy.js.html +0 -165
  60. package/jsdoc/server_docker.js.html +0 -133
  61. package/jsdoc/server_platform-server.js.html +0 -91
  62. package/jsdoc/server_rest-api.js.html +0 -82
  63. package/jsdoc/styles/jsdoc-default.css +0 -358
  64. package/jsdoc/styles/prettify-jsdoc.css +0 -111
  65. package/jsdoc/styles/prettify-tomorrow.css +0 -132
  66. package/jsdoc/template_platform-template.js.html +0 -134
  67. package/jsdoc.config.js +0 -15
  68. package/src/deploy/cli.js +0 -60
  69. package/src/deploy/index.js +0 -1
  70. package/src/deploy/platform-deployment.js +0 -122
  71. package/src/deployment-queue/deployment-queue.js +0 -81
  72. package/src/deployment-queue/index.js +0 -1
  73. package/src/docker/docker-service.js +0 -136
  74. package/src/docker/docker-service.playground.js +0 -15
  75. package/src/docker/index.js +0 -1
  76. package/src/infrastructure/ecr-stack.js +0 -53
  77. package/src/server/cli.js +0 -34
  78. package/src/server/platform-server.js +0 -42
package/jsdoc.config.js DELETED
@@ -1,15 +0,0 @@
1
-
2
- module.exports = {
3
- recurseDepth: 10,
4
- source: {
5
- include: ['src'],
6
- includePattern: '\.js',
7
- exclude: ['node_modules']
8
- },
9
- opts: {
10
- // template: './template',
11
- destination: './jsdoc',
12
- recurse: true
13
- // tutorials: './tutorials'
14
- }
15
- }
package/src/deploy/cli.js DELETED
@@ -1,60 +0,0 @@
1
- #!/usr/bin/env node
2
- const arg = require('arg')
3
- const { PlatformDeploymentService } = require('./platform-deployment')
4
- const { logInfo, logError } = require('../log')
5
-
6
- const deploy = options => {
7
- logInfo({ message: '[CLI] Running deploy command' })
8
-
9
- const parsedArgs = arg({
10
- '--domain': String,
11
- '-d': '--domain',
12
-
13
- '--platform': String,
14
- '-p': '--platform',
15
-
16
- '--platforms-path': String,
17
- '-pp': '--platforms-path',
18
-
19
- '--deployments-path': String,
20
- '-dp': '--deployments-path',
21
-
22
- }, { argv: options })
23
-
24
- PlatformDeploymentService.deploy({
25
- targetDomain: parsedArgs['--domain'],
26
- targetPlatform: parsedArgs['--platform'],
27
- pathToPlatformTemplates: parsedArgs['--platforms-path'],
28
- pathToDeploymentTemplates: parsedArgs['--deployments-path']
29
- })
30
- }
31
-
32
- const deployAll = options => {
33
- logInfo({ message: '[CLI] Running deploy-all command' })
34
-
35
- const parsedArgs = arg({
36
- '--platform': String,
37
- '-p': '--platform',
38
-
39
- '--platforms-path': String,
40
- '-pp': '--platforms-path',
41
-
42
- '--deployments-path': String,
43
- '-dp': '--deployments-path',
44
-
45
- }, { argv: options })
46
-
47
- PlatformDeploymentService.deployAll({
48
- targetPlatform: parsedArgs['--platform'],
49
- pathToPlatformTemplates: parsedArgs['--platforms-path'],
50
- pathToDeploymentTemplates: parsedArgs['--deployments-path']
51
- })
52
- }
53
-
54
- module.exports = {
55
- handler: ([command, ...options]) => {
56
- !!command
57
- ? { deploy, 'deploy-all': deployAll }[command](options)
58
- : logError({ message: 'No command provided' })
59
- }
60
- }
@@ -1 +0,0 @@
1
- module.exports = require('./platform-deployment.js')
@@ -1,122 +0,0 @@
1
- const { PlatformTemplateService, DeploymentTemplateService } = require('../template')
2
- const { PlatformConfigService, SupportedDeploymentTypes } = require('../config')
3
- const { DeploymentQueueService } = require('../deployment-queue')
4
- const { DockerService } = require('../docker/docker-service')
5
- const { logError } = require('../log')
6
-
7
- function assertEcrContainer(deploymentTemplate) {
8
- const r = deploymentTemplate.registry
9
- if (!r || !DockerService.isEcrRegistry(r)) {
10
- logError({
11
- message:
12
- `[PlatformDeploymentService] ${deploymentTemplate.domain}: container deployments only support Amazon ECR. ` +
13
- 'Set `registry` in deployments JSON to your ECR hostname (e.g. 123456789012.dkr.ecr.eu-north-1.amazonaws.com).'
14
- })
15
- return false
16
- }
17
- return true
18
- }
19
-
20
- /**
21
- * @class
22
- */
23
- class PlatformDeploymentService {
24
-
25
- static deploy({
26
- targetDomain,
27
- targetPlatform,
28
- pathToPlatformTemplates,
29
- pathToDeploymentTemplates
30
- }) {
31
-
32
- return Promise.all([
33
- DeploymentTemplateService.readFromFiles(pathToDeploymentTemplates),
34
- PlatformTemplateService.readFromFile(pathToPlatformTemplates)
35
- .then(templates => templates.map(PlatformConfigService.from))
36
- ])
37
- .then(([deploymentTemplates, platformConfigs]) => {
38
-
39
- const platformConfig = platformConfigs.find(({ platformName }) => platformName === targetPlatform)
40
- const deploymentTemplatesForTargetPlatform = deploymentTemplates[targetPlatform] || [] //todo remove deploymentTargetPlatform
41
- const deploymentTemplate = deploymentTemplatesForTargetPlatform.find(({ domain }) => domain === targetDomain)
42
-
43
- if (!platformConfig) {
44
- logError({ message: `[PlatformDeploymentService] Could not find a platform named ${targetPlatform}` })
45
- return Promise.reject()
46
- }
47
-
48
- if (!deploymentTemplate) {
49
- logError({ message: `[PlatformDeploymentService] Could not find a deployment template for ${targetDomain} in ${targetPlatform}` })
50
- return Promise.reject()
51
- }
52
-
53
- process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0'
54
-
55
- if (deploymentTemplate.type === SupportedDeploymentTypes.Container) {
56
- if (!assertEcrContainer(deploymentTemplate)) {
57
- return Promise.reject()
58
- }
59
-
60
- const deploymentRequest = { ...deploymentTemplate }
61
-
62
- return DeploymentQueueService.sendDeploymentRequest(platformConfig, deploymentRequest)
63
- }
64
-
65
- logError({ message: `[PlatformDeploymentService] Unsupported deployment type of ${deploymentTemplate.type}` })
66
- return Promise.reject()
67
- })
68
- .catch(error => logError({ message: '[PlatformDeploymentService] Could not send deployment request', error }))
69
- }
70
-
71
- static deployAll({
72
- targetPlatform,
73
- pathToPlatformTemplates,
74
- pathToDeploymentTemplates
75
- }) {
76
-
77
- return Promise.all([
78
- DeploymentTemplateService.readFromFiles(pathToDeploymentTemplates),
79
- PlatformTemplateService.readFromFile(pathToPlatformTemplates)
80
- .then(templates => templates.map(PlatformConfigService.from))
81
- ])
82
- .then(([deploymentTemplates, platformConfigs]) => {
83
-
84
- const platformConfig = platformConfigs.find(({ platformName }) => platformName === targetPlatform)
85
- const deploymentTemplatesForTargetPlatform = deploymentTemplates[targetPlatform] || []
86
-
87
- if (!platformConfig) {
88
- logError({ message: `[PlatformDeploymentService] Could not find a platform named ${targetPlatform}` })
89
- return Promise.reject()
90
- }
91
-
92
- if (deploymentTemplatesForTargetPlatform.length === 0) {
93
- logError({ message: `[PlatformDeploymentService] Could not find any deployment templates for platform ${targetPlatform}` })
94
- return Promise.reject()
95
- }
96
-
97
- process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0'
98
-
99
- return deploymentTemplatesForTargetPlatform.map(deploymentTemplate => {
100
- if (deploymentTemplate.type === SupportedDeploymentTypes.Container) {
101
- if (!assertEcrContainer(deploymentTemplate)) {
102
- return Promise.reject()
103
- }
104
-
105
- const deploymentRequest = { ...deploymentTemplate }
106
-
107
- return DeploymentQueueService.sendDeploymentRequest(platformConfig, deploymentRequest)
108
- }
109
-
110
- logError({ message: `[PlatformDeploymentService] Unsupported deployment type of ${deploymentTemplate.type}` })
111
- return Promise.reject()
112
- })
113
-
114
- })
115
- .catch(error => logError({ message: '[PlatformDeploymentService] Could not send deployment request', error }))
116
- }
117
-
118
- }
119
-
120
- module.exports = {
121
- PlatformDeploymentService
122
- }
@@ -1,81 +0,0 @@
1
- const {
2
- SQSClient,
3
- SendMessageCommand,
4
- DeleteMessageCommand,
5
- ReceiveMessageCommand
6
- } = require('@aws-sdk/client-sqs')
7
- const { AwsCredentialsService } = require('../aws-credentials')
8
- const { logInfo, logError, logDebug } = require('../log')
9
-
10
- /**
11
- * @class
12
- */
13
- class DeploymentQueueService {
14
-
15
- static sendDeploymentRequest(platformConfig, deploymentRequest) {
16
- logInfo({ message: '[DeploymentQueueService] Starting deployment sequence' })
17
- return DeploymentQueueService.createAwsSqsClient(platformConfig)
18
- .then(sqsClient => {
19
-
20
- const sendMessageParams = {
21
- QueueUrl: platformConfig.awsDeploymentSqsArn,
22
- MessageBody: JSON.stringify(deploymentRequest)
23
- }
24
-
25
- logDebug({ message: '[DeploymentQueueService] SendMessageCommand params', data: sendMessageParams })
26
- const command = new SendMessageCommand(sendMessageParams)
27
-
28
- return sqsClient.send(command)
29
- .then(() => logInfo({ message: '[DeploymentQueueService] Deployment request sent' }))
30
- .catch(error => logError({ message: '[DeploymentQueueService] Could not send deployment request', error }))
31
- })
32
-
33
- }
34
-
35
- static pollForDeploymentRequests(platformConfig, handleDeploymentRequest) {
36
- logInfo({ message: '[DeploymentQueueService] Starting polling for deployment requests' })
37
- DeploymentQueueService.createAwsSqsClient(platformConfig).then(sqsClient => {
38
- const FIVE_MINUTES = 300000
39
-
40
- setInterval(() => {
41
-
42
- const receiveMessageCommand = new ReceiveMessageCommand({ QueueUrl: platformConfig.awsDeploymentSqsArn })
43
-
44
- sqsClient.send(receiveMessageCommand)
45
- .then(data => data && data.Messages && data.Messages.map(message => {
46
-
47
- logInfo({ message: '[DeploymentQueueService] Received deployment request' })
48
-
49
- handleDeploymentRequest(JSON.parse(message.Body))
50
- .then(() => {
51
-
52
- const deleteMessageCommand = new DeleteMessageCommand({
53
- QueueUrl: platformConfig.awsDeploymentSqsArn,
54
- ReceiptHandle: message.ReceiptHandle
55
- })
56
-
57
- sqsClient.send(deleteMessageCommand)
58
- .then(() => logInfo({ message: '[DeploymentQueueService] Removing deployment request from queue' }))
59
- .catch(error => logError({ message: '[DeploymentQueueService] Could not delete message from queue', error }))
60
- })
61
-
62
- }))
63
- .catch(error => logError({ message: '[DeploymentQueueService] Could not handle incoming deployment request', error }))
64
- }, FIVE_MINUTES)
65
-
66
- })
67
- }
68
-
69
- static createAwsSqsClient(platformConfig) {
70
- return AwsCredentialsService.resolveAwsCredentials(platformConfig)
71
- .then(awsCredentials => new SQSClient({
72
- region: platformConfig.awsRegion,
73
- credentials: awsCredentials
74
- }))
75
- }
76
-
77
- }
78
-
79
- module.exports = {
80
- DeploymentQueueService
81
- }
@@ -1 +0,0 @@
1
- module.exports = require('./deployment-queue')
@@ -1,136 +0,0 @@
1
- const { exec: execBash } = require('child_process')
2
- const { logInfo, logError, logDebug, logErrorAndReject } = require('../log')
3
-
4
- const exec = command => new Promise((resolve, reject) => {
5
- execBash(command, (error, stdout, stderr) => {
6
- logInfo({ message: `[DockerService] ${stderr}` })
7
-
8
- if (error) return reject({ error, stderr })
9
- resolve(stdout, stderr)
10
- })
11
- })
12
-
13
- /**
14
- * @class
15
- */
16
- class DockerService {
17
-
18
- static isEcrRegistry(registry) {
19
- return (
20
- typeof registry === 'string' &&
21
- registry.includes('.dkr.ecr.') &&
22
- registry.includes('amazonaws.com')
23
- )
24
- }
25
-
26
- /**
27
- * Log in to ECR using the host credentials (EC2 instance profile, env keys, etc.).
28
- * Requires AWS CLI v2 on the worker (`aws ecr get-login-password`).
29
- */
30
- static ecrLoginViaAwsCli(registry) {
31
- const m =
32
- typeof registry === 'string' &&
33
- registry.match(/\.dkr\.ecr\.([a-z0-9-]+)\.amazonaws\.com/)
34
- const region = (m && m[1]) || process.env.AWS_DEFAULT_REGION || 'eu-north-1'
35
- logInfo({ message: `[DockerService] ECR login via IAM for ${registry} (region ${region})` })
36
- return exec(
37
- `bash -c 'aws ecr get-login-password --region ${region} | docker login --username AWS --password-stdin ${registry}'`
38
- ).catch(logErrorAndReject(`[DockerService] Could not IAM-login to ECR ${registry}`))
39
- }
40
-
41
- static startDefaultContainers(platformConfig) {
42
- logInfo({ message: '[DockerService] Starting default containers' })
43
- return exec(`docker run -d --name=mongodb --network=${platformConfig.ciDockerNetworkName} --network-alias=mongodb --rm mongo`)
44
- .catch(() => {
45
- logError({ message: '[DockerService] Faild to start default containers' })
46
- })
47
- }
48
-
49
- static createDockerNetworkForContainerManagerServer(platformConfig) {
50
- logInfo({ message: '[DockerService] Creating docker network for comunication between containers' })
51
- return exec(`docker network create ${platformConfig.ciDockerNetworkName}`)
52
- .catch(() => {
53
- /* if it fails it's probably because the network already exists*/
54
- logError({ message: '[DockerService] Faild to start default containers' })
55
- })
56
- }
57
-
58
- static stopContainer(deploymentRequest) {
59
- logInfo({ message: `[DockerService] Stopping container for ${deploymentRequest.domain}` })
60
- return exec(`docker stop c-${deploymentRequest.domain}`)
61
- .catch(() => {
62
- logError({ message: `[DockerService] Faild to stop container for ${deploymentRequest.domain}` })
63
- }) // no worries if container isn't there
64
- }
65
-
66
- static removeImage(deploymentRequest) {
67
- const { registry, image } = deploymentRequest
68
- const name = !!registry ? `${registry}/${image}` : image
69
- logInfo({ message: `[DockerService] Removing image ${name}` })
70
- return exec(`docker image rm -f ${name}`)
71
- .catch(() => {
72
- logError({ message: `[DockerService] Faild to remove image for ${deploymentRequest.domain}` })
73
- }) // no worries if container isn't there
74
- .then(() => exec(`docker rm -f c-${name}`))
75
- }
76
-
77
- static pullImage({ image, registry }) {
78
- const imageUrl = !!registry ? `${registry}/${image}` : image
79
- logInfo({ message: `[DockerService] Pulling image for ${image}:latest` })
80
- return exec(`docker image pull ${imageUrl}:latest`)
81
- .catch(logErrorAndReject(`[DockerService] Could pull image ${image}:latest`))
82
- }
83
-
84
- static startContainer(platformConfig, { image, containerPort, registry, env, domain }) {
85
- const imageUrl = !!registry ? `${registry}/${image}` : image
86
- const envsAsString = Object.entries(env || {}).reduce((envs, [name, value]) => `${envs} --env ${name}="${value}"`, '')
87
-
88
- return DockerService.getUnusedPort()
89
- .then(hostPort => {
90
- logInfo({ message: `[DockerService] Starting container for ${domain} with port mapping ${hostPort}:${containerPort} and source ${imageUrl}` })
91
- return exec(`docker run -d -p ${hostPort}:${containerPort} --name=c-${domain} --network=${platformConfig.ciDockerNetworkName} --network-alias=c-${domain} --rm ${envsAsString} ${imageUrl}`)
92
- .then(() => ({ hostPort }))
93
- .catch(logErrorAndReject(`[DockerService] Could not start container ${image}`))
94
- })
95
-
96
- }
97
-
98
- static resolveCredentials({ registry }) {
99
- if (!DockerService.isEcrRegistry(registry)) {
100
- return Promise.reject(
101
- new Error(
102
- `[DockerService] Only Amazon ECR is supported; registry was: ${registry ?? '(missing)'}`
103
- )
104
- )
105
- }
106
- return DockerService.ecrLoginViaAwsCli(registry)
107
- }
108
-
109
- static deploy(platformConfig, deploymentRequest) {
110
- logInfo({ message: '[DockerService] Starting docker deployment sequence' })
111
- logDebug({ message: '[DockerService] deploymentRequest', data: deploymentRequest })
112
-
113
- return DockerService.resolveCredentials(deploymentRequest)
114
- .then(() => DockerService.stopContainer(deploymentRequest))
115
- .then(() => DockerService.removeImage(deploymentRequest))
116
- .then(() => DockerService.pullImage(deploymentRequest))
117
- .then(() => DockerService.startContainer(platformConfig, deploymentRequest))
118
- .catch(logErrorAndReject('[DockerService] Deployment failed'))
119
- }
120
-
121
- static getUnusedPort() {
122
- // get-port is written in es6, so we need to import it like this
123
- return import('get-port')
124
- .then(module => {
125
- const getPort = module.default;
126
- const portNumbers = module.portNumbers;
127
-
128
- return getPort({ port: portNumbers(3000, 3200) })
129
- });
130
- }
131
-
132
- }
133
-
134
- module.exports = {
135
- DockerService
136
- }
@@ -1,15 +0,0 @@
1
- const { DockerService } = require('./docker-service')
2
-
3
-
4
- const deploymentTemplate = {
5
- "domain": "api.qa.ossy.se",
6
- "image": "ossy-se/api",
7
- "targetDeploymentPlatform": "ossybot",
8
- "type": "CONTAINER",
9
- "hostPort": "3001",
10
- "containerPort": "3000",
11
- }
12
-
13
- DockerService.pullImage(
14
- deploymentTemplate
15
- )
@@ -1 +0,0 @@
1
- module.exports = require('./docker-service')
@@ -1,53 +0,0 @@
1
- const { Stack, RemovalPolicy } = require('aws-cdk-lib')
2
- const { Repository, TagStatus } = require('aws-cdk-lib/aws-ecr')
3
- const { SupportedDeploymentTypes } = require('../config')
4
-
5
- /**
6
- * EcrStackProps
7
- * @typedef {Object} EcrStackProps
8
- * @property {PlatformConfig} config - platform config
9
- * @property {DeploymentTemplate[]} deployments - deployment templates
10
- */
11
-
12
- /**
13
- * Creates one ECR repository per unique container image name.
14
- * @class
15
- */
16
- class EcrStack extends Stack {
17
-
18
- /**
19
- * @param {object} scope
20
- * @param {string} id
21
- * @param {EcrStackProps} props
22
- */
23
- constructor(scope, id, props) {
24
- super(scope, id, props)
25
-
26
- const deployments = props.deployments || []
27
- const repositoryNames = [...new Set(
28
- deployments
29
- .filter(deployment => deployment.type === SupportedDeploymentTypes.Container)
30
- .map(deployment => deployment.image)
31
- .filter(Boolean)
32
- )]
33
-
34
- repositoryNames.forEach(repositoryName => {
35
- new Repository(this, `${repositoryName.replace(/[^A-Za-z0-9]/g, '-')}-repository`, {
36
- repositoryName,
37
- removalPolicy: RemovalPolicy.RETAIN,
38
- imageScanOnPush: true,
39
- lifecycleRules: [
40
- {
41
- description: 'Keep latest 5 tagged images',
42
- maxImageCount: 5,
43
- tagStatus: TagStatus.TAGGED
44
- }
45
- ]
46
- })
47
- })
48
- }
49
- }
50
-
51
- module.exports = {
52
- EcrStack
53
- }
package/src/server/cli.js DELETED
@@ -1,34 +0,0 @@
1
- const arg = require('arg')
2
- const { exec } = require('child_process')
3
- const { PlatformServerService } = require('./platform-server')
4
-
5
- const { logInfo, logError } = require('../log')
6
-
7
- const start = options => {
8
- logInfo({ message: 'Running start command' })
9
-
10
- const parsedArgs = arg({
11
- '--platforms': String,
12
- '-p': '--platforms'
13
- }, { argv: options })
14
-
15
- PlatformServerService.start(parsedArgs['--platforms'])
16
- }
17
-
18
- const status = () => {
19
- logInfo({ message: 'Running status command' })
20
- exec('systemctl status deployment-tools.service')
21
- }
22
-
23
- const stop = () => {
24
- logInfo({ message: 'Running stop command' })
25
- exec('systemctl stop deployment-tools.service')
26
- }
27
-
28
- module.exports = {
29
- handler: ([command, ...options]) => {
30
- !!command
31
- ? { start, status, stop }[command](options)
32
- : logError({ message: 'No command provided' })
33
- }
34
- }
@@ -1,42 +0,0 @@
1
- const { CaddyService } = require('../caddy')
2
- const { DockerService } = require('../docker')
3
- const { PlatformTemplateService } = require('../template')
4
- const { PlatformConfigService } = require('../config')
5
- const { DeploymentQueueService } = require('../deployment-queue')
6
- const { logError } = require('../log')
7
-
8
- /**
9
- * @class
10
- */
11
- class PlatformServerService {
12
-
13
- static start(platformTemplatesFilePath) {
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
- )
33
-
34
- })
35
- .catch(error => logError({ message: '[PlatformServerService] Could not start the platform server', error }))
36
- }
37
-
38
- }
39
-
40
- module.exports = {
41
- PlatformServerService
42
- }