@ossy/deployment-tools 0.0.41 → 0.0.43
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 +7 -11
- package/src/{aws-credentials-client.ts → aws-credentials-client.js} +8 -9
- package/src/{caddy-client.ts → caddy-client.js} +6 -7
- package/src/{ci-rest-api.ts → ci-rest-api.js} +2 -3
- package/src/cli-commands/{deploy-handler.ts → deploy-handler.js} +2 -2
- package/src/cli-commands/{index.ts → index.js} +5 -5
- package/src/cli-commands/{start-handler.ts → start-handler.js} +2 -2
- package/src/cli-commands/{status-handler.ts → status-handler.js} +1 -1
- package/src/cli-commands/{stop-handler.ts → stop-handler.js} +1 -1
- package/src/{deployment-queue-client.ts → deployment-queue-client.js} +6 -7
- package/src/{docker-client.ts → docker-client.js} +15 -16
- package/src/index.js +3 -0
- package/src/{log/index.ts → log.js} +11 -11
- package/src/{platform-cli.ts → platform-cli.js} +1 -1
- package/src/{platform-client.ts → platform-client.js} +16 -23
- package/src/{platform-config.ts → platform-config.js} +2 -4
- package/src/platform-template.js +63 -0
- package/src/types.js +65 -0
- package/bin/619.index.js +0 -452
- package/bin/619.index.js.map +0 -1
- package/bin/aws-credentials-client.d.ts +0 -4
- package/bin/caddy-client.d.ts +0 -13
- package/bin/ci-rest-api.d.ts +0 -4
- package/bin/cli-commands/deploy-handler.d.ts +0 -1
- package/bin/cli-commands/index.d.ts +0 -4
- package/bin/cli-commands/start-handler.d.ts +0 -1
- package/bin/cli-commands/status-handler.d.ts +0 -1
- package/bin/cli-commands/stop-handler.d.ts +0 -1
- package/bin/deployment-queue-client.d.ts +0 -7
- package/bin/docker-client.d.ts +0 -8
- package/bin/index.d.ts +0 -4
- package/bin/index.js +0 -362
- package/bin/index.js.map +0 -1
- package/bin/licenses.txt +0 -23
- package/bin/log/index.d.ts +0 -3
- package/bin/package.json +0 -3
- package/bin/platform-cli.d.ts +0 -1
- package/bin/platform-client.d.ts +0 -13
- package/bin/platform-config.d.ts +0 -4
- package/bin/platform-template.d.ts +0 -5
- package/bin/sourcemap-register.cjs +0 -1
- package/bin/types/index.d.ts +0 -65
- package/bin/types.d.ts +0 -65
- package/dist/619.index.js +0 -452
- package/dist/619.index.js.map +0 -1
- package/dist/aws-credentials-client.d.ts +0 -4
- package/dist/caddy-client.d.ts +0 -13
- package/dist/ci-rest-api.d.ts +0 -4
- package/dist/cli-commands/deploy-handler.d.ts +0 -1
- package/dist/cli-commands/index.d.ts +0 -4
- package/dist/cli-commands/start-handler.d.ts +0 -1
- package/dist/cli-commands/status-handler.d.ts +0 -1
- package/dist/cli-commands/stop-handler.d.ts +0 -1
- package/dist/deployment-queue-client.d.ts +0 -7
- package/dist/docker-client.d.ts +0 -8
- package/dist/index.d.ts +0 -4
- package/dist/index.js +0 -361
- package/dist/index.js.map +0 -1
- package/dist/licenses.txt +0 -23
- package/dist/log/index.d.ts +0 -3
- package/dist/package.json +0 -3
- package/dist/platform-cli.d.ts +0 -2
- package/dist/platform-client.d.ts +0 -13
- package/dist/platform-config.d.ts +0 -4
- package/dist/platform-template.d.ts +0 -5
- package/dist/sourcemap-register.cjs +0 -1
- package/dist/types/index.d.ts +0 -65
- package/dist/types.d.ts +0 -65
- package/src/index.d.ts +0 -2
- package/src/index.ts +0 -4
- package/src/platform-template.ts +0 -31
- package/src/types.ts +0 -65
- package/tsconfig.json +0 -10
package/package.json
CHANGED
|
@@ -1,31 +1,27 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ossy/deployment-tools",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.43",
|
|
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
|
"type": "module",
|
|
6
|
-
"
|
|
7
|
-
"main": "dist/index.js",
|
|
6
|
+
"main": "src/index.js",
|
|
8
7
|
"scripts": {
|
|
9
8
|
"test": "echo \"Error: no test specified\" && exit 1",
|
|
10
|
-
"build": "
|
|
11
|
-
"build:
|
|
12
|
-
"build:cli": "npx --yes @vercel/ncc build src/platform-cli.ts --source-map --out bin --license licenses.txt --minify"
|
|
9
|
+
"build": "",
|
|
10
|
+
"build:docs": "jsdoc src/index.js"
|
|
13
11
|
},
|
|
14
12
|
"author": "Ossy",
|
|
15
13
|
"license": "ISC",
|
|
16
|
-
"bin": "
|
|
14
|
+
"bin": "src/platform-cli.js",
|
|
17
15
|
"dependencies": {
|
|
18
16
|
"@actions/core": "^1.10.0",
|
|
19
17
|
"@aws-sdk/client-sqs": "^3.186.0",
|
|
20
18
|
"@aws-sdk/client-sts": "^3.188.0",
|
|
21
|
-
"@aws-sdk/types": "^3.193.0",
|
|
22
19
|
"arg": "^5.0.2",
|
|
23
20
|
"express": "^4.18.1",
|
|
24
21
|
"nanoid": "^4.0.0",
|
|
25
|
-
"node-fetch": "^3.2.6"
|
|
26
|
-
"typescript": "^4.8.4"
|
|
22
|
+
"node-fetch": "^3.2.6"
|
|
27
23
|
},
|
|
28
24
|
"devDependencies": {
|
|
29
|
-
"
|
|
25
|
+
"jsdoc": "^3.6.11"
|
|
30
26
|
}
|
|
31
27
|
}
|
|
@@ -1,26 +1,25 @@
|
|
|
1
1
|
import * as core from '@actions/core'
|
|
2
2
|
import { STSClient, AssumeRoleWithWebIdentityCommand } from '@aws-sdk/client-sts'
|
|
3
|
-
import {
|
|
4
|
-
import { logInfo, logError } from 'log'
|
|
3
|
+
import { logInfo, logError } from './log.js'
|
|
5
4
|
|
|
6
5
|
export class AwsCredentialsClient {
|
|
7
6
|
|
|
8
|
-
static resolveAwsCredentials(
|
|
7
|
+
static resolveAwsCredentials(platformConfig) {
|
|
9
8
|
// If awsRoleToAssume is present, then we assume we run in a github workflow
|
|
10
9
|
// If awsRoleToAssume is not present, then we assume they are resolved localy by aws-sdk
|
|
11
|
-
if (!awsRoleToAssume) {
|
|
12
|
-
logInfo({ message:
|
|
10
|
+
if (!platformConfig.awsRoleToAssume) {
|
|
11
|
+
logInfo({ message: '[AwsCredentialsClient] No aws role to assume was found, leaving auth logic to @aws-sdk package' })
|
|
13
12
|
return Promise.resolve(undefined)
|
|
14
13
|
}
|
|
15
14
|
|
|
16
|
-
const stsClient = new STSClient({ region: awsRegion })
|
|
15
|
+
const stsClient = new STSClient({ region: platformConfig.awsRegion })
|
|
17
16
|
|
|
18
17
|
logInfo({ message: '[AwsCredentialsClient] Fetching GitHub ID token' })
|
|
19
18
|
return core.getIDToken('sts.amazonaws.com')
|
|
20
19
|
.then(webIdentityToken => {
|
|
21
|
-
logInfo({ message: `[AwsCredentialsClient] Attempting to resolve aws credentials by assuming the role: ${awsRoleToAssume}` })
|
|
20
|
+
logInfo({ message: `[AwsCredentialsClient] Attempting to resolve aws credentials by assuming the role: ${platformConfig.awsRoleToAssume}` })
|
|
22
21
|
return stsClient.send(new AssumeRoleWithWebIdentityCommand({
|
|
23
|
-
RoleArn: `arn:aws:iam::${awsAccountId}:role/${awsRoleToAssume}`,
|
|
22
|
+
RoleArn: `arn:aws:iam::${platformConfig.awsAccountId}:role/${platformConfig.awsRoleToAssume}`,
|
|
24
23
|
RoleSessionName: 'GitHubActions',
|
|
25
24
|
DurationSeconds: 15 * 60,
|
|
26
25
|
WebIdentityToken: webIdentityToken
|
|
@@ -33,7 +32,7 @@ export class AwsCredentialsClient {
|
|
|
33
32
|
SecretAccessKey: responseData.Credentials.SecretAccessKey,
|
|
34
33
|
accessKeyId: responseData.Credentials.AccessKeyId,
|
|
35
34
|
sessionToken: responseData.Credentials.SessionToken,
|
|
36
|
-
secretAccessKey: responseData.Credentials.SecretAccessKey
|
|
35
|
+
secretAccessKey: responseData.Credentials.SecretAccessKey
|
|
37
36
|
}))
|
|
38
37
|
.catch(error => {
|
|
39
38
|
logError({ message: '[AwsCredentialsClient] Could not resolve temporary credentials', error })
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import fetch from 'node-fetch'
|
|
2
|
-
import { logInfo, logError } from './log'
|
|
3
|
-
import { PlatformConfig, ContainerDeploymentRequest } from 'types'
|
|
2
|
+
import { logInfo, logError } from './log.js'
|
|
4
3
|
|
|
5
4
|
export const Matchers = {
|
|
6
5
|
host: host => ({ host: [host] }),
|
|
@@ -20,7 +19,7 @@ const Handlers = {
|
|
|
20
19
|
|
|
21
20
|
export class CaddyClient {
|
|
22
21
|
|
|
23
|
-
static deploy(platformConfig
|
|
22
|
+
static deploy(platformConfig, deploymentRequest) {
|
|
24
23
|
|
|
25
24
|
const url = `${deploymentRequest.subdomain}.${platformConfig.activeEnvironment}.${platformConfig.domain}`
|
|
26
25
|
|
|
@@ -36,11 +35,11 @@ export class CaddyClient {
|
|
|
36
35
|
}
|
|
37
36
|
]))
|
|
38
37
|
})
|
|
39
|
-
|
|
38
|
+
.catch(error => logError({ message: `[CaddyClient] Could not update caddy config to include ${url}`, error }))
|
|
40
39
|
}
|
|
41
40
|
|
|
42
|
-
static applyDefaultServerConfig(platformConfig
|
|
43
|
-
logInfo({
|
|
41
|
+
static applyDefaultServerConfig(platformConfig) {
|
|
42
|
+
logInfo({ message: '[CaddyClient] Applying default caddy config' })
|
|
44
43
|
return fetch('http://localhost:2019/load', {
|
|
45
44
|
method: 'POST',
|
|
46
45
|
headers: { 'Content-Type': 'application/json' },
|
|
@@ -102,7 +101,7 @@ export class CaddyClient {
|
|
|
102
101
|
}
|
|
103
102
|
})
|
|
104
103
|
})
|
|
105
|
-
.catch(error => logError({
|
|
104
|
+
.catch(error => logError({ message: '[CaddyClient] Could not apply default caddy config', error }))
|
|
106
105
|
}
|
|
107
106
|
|
|
108
107
|
}
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import express from 'express'
|
|
2
|
-
import {
|
|
3
|
-
import { logInfo } from './log'
|
|
2
|
+
import { logInfo } from './log.js'
|
|
4
3
|
|
|
5
4
|
export class CiRestApi {
|
|
6
5
|
|
|
7
|
-
static start(platformConfig
|
|
6
|
+
static start(platformConfig) {
|
|
8
7
|
const server = express()
|
|
9
8
|
|
|
10
9
|
server.use(express.json())
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import arg from 'arg'
|
|
2
|
-
import { logInfo } from 'log'
|
|
3
|
-
import { PlatformClient } from 'platform-client'
|
|
2
|
+
import { logInfo } from '../log.js'
|
|
3
|
+
import { PlatformClient } from '../platform-client.js'
|
|
4
4
|
|
|
5
5
|
export const deployHandler = cliArgs => {
|
|
6
6
|
logInfo({ message: 'Running deploy command' })
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { logError } from 'log'
|
|
2
|
-
import { startHandler } from './start-handler'
|
|
3
|
-
import { stopHandler } from './stop-handler'
|
|
4
|
-
import { statusHandler } from './status-handler'
|
|
5
|
-
import { deployHandler } from './deploy-handler'
|
|
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
6
|
|
|
7
7
|
export const runCliCommand = ({ name, args }) => {
|
|
8
8
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import arg from 'arg'
|
|
2
2
|
import { platform } from 'os'
|
|
3
|
-
import { logInfo, logError } from '../log'
|
|
4
|
-
import { PlatformClient } from 'platform-client'
|
|
3
|
+
import { logInfo, logError } from '../log.js'
|
|
4
|
+
import { PlatformClient } from '../platform-client.js'
|
|
5
5
|
|
|
6
6
|
export const startHandler = cliArgs => {
|
|
7
7
|
logInfo({ message: 'Running start command' })
|
|
@@ -4,13 +4,12 @@ import {
|
|
|
4
4
|
DeleteMessageCommand,
|
|
5
5
|
ReceiveMessageCommand
|
|
6
6
|
} from '@aws-sdk/client-sqs'
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import { logInfo, logError, logDebug } from 'log'
|
|
7
|
+
import { AwsCredentialsClient } from './aws-credentials-client.js'
|
|
8
|
+
import { logInfo, logError, logDebug } from './log.js'
|
|
10
9
|
|
|
11
10
|
export class DeploymentQueueClient {
|
|
12
11
|
|
|
13
|
-
static sendDeploymentRequest(platformConfig
|
|
12
|
+
static sendDeploymentRequest(platformConfig, deploymentRequest) {
|
|
14
13
|
logInfo({ message: '[DeploymentQueueClient] Starting deployment sequence' })
|
|
15
14
|
return DeploymentQueueClient.createAwsSqsClient(platformConfig)
|
|
16
15
|
.then(sqsClient => {
|
|
@@ -30,7 +29,7 @@ export class DeploymentQueueClient {
|
|
|
30
29
|
|
|
31
30
|
}
|
|
32
31
|
|
|
33
|
-
static pollForDeploymentRequests(platformConfig
|
|
32
|
+
static pollForDeploymentRequests(platformConfig, handleDeploymentRequest) {
|
|
34
33
|
logInfo({ message: '[DeploymentQueueClient] Starting polling for deployment requests' })
|
|
35
34
|
DeploymentQueueClient.createAwsSqsClient(platformConfig).then(sqsClient => {
|
|
36
35
|
const FIVE_MINUTES = 3000
|
|
@@ -61,10 +60,10 @@ export class DeploymentQueueClient {
|
|
|
61
60
|
.catch(error => logError({ message: '[ContainerManagerServer] Could not handle incoming deployment request', error }))
|
|
62
61
|
}, FIVE_MINUTES)
|
|
63
62
|
|
|
64
|
-
|
|
63
|
+
})
|
|
65
64
|
}
|
|
66
65
|
|
|
67
|
-
static createAwsSqsClient(platformConfig
|
|
66
|
+
static createAwsSqsClient(platformConfig) {
|
|
68
67
|
return AwsCredentialsClient.resolveAwsCredentials(platformConfig)
|
|
69
68
|
.then(awsCredentials => new SQSClient({
|
|
70
69
|
region: platformConfig.awsRegion,
|
|
@@ -3,48 +3,47 @@ import fs from 'fs'
|
|
|
3
3
|
import { nanoid } from 'nanoid'
|
|
4
4
|
import path from 'path'
|
|
5
5
|
import { fileURLToPath } from 'url'
|
|
6
|
-
import { logInfo, logError } from './log'
|
|
7
|
-
import { PlatformConfig, ContainerDeploymentRequest } from 'types'
|
|
6
|
+
import { logInfo, logError } from './log.js'
|
|
8
7
|
|
|
9
8
|
const __filename = fileURLToPath(import.meta.url)
|
|
10
9
|
const __dirname = path.dirname(__filename)
|
|
11
10
|
|
|
12
11
|
export class DockerClient {
|
|
13
12
|
|
|
14
|
-
static createDockerNetworkForContainerManagerServer(platformConfig
|
|
15
|
-
logInfo({
|
|
13
|
+
static createDockerNetworkForContainerManagerServer(platformConfig) {
|
|
14
|
+
logInfo({ message: '[DockerClient] Creating docker network for comunication between containers' })
|
|
16
15
|
exec(`sudo docker network create ${platformConfig.ciDockerNetworkName}`)
|
|
17
16
|
}
|
|
18
17
|
|
|
19
|
-
static stopContainer(deploymentRequest
|
|
18
|
+
static stopContainer(deploymentRequest) {
|
|
20
19
|
const name = deploymentRequest.image.replaceAll('/', '_')
|
|
21
|
-
logInfo({
|
|
20
|
+
logInfo({ message: `Running docker stop for image with the name of ${name}` })
|
|
22
21
|
return `sudo docker stop ${name} ||`
|
|
23
22
|
}
|
|
24
23
|
|
|
25
|
-
static startContainer(platformConfig
|
|
24
|
+
static startContainer(platformConfig, { image, containerPort, hostPort, registry, env }) {
|
|
26
25
|
const name = image.replaceAll('/', '_')
|
|
27
26
|
const imageUrl = !!registry ? `${registry}/${image}` : image
|
|
28
27
|
const envsAsString = Object.entries(env || {}).reduce((envs, [name, value]) => `${envs} --env ${name}=${value}`, '')
|
|
29
|
-
logInfo({
|
|
28
|
+
logInfo({ message: `Running docker start for image with the name of ${name} with port mapping ${hostPort}:${containerPort} and source ${imageUrl}` })
|
|
30
29
|
return `sudo docker run -d -p ${hostPort}:${containerPort} --name=${name} --network=${platformConfig.ciDockerNetworkName} --network-alias=${name} --rm ${envsAsString} ${imageUrl}`
|
|
31
30
|
}
|
|
32
31
|
|
|
33
|
-
static resolveCredentials({ registry, username, authentication }
|
|
32
|
+
static resolveCredentials({ registry, username, authentication }) {
|
|
34
33
|
const shouldAuthenticate = username || authentication
|
|
35
34
|
|
|
36
35
|
if (!shouldAuthenticate) {
|
|
37
|
-
logInfo({
|
|
36
|
+
logInfo({ message: 'No docker credentials provided, assuming image is publicly hosted' })
|
|
38
37
|
return ''
|
|
39
38
|
}
|
|
40
39
|
|
|
41
|
-
logInfo({
|
|
40
|
+
logInfo({ message: `Resolving docker credentials for ${registry}` })
|
|
42
41
|
return `sudo docker login ${registry} -u ${username} -p ${authentication}`
|
|
43
42
|
}
|
|
44
43
|
|
|
45
|
-
static deploy(platformConfig
|
|
44
|
+
static deploy(platformConfig, deploymentRequest) {
|
|
46
45
|
return new Promise(resolve => {
|
|
47
|
-
logInfo({
|
|
46
|
+
logInfo({ message: 'Starting docker deployment sequence' })
|
|
48
47
|
|
|
49
48
|
const dockerCommandScript = `'#!/bin/bash'
|
|
50
49
|
${DockerClient.stopContainer(deploymentRequest)}
|
|
@@ -61,15 +60,15 @@ ${DockerClient.startContainer(platformConfig, deploymentRequest)}`
|
|
|
61
60
|
const command = exec(`bash ${FilePaths.DeploymentScript}`)
|
|
62
61
|
|
|
63
62
|
command.stdout.on('data', data => {
|
|
64
|
-
logInfo({
|
|
63
|
+
logInfo({ message: `[DockerClient]: ${data}` })
|
|
65
64
|
})
|
|
66
65
|
|
|
67
66
|
command.stderr.on('data', (data) => {
|
|
68
|
-
logError({
|
|
67
|
+
logError({ message: `[DockerClient]: ${data}` })
|
|
69
68
|
})
|
|
70
69
|
|
|
71
70
|
command.on('close', code => {
|
|
72
|
-
logInfo({
|
|
71
|
+
logInfo({ message: `[DockerClient] command exited with code ${code}` })
|
|
73
72
|
fs.unlinkSync(FilePaths.DeploymentScript)
|
|
74
73
|
resolve()
|
|
75
74
|
})
|
package/src/index.js
ADDED
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
interface LogInput {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
}
|
|
1
|
+
// interface LogInput {
|
|
2
|
+
// type: TypeOfMessage;
|
|
3
|
+
// message: string;
|
|
4
|
+
// data?: any;
|
|
5
|
+
// dataPrefix: string;
|
|
6
|
+
// }
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
Info
|
|
10
|
-
Error
|
|
11
|
-
Debug
|
|
8
|
+
const TypeOfMessage = {
|
|
9
|
+
Info: 'INFO',
|
|
10
|
+
Error: 'ERROR',
|
|
11
|
+
Debug: 'DEBUG'
|
|
12
12
|
}
|
|
13
13
|
|
|
14
14
|
const log = (...params) => { console.log(...params) }
|
|
15
|
-
const prefixTo = (prefix
|
|
15
|
+
const prefixTo = (prefix, message) => `[${prefix}]${message.startsWith('[') ? '' : ': '}`
|
|
16
16
|
|
|
17
17
|
export const logInfo = logInput => {
|
|
18
18
|
const messagePrefix = prefixTo(TypeOfMessage.Info, logInput.message)
|
|
@@ -1,25 +1,18 @@
|
|
|
1
1
|
import { resolve } from 'path'
|
|
2
2
|
import { readFileSync } from 'fs'
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
} from '
|
|
10
|
-
import {
|
|
11
|
-
import { PlatformConfigService } from 'platform-config'
|
|
12
|
-
import { CaddyClient } from './caddy-client'
|
|
13
|
-
import { DockerClient } from './docker-client'
|
|
14
|
-
import { DeploymentQueueClient } from './deployment-queue-client'
|
|
15
|
-
import { CiRestApi } from './ci-rest-api'
|
|
16
|
-
import { logInfo, logError } from 'log'
|
|
17
|
-
|
|
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'
|
|
18
11
|
|
|
19
12
|
// journalctl -u service-name.service
|
|
20
13
|
export class PlatformClient {
|
|
21
14
|
|
|
22
|
-
static start(platformTemplatesFilePath
|
|
15
|
+
static start(platformTemplatesFilePath) {
|
|
23
16
|
PlatformTemplateService.readFromFile(platformTemplatesFilePath).then(([firstPlatformTemplateFound]) => {
|
|
24
17
|
const platformConfig = PlatformConfigService.from(firstPlatformTemplateFound)
|
|
25
18
|
|
|
@@ -28,7 +21,7 @@ export class PlatformClient {
|
|
|
28
21
|
|
|
29
22
|
DeploymentQueueClient.pollForDeploymentRequests(
|
|
30
23
|
platformConfig,
|
|
31
|
-
|
|
24
|
+
deploymentRequest => {
|
|
32
25
|
DockerClient.deploy(platformConfig, deploymentRequest)
|
|
33
26
|
CaddyClient.deploy(platformConfig, deploymentRequest)
|
|
34
27
|
return Promise.resolve()
|
|
@@ -36,7 +29,7 @@ export class PlatformClient {
|
|
|
36
29
|
)
|
|
37
30
|
|
|
38
31
|
})
|
|
39
|
-
|
|
32
|
+
.catch(error => logError({ message: '[PlatformClient] Could not start the deployment platform', error }))
|
|
40
33
|
}
|
|
41
34
|
|
|
42
35
|
//eslint-disable-next-line max-params
|
|
@@ -54,7 +47,7 @@ export class PlatformClient {
|
|
|
54
47
|
|
|
55
48
|
const deploymentTemplatesRequest = PlatformClient.getDeploymentTemplates(pathToOssyFile)
|
|
56
49
|
|
|
57
|
-
return Promise.all([
|
|
50
|
+
return Promise.all([platformConfigRequest, deploymentTemplatesRequest])
|
|
58
51
|
.then(([platformConfigs, deploymentTemplates]) => {
|
|
59
52
|
deploymentTemplates.map(deploymentTemplate => {
|
|
60
53
|
|
|
@@ -72,8 +65,8 @@ export class PlatformClient {
|
|
|
72
65
|
return Promise.reject()
|
|
73
66
|
}
|
|
74
67
|
|
|
75
|
-
const deploymentRequest
|
|
76
|
-
...deploymentTemplate
|
|
68
|
+
const deploymentRequest = {
|
|
69
|
+
...deploymentTemplate,
|
|
77
70
|
env: PlatformClient.getEnvironmentVariables(targetEnvironment, deploymentTemplate),
|
|
78
71
|
username: username,
|
|
79
72
|
authentication: authentication
|
|
@@ -86,12 +79,12 @@ export class PlatformClient {
|
|
|
86
79
|
.catch(error => logError({ message: '[PlatformClient] Could not send deployment request', error }))
|
|
87
80
|
}
|
|
88
81
|
|
|
89
|
-
static getDeploymentTemplates(pathToOssyFile
|
|
82
|
+
static getDeploymentTemplates(pathToOssyFile) {
|
|
90
83
|
const ossyfile = JSON.parse(readFileSync(resolve(pathToOssyFile), 'utf8'))
|
|
91
84
|
return Promise.resolve(ossyfile.deployments || [])
|
|
92
85
|
}
|
|
93
86
|
|
|
94
|
-
static getEnvironmentVariables(targetEnvironment
|
|
87
|
+
static getEnvironmentVariables(targetEnvironment, deploymentRequest) {
|
|
95
88
|
const envs = deploymentRequest.env || {}
|
|
96
89
|
return {
|
|
97
90
|
...(envs.shared || {}),
|
|
@@ -1,13 +1,11 @@
|
|
|
1
1
|
import {
|
|
2
|
-
PlatformConfig,
|
|
3
|
-
PlatformTemplate,
|
|
4
2
|
SupportedEnvironments,
|
|
5
3
|
SupportedRegions
|
|
6
|
-
} from 'types'
|
|
4
|
+
} from './types.js'
|
|
7
5
|
|
|
8
6
|
export class PlatformConfigService {
|
|
9
7
|
|
|
10
|
-
static from(template
|
|
8
|
+
static from(template) {
|
|
11
9
|
|
|
12
10
|
const withDefaults = {
|
|
13
11
|
platformName: SupportedEnvironments.LOCAL,
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { resolve } from 'path'
|
|
2
|
+
import { readFileSync } from 'fs'
|
|
3
|
+
import { logError, logInfo } from './log.js'
|
|
4
|
+
// @param {number} [foo=1]
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Platform template definition
|
|
8
|
+
* @typedef {Object} PlatformTemplate
|
|
9
|
+
* @property {string} platformName - Name of platform
|
|
10
|
+
* @property {string} domain - example.com
|
|
11
|
+
* @property {string[]} supportedDeploymentTypes - container
|
|
12
|
+
* @property {string[]} supportedEnvironments - qa
|
|
13
|
+
* @property {string} awsAccountId - Aws account id
|
|
14
|
+
* @property {string} awsRegion - ?
|
|
15
|
+
* @property {string} awsKeyPairName - ?
|
|
16
|
+
* @property {string} awsRoleToAssume - ?
|
|
17
|
+
* @property {string} awsDeploymentSqsArn - ?
|
|
18
|
+
* @property {string} ciSubDomain - ?
|
|
19
|
+
* @property {string} ciInternalServerPort- ? | number;
|
|
20
|
+
* @property {string} ciServerName - ?
|
|
21
|
+
* @property {string} ciDockerNetworkName - ?
|
|
22
|
+
*/
|
|
23
|
+
export class PlatformTemplateService {
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Reads the json file that holds the platform templates
|
|
27
|
+
*
|
|
28
|
+
* @param {string} path - File path to platform templates json
|
|
29
|
+
* @return @Async {PlatformTemplate[]} - List of platform templates
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* const platformTemplate = PlatformTemplateService.readFromFile('./platforms.json')
|
|
33
|
+
*/
|
|
34
|
+
static readFromFile(path) {
|
|
35
|
+
|
|
36
|
+
if (!path) {
|
|
37
|
+
logError({ message: '[PlatformTemplateService] No path provided' })
|
|
38
|
+
return Promise.reject()
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const fileData = readFileSync(resolve(path), 'utf8')
|
|
42
|
+
|
|
43
|
+
if (!fileData && typeof fileData !== 'string') {
|
|
44
|
+
logError({ message: `[PlatformTemplateService] Could not find a deployment platform at ${path}` })
|
|
45
|
+
return Promise.reject()
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
let potentialTemplates = JSON.parse(fileData)
|
|
49
|
+
|
|
50
|
+
if (!Array.isArray(potentialTemplates)) {
|
|
51
|
+
potentialTemplates = [potentialTemplates]
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const templates = potentialTemplates.map(PlatformTemplateService.fakeValidateTemplate)
|
|
55
|
+
logInfo({ message: `[PlatformTemplateService]: Found platforms [${templates.map(x => x.platformName).join(', ')}]` })
|
|
56
|
+
return Promise.resolve(templates)
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
static fakeValidateTemplate(obj) {
|
|
60
|
+
// todo: implement real one
|
|
61
|
+
return obj
|
|
62
|
+
}
|
|
63
|
+
}
|
package/src/types.js
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
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
|
+
// export interface PlatformConfig extends Required<Omit<PlatformTemplate, 'awsRoleToAssume' | 'awsKeyPairName'>> {
|
|
18
|
+
// activeEnvironment: SupportedEnvironments;
|
|
19
|
+
// awsRoleToAssume?: string;
|
|
20
|
+
// awsKeyPairName?: string;
|
|
21
|
+
// }
|
|
22
|
+
|
|
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
|
+
// export interface DeploymentTemplate {
|
|
41
|
+
// type: SupportedDeploymentTypes;
|
|
42
|
+
// targetDeploymentPlatform: string;
|
|
43
|
+
// subdomain?: string;
|
|
44
|
+
// env?: {
|
|
45
|
+
// shared?: { [name: string]: string | number };
|
|
46
|
+
// prod?: { [name: string]: string | number };
|
|
47
|
+
// test?: { [name: string]: string | number };
|
|
48
|
+
// qa?: { [name: string]: string | number };
|
|
49
|
+
// }
|
|
50
|
+
// }
|
|
51
|
+
//
|
|
52
|
+
// export interface ContainerDeploymentTemplate extends DeploymentTemplate {
|
|
53
|
+
// type: SupportedDeploymentTypes.Container;
|
|
54
|
+
// dockerFile: string;
|
|
55
|
+
// dockerContext: string;
|
|
56
|
+
// image: string;
|
|
57
|
+
// hostPort: number;
|
|
58
|
+
// containerPort: number;
|
|
59
|
+
// registry: string;
|
|
60
|
+
// }
|
|
61
|
+
|
|
62
|
+
// export interface ContainerDeploymentRequest extends ContainerDeploymentTemplate {
|
|
63
|
+
// authentication?: string;
|
|
64
|
+
// username?: string;
|
|
65
|
+
// }
|