@ossy/deployment-tools 0.0.44 → 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.
Files changed (40) hide show
  1. package/README.md +30 -4
  2. package/cdk.context.json +37 -0
  3. package/cdk.json +40 -0
  4. package/package.json +18 -8
  5. package/src/aws-credentials/aws-credentials.js +74 -0
  6. package/src/aws-credentials/cli.js +28 -0
  7. package/src/aws-credentials/index.js +1 -0
  8. package/src/config/index.js +1 -0
  9. package/src/{platform-config.js → config/platform-config.js} +24 -5
  10. package/src/{cli-commands/deploy-handler.js → deploy/cli.js} +12 -6
  11. package/src/deploy/platform-deployment.js +74 -0
  12. package/src/{deployment-queue-client.js → deployment-queue/deployment-queue.js} +20 -16
  13. package/src/deployment-queue/index.js +1 -0
  14. package/src/index.js +5 -3
  15. package/src/infrastructure/cli.js +30 -0
  16. package/src/infrastructure/container-server/aws-profile.js +22 -0
  17. package/src/infrastructure/container-server/caddy.service.js +69 -0
  18. package/src/infrastructure/container-server/container-server.js +175 -0
  19. package/src/infrastructure/container-server/deployment-tools.service.js +37 -0
  20. package/src/infrastructure/container-server/index.js +3 -0
  21. package/src/infrastructure/container-server/user-data-commands.js +32 -0
  22. package/src/infrastructure/establish-trust-stack.js +65 -0
  23. package/src/infrastructure/platform-stack.js +53 -0
  24. package/src/log.js +9 -3
  25. package/src/{caddy-client.js → server/caddy.js} +14 -10
  26. package/src/server/cli.js +34 -0
  27. package/src/{docker-client.js → server/docker.js} +16 -16
  28. package/src/server/platform-server.js +37 -0
  29. package/src/{ci-rest-api.js → server/rest-api.js} +8 -4
  30. package/src/template/cli.js +22 -0
  31. package/src/template/index.js +1 -0
  32. package/src/{platform-template.js → template/platform-template.js} +9 -5
  33. package/src/types.js +0 -33
  34. package/src/aws-credentials-client.js +0 -43
  35. package/src/cli-commands/index.js +0 -23
  36. package/src/cli-commands/start-handler.js +0 -24
  37. package/src/cli-commands/status-handler.js +0 -7
  38. package/src/cli-commands/stop-handler.js +0 -7
  39. package/src/platform-cli.js +0 -7
  40. package/src/platform-client.js +0 -95
package/src/types.js CHANGED
@@ -1,42 +1,9 @@
1
- // export interface PlatformTemplate {
2
- // platformName: string;
3
- // domain: string;
4
- // supportedDeploymentTypes: SupportedDeploymentTypes[];
5
- // supportedEnvironments: SupportedEnvironments[];
6
- // awsRegion?: string;
7
- // awsAccountId: string;
8
- // awsKeyPairName?: string;
9
- // awsRoleToAssume?: string;
10
- // awsDeploymentSqsArn?: string;
11
- // ciSubDomain?: string;
12
- // ciInternalServerPort?: string | number;
13
- // ciServerName?: string;
14
- // ciDockerNetworkName?: string;
15
- // }
16
- //
17
1
  // export interface PlatformConfig extends Required<Omit<PlatformTemplate, 'awsRoleToAssume' | 'awsKeyPairName'>> {
18
2
  // activeEnvironment: SupportedEnvironments;
19
3
  // awsRoleToAssume?: string;
20
4
  // awsKeyPairName?: string;
21
5
  // }
22
6
 
23
- export const SupportedRegions = {
24
- North: 'eu-north-1'
25
- }
26
-
27
- export const SupportedEnvironments = {
28
- LOCAL: 'local',
29
- QA: 'qa',
30
- TEST: 'test',
31
- DEMO: 'demo',
32
- PROD: 'prod'
33
- }
34
-
35
- export const SupportedDeploymentTypes = {
36
- Container: 'CONTAINER'
37
- // Static = 'STATIC'
38
- }
39
-
40
7
  // export interface DeploymentTemplate {
41
8
  // type: SupportedDeploymentTypes;
42
9
  // targetDeploymentPlatform: string;
@@ -1,43 +0,0 @@
1
- import * as core from '@actions/core'
2
- import { STSClient, AssumeRoleWithWebIdentityCommand } from '@aws-sdk/client-sts'
3
- import { logInfo, logError } from './log.js'
4
-
5
- export 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
- }
@@ -1,23 +0,0 @@
1
- import { logError } from '../log.js'
2
- import { startHandler } from './start-handler.js'
3
- import { stopHandler } from './stop-handler.js'
4
- import { statusHandler } from './status-handler.js'
5
- import { deployHandler } from './deploy-handler.js'
6
-
7
- export 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
- }
@@ -1,24 +0,0 @@
1
- import arg from 'arg'
2
- import { platform } from 'os'
3
- import { logInfo, logError } from '../log.js'
4
- import { PlatformClient } from '../platform-client.js'
5
-
6
- export 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
- }
@@ -1,7 +0,0 @@
1
- import { exec } from 'child_process'
2
- import { logInfo } from '../log.js'
3
-
4
- export const statusHandler = () => {
5
- logInfo({ message: 'Running status command' })
6
- exec('systemctl status deployment-tools.service')
7
- }
@@ -1,7 +0,0 @@
1
- import { exec } from 'child_process'
2
- import { logInfo } from '../log.js'
3
-
4
- export const stopHandler = () => {
5
- logInfo({ message: 'Running stop command' })
6
- exec('systemctl stop deployment-tools.service')
7
- }
@@ -1,7 +0,0 @@
1
- #!/usr/bin/env node
2
- import { runCliCommand } from './cli-commands/index.js'
3
-
4
- //eslint-disable-next-line no-unused-vars
5
- const [_, __, command, ...restArgs] = process.argv
6
-
7
- runCliCommand({ name: command, args: restArgs })
@@ -1,95 +0,0 @@
1
- import { resolve } from 'path'
2
- import { readFileSync } from 'fs'
3
- import { SupportedDeploymentTypes } from './types.js'
4
- import { PlatformTemplateService } from './platform-template.js'
5
- import { PlatformConfigService } from './platform-config.js'
6
- import { CaddyClient } from './caddy-client.js'
7
- import { DockerClient } from './docker-client.js'
8
- import { DeploymentQueueClient } from './deployment-queue-client.js'
9
- import { CiRestApi } from './ci-rest-api.js'
10
- import { logError } from './log.js'
11
-
12
- // journalctl -u service-name.service
13
- export 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
- }