@ossy/deployment-tools 0.0.46 → 0.0.48

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/cdk.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "app": "node src/infrastructure/cli.js",
2
+ "app": "node ./src/infrastructure/cli.js",
3
3
  "watch": {
4
4
  "include": [
5
5
  "**"
@@ -0,0 +1,19 @@
1
+
2
+ module.exports = {
3
+ plugins: ['plugins/markdown'],
4
+ recurseDepth: 10,
5
+ source: {
6
+ // includePattern: '.+\\.js(doc|x)?$',
7
+ includePattern: '.+\\.js$',
8
+ excludePattern: '(^|\\/|\\\\)_'
9
+ },
10
+ sourceType: 'module',
11
+ tags: {
12
+ allowUnknownTags: true,
13
+ dictionaries: ['jsdoc', 'closure']
14
+ },
15
+ templates: {
16
+ cleverLinks: false,
17
+ monospaceLinks: false
18
+ }
19
+ }
package/package.json CHANGED
@@ -1,23 +1,18 @@
1
1
  {
2
2
  "name": "@ossy/deployment-tools",
3
- "version": "0.0.46",
3
+ "version": "0.0.48",
4
4
  "description": "Collection of scripts and tools to aid deployment of containers and static files to Amazon Web Services through GitHub Actions",
5
+ "source": "./src/index.js",
5
6
  "main": "./src/index.js",
6
7
  "scripts": {
7
8
  "test": "echo \"Error: no test specified\" && exit 1",
8
9
  "build": "echo \"The build step is not required when using JavaScript!\" && exit 0",
9
- "build:docs": "jsdoc ./src/index.js ./package.json",
10
+ "build:docs": "jsdoc -c ./jsdoc.config.js ./src/index.js ./package.json",
10
11
  "cdk": "cdk"
11
12
  },
12
13
  "author": "Ossy",
13
14
  "license": "ISC",
14
- "bin": {
15
- "aws": "./src/aws-credentials/cli.js",
16
- "deploy": "./src/deploy/cli.js",
17
- "template": "./src/template/cli.js",
18
- "server": "./src/server/cli.js",
19
- "infrastructure": "./src/infrastructure/cli.js"
20
- },
15
+ "bin": "./src/index.cli.js",
21
16
  "dependencies": {
22
17
  "@actions/core": "^1.10.0",
23
18
  "@aws-sdk/client-sqs": "^3.186.0",
@@ -35,6 +35,7 @@ class AwsCredentialsService {
35
35
  sessionToken: responseData.Credentials.SessionToken,
36
36
  secretAccessKey: responseData.Credentials.SecretAccessKey
37
37
  }))
38
+ .then(x => AwsCredentialsService.exportCredentialsToGithubWorkflow({ ...x, awsRegion: platformConfig.awsRegion }))
38
39
  .catch(error => {
39
40
  logError({ message: '[AwsCredentialsService] Could not resolve temporary credentials', error })
40
41
  return undefined
@@ -44,7 +45,7 @@ class AwsCredentialsService {
44
45
  static exportCredentialsToGithubWorkflow(params) {
45
46
  // Configure the AWS CLI and AWS SDKs using environment variables and set them as secrets.
46
47
  // Setting the credentials as secrets masks them in Github Actions logs
47
- const { accessKeyId, secretAccessKey, sessionToken } = params
48
+ const { accessKeyId, secretAccessKey, sessionToken, awsRegion } = params
48
49
 
49
50
  // AWS_ACCESS_KEY_ID:
50
51
  // Specifies an AWS access key associated with an IAM user or role
@@ -65,6 +66,15 @@ class AwsCredentialsService {
65
66
  // clear session token from previous credentials action
66
67
  core.exportVariable('AWS_SESSION_TOKEN', '')
67
68
  }
69
+
70
+ if (awsRegion) {
71
+ core.exportVariable('AWS_REGION', awsRegion)
72
+ } else if (process.env.AWS_REGION) {
73
+ // clear AWS_REGION from previous credentials action
74
+ core.exportVariable('AWS_REGION', '')
75
+ }
76
+
77
+ return params
68
78
  }
69
79
 
70
80
  }
@@ -1,13 +1,11 @@
1
- #!/usr/bin/env node
2
1
  const arg = require('arg')
3
2
  const { AwsCredentialsService } = require('./aws-credentials')
4
3
 
4
+ const { PlatformTemplateService } = require('../template')
5
+ const { PlatformConfigService } = require('../config')
5
6
  const { logInfo, logError } = require('../log')
6
7
 
7
- //eslint-disable-next-line no-unused-vars
8
- const [_, __, command, ...options] = process.argv
9
-
10
- const resolveCredentials = () => {
8
+ const resolveCredentials = options => {
11
9
  logInfo({ message: 'resolve-credentials' })
12
10
 
13
11
  const parsedArgs = arg({
@@ -23,6 +21,36 @@ const resolveCredentials = () => {
23
21
  })
24
22
  }
25
23
 
26
- !!command
27
- ? { 'resolve-credentials': resolveCredentials }[command]()
28
- : logError({ message: 'No command provided' })
24
+ const assumeRole = options => {
25
+ logInfo({ message: 'assume-role' })
26
+
27
+ const parsedArgs = arg({
28
+ '--platforms': String,
29
+ '--target-platform': String
30
+ }, { argv: options })
31
+
32
+ const [platformName] = parsedArgs['--target-platform']
33
+
34
+ PlatformTemplateService.readFromFile(parsedArgs['--platforms'] || process.env.PLATFORMS)
35
+ .then(templates => templates.map(PlatformConfigService.from))
36
+ .then(configs => configs.find(x => x.platformName === platformName))
37
+ .then(targetConfig => {
38
+
39
+ if (!targetConfig) {
40
+ return logError({ message: 'No configuration found' })
41
+ }
42
+
43
+ AwsCredentialsService.resolveAwsCredentials(targetConfig)
44
+ .then(() => logInfo({ message: `Assumed role for ${targetConfig.platformName}` }))
45
+
46
+ })
47
+
48
+ }
49
+
50
+ module.exports = {
51
+ handler: ([command, ...options]) => {
52
+ !!command
53
+ ? { 'resolve-credentials': resolveCredentials, 'assume-role': assumeRole }[command](options)
54
+ : logError({ message: 'No command provided' })
55
+ }
56
+ }
@@ -0,0 +1,13 @@
1
+ #!/usr/bin/env node
2
+ /* eslint-disable global-require, no-unused-vars */
3
+
4
+ const [_, __, handlerName, ...restArgs] = process.argv
5
+
6
+ const { handler } = {
7
+ aws: require('./aws-credentials/cli.js'),
8
+ deploy: require('./deploy/cli.js'),
9
+ template: require('./template/cli.js'),
10
+ server: require('./server/cli.js')
11
+ }[handlerName]
12
+
13
+ !!handler && handler(restArgs)
package/src/server/cli.js CHANGED
@@ -1,22 +1,18 @@
1
- #!/usr/bin/env node
2
1
  const arg = require('arg')
3
2
  const { exec } = require('child_process')
4
- const { PlatformClient } = require('./platform-server')
3
+ const { PlatformServerService } = require('./platform-server')
5
4
 
6
5
  const { logInfo, logError } = require('../log')
7
6
 
8
- //eslint-disable-next-line no-unused-vars
9
- const [_, __, command, ...restArgs] = process.argv
10
-
11
- const start = cliArgs => {
7
+ const start = options => {
12
8
  logInfo({ message: 'Running start command' })
13
9
 
14
10
  const parsedArgs = arg({
15
11
  '--platforms': String,
16
12
  '-p': '--platforms'
17
- }, { argv: cliArgs })
13
+ }, { argv: options })
18
14
 
19
- PlatformClient.start(parsedArgs['--platforms'])
15
+ PlatformServerService.start(parsedArgs['--platforms'])
20
16
  }
21
17
 
22
18
  const status = () => {
@@ -29,6 +25,10 @@ const stop = () => {
29
25
  exec('systemctl stop deployment-tools.service')
30
26
  }
31
27
 
32
- !!command
33
- ? { start, status, stop }[command]()
34
- : logError({ message: 'No command provided' })
28
+ module.exports = {
29
+ handler: ([command, ...options]) => {
30
+ !!command
31
+ ? { start, status, stop }[command](options)
32
+ : logError({ message: 'No command provided' })
33
+ }
34
+ }
@@ -1,13 +1,9 @@
1
- #!/usr/bin/env node
2
1
  const arg = require('arg')
3
2
  const { PlatformTemplateService } = require('./platform-template')
4
3
 
5
4
  const { logInfo, logError } = require('../log')
6
5
 
7
- //eslint-disable-next-line no-unused-vars
8
- const [_, __, command, ...options] = process.argv
9
-
10
- const validate = () => {
6
+ const validate = options => {
11
7
  logInfo({ message: 'Running validate command' })
12
8
 
13
9
  const parsedArgs = arg({
@@ -19,4 +15,10 @@ const validate = () => {
19
15
  .then(() => logInfo({ message: 'Template is valid' }))
20
16
  }
21
17
 
22
- command === 'validate' ? validate() : logError({ message: 'No command provided' })
18
+ module.exports = {
19
+ handler: ([command, ...options]) => {
20
+ !!command
21
+ ? { validate }[command](options)
22
+ : logError({ message: 'No command provided' })
23
+ }
24
+ }