@ossy/deployment-tools 0.0.82 → 0.0.84

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ossy/deployment-tools",
3
- "version": "0.0.82",
3
+ "version": "0.0.84",
4
4
  "description": "Collection of scripts and tools to aid deployment of containers and static files to Amazon Web Services through GitHub Actions",
5
5
  "source": "./src/index.js",
6
6
  "main": "./src/index.js",
package/src/cms/cli.js CHANGED
@@ -1,37 +1,45 @@
1
1
  #!/usr/bin/env node
2
+ const { resolve } = require('path')
2
3
  const { readFileSync } = require('fs')
3
4
  const arg = require('arg')
4
5
  const fetch = require('node-fetch')
5
- const { PlatformDeploymentService } = require('./platform-deployment')
6
6
  const { logInfo, logError } = require('../log')
7
7
 
8
8
  const getTokenPayload = token =>
9
9
  JSON.parse(Buffer.from(token.split('.')[1], 'base64').toString())
10
10
 
11
-
12
- const import = options => {
11
+ const importResourceTemplates = options => {
13
12
 
14
13
  const parsedArgs = arg({
15
14
  '--authentication': String,
16
15
  '--a': '--authentication',
17
16
 
18
- '--resource-templates': String,
19
- '-t': '--resource-templates'
17
+ '--ossy-file': String,
18
+ '-o': '--ossy-file',
20
19
  }, { argv: options })
21
20
 
22
21
  logInfo({ message: '[CMS] reading files' })
23
22
  const token = parsedArgs['--authentication']
24
23
  const tokenPayload = getTokenPayload(token)
25
- const templates = readFileSync(resolve(parsedArgs['--resource-templates']), 'utf8')
24
+ const ossyfile = JSON.parse(readFileSync(resolve(parsedArgs['--ossy-file']), 'utf8'))
25
+
26
+ console.log('ossyfile', ossyfile)
26
27
 
27
28
  if (!token) return logError({ message: '[CMS] No token provided with --authentication'})
28
- if (!templates) return logError({ message: '[CMS] No templates provided with --resource-templates'})
29
+ if (!ossyfile?.workspaceId) return logError({ message: '[CMS] No workspaceId provided in ossy.json'})
30
+ if (!ossyfile?.resourceTemplates) return logError({ message: '[CMS] No resource templates provided in ossy.json'})
29
31
 
30
- logInfo({ message: '[CMS] uploading files' })
32
+ logInfo({ message: '[CMS] uploading resource templates' })
33
+
34
+ const fetchOptions = {
35
+ method: 'POST',
36
+ headers: { 'Authorization': token, 'Content-Type': 'application/json' },
37
+ body: JSON.stringify(ossyfile.resourceTemplates)
38
+ }
31
39
 
32
40
  fetch(
33
- `https://cms.ossy.se/api/v0/workspaces/${tokenPayload?.workspaceId}/resource-templates`,
34
- { method: 'POST', headers: { 'Authorization': token }, body: templates }
41
+ `http://localhost:3001/api/v0/workspaces/${ossyfile.workspaceId}/resource-templates`,
42
+ fetchOptions
35
43
  )
36
44
  .then(() => logInfo({ message: '[CMS] done' }))
37
45
  .catch(error => logError({ message: '[CMS] Error', error }))
@@ -40,7 +48,7 @@ const import = options => {
40
48
  module.exports = {
41
49
  handler: ([command, ...options]) => {
42
50
  !!command
43
- ? { deploy }[command](options)
51
+ ? { 'import-resource-templates': importResourceTemplates }[command](options)
44
52
  : logError({ message: '[CMS] No command provided' })
45
53
  }
46
54
  }
@@ -28,7 +28,7 @@ class PlatformDeploymentService {
28
28
  .then(([deploymentTemplates, platformConfigs]) => {
29
29
 
30
30
  const platformConfig = platformConfigs.find(({ platformName }) => platformName === targetPlatform)
31
- const deploymentTemplatesForTargetPlatform = deploymentTemplates[targetPlatform] || []
31
+ const deploymentTemplatesForTargetPlatform = deploymentTemplates[targetPlatform] || [] //todo remove deploymentTargetPlatform
32
32
  const deploymentTemplate = deploymentTemplatesForTargetPlatform.find(({ domain }) => domain === targetDomain)
33
33
 
34
34
  if (!platformConfig) {
@@ -39,6 +39,13 @@ class DockerService {
39
39
  .catch(() => {}) // no worries if container isn't there
40
40
  }
41
41
 
42
+ static pullImage({ image, registry }) {
43
+ const imageUrl = !!registry ? `${registry}/${image}` : image
44
+ logInfo({ message: `[DockerService] Pulling image for ${image}:latest` })
45
+ return exec(`docker image pull ${imageUrl}:latest`)
46
+ .catch(logErrorAndReject(`[DockerService] Could pull image ${image}:latest`))
47
+ }
48
+
42
49
  static startContainer(platformConfig, { image, containerPort, hostPort, registry, env, domain }) {
43
50
  const imageUrl = !!registry ? `${registry}/${image}` : image
44
51
  const envsAsString = Object.entries(env || {}).reduce((envs, [name, value]) => `${envs} --env ${name}="${value}"`, '')
@@ -67,6 +74,7 @@ class DockerService {
67
74
  return DockerService.resolveCredentials(deploymentRequest)
68
75
  .then(() => DockerService.stopContainer(deploymentRequest))
69
76
  .then(() => DockerService.removeImage(deploymentRequest))
77
+ .then(() => DockerService.pullImage(deploymentRequest))
70
78
  .then(() => DockerService.startContainer(platformConfig, deploymentRequest))
71
79
  }
72
80
 
@@ -13,7 +13,6 @@ const deploymentTemplate = {
13
13
  "containerPort": "3000",
14
14
  }
15
15
 
16
- DockerService.startContainer(
17
- platformConfig,
16
+ DockerService.pullImage(
18
17
  deploymentTemplate
19
18
  )
package/src/ossy.json ADDED
@@ -0,0 +1,14 @@
1
+ {
2
+ "workspaceId": "-LWn40rqowQXuNhm4BTvz",
3
+ "resourceTemplates": [
4
+ {
5
+ "name": "Consulting profile",
6
+ "fields": [
7
+ {
8
+ "name": "Name",
9
+ "type": "string"
10
+ }
11
+ ]
12
+ }
13
+ ]
14
+ }