@ossy/deployment-tools 0.0.75 → 0.0.77
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.
|
|
3
|
+
"version": "0.0.77",
|
|
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",
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
* @typedef {Object} PlatformConfig
|
|
4
4
|
* @property {string} platformName - Name of platform
|
|
5
5
|
* @property {string} environmentType - local, test, qa, prod
|
|
6
|
+
* @property {object} dnsRecords - map of dns records by root domain, only supports MX records so that we can add dns records for our email service
|
|
6
7
|
*
|
|
7
8
|
* @property {string} awsAccountId - Aws account id
|
|
8
9
|
* @property {string=} awsRegion - ?
|
|
@@ -16,21 +16,29 @@ class DockerService {
|
|
|
16
16
|
|
|
17
17
|
static startDefaultContainers(platformConfig) {
|
|
18
18
|
return exec(`docker run -d --name=mongodb --network=${platformConfig.ciDockerNetworkName} --network-alias=mongodb --rm mongo`)
|
|
19
|
-
.catch(
|
|
19
|
+
.catch(() => {/* if it fails it's probably because the network already exists*/})
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
static createDockerNetworkForContainerManagerServer(platformConfig) {
|
|
23
23
|
logInfo({ message: '[DockerService] Creating docker network for comunication between containers' })
|
|
24
24
|
return exec(`docker network create ${platformConfig.ciDockerNetworkName}`)
|
|
25
|
+
.catch(() => {/* if it fails it's probably because the network already exists*/ })
|
|
25
26
|
}
|
|
26
27
|
|
|
27
28
|
static stopContainer(deploymentRequest) {
|
|
28
29
|
const name = deploymentRequest.image.replaceAll('/', '_')
|
|
29
|
-
logInfo({ message: `[DockerService]
|
|
30
|
+
logInfo({ message: `[DockerService] Stopping container for ${name}` })
|
|
30
31
|
return exec(`docker stop ${name}`)
|
|
31
32
|
.catch(() => {}) // no worries if container isn't there
|
|
32
33
|
}
|
|
33
34
|
|
|
35
|
+
static removeImage(deploymentRequest) {
|
|
36
|
+
const name = deploymentRequest.image.replaceAll('/', '_')
|
|
37
|
+
logInfo({ message: `[DockerService] Removing image ${name}` })
|
|
38
|
+
return exec(`docker image rm -f ${name}`)
|
|
39
|
+
.catch(() => {}) // no worries if container isn't there
|
|
40
|
+
}
|
|
41
|
+
|
|
34
42
|
static startContainer(platformConfig, { image, containerPort, hostPort, registry, env }) {
|
|
35
43
|
const name = image.replaceAll('/', '_')
|
|
36
44
|
const imageUrl = !!registry ? `${registry}/${image}` : image
|
|
@@ -59,6 +67,7 @@ class DockerService {
|
|
|
59
67
|
|
|
60
68
|
return DockerService.resolveCredentials(deploymentRequest)
|
|
61
69
|
.then(() => DockerService.stopContainer(deploymentRequest))
|
|
70
|
+
.then(() => DockerService.removeImage(deploymentRequest))
|
|
62
71
|
.then(() => DockerService.startContainer(platformConfig, deploymentRequest))
|
|
63
72
|
}
|
|
64
73
|
|
|
@@ -1,17 +1,4 @@
|
|
|
1
1
|
const { DockerService } = require('./docker-service')
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
{
|
|
6
|
-
type: 'CONTAINER',
|
|
7
|
-
dockerFile: './Dockerfile-prod',
|
|
8
|
-
dockerContext: './',
|
|
9
|
-
targetDeploymentPlatform: 'oskarssylwan',
|
|
10
|
-
image: 'mongo',
|
|
11
|
-
hostPort: '3005',
|
|
12
|
-
containerPort: '3000',
|
|
13
|
-
subdomain: 'cms',
|
|
14
|
-
env: {},
|
|
15
|
-
registry: 'ghcr.io'
|
|
16
|
-
}
|
|
17
|
-
)
|
|
3
|
+
|
|
4
|
+
DockerService.removeImage({ ciDockerNetworkName: 'foo', image: 'mongo' })
|
|
@@ -1,5 +1,10 @@
|
|
|
1
|
-
const { Stack } = require('aws-cdk-lib')
|
|
2
|
-
const {
|
|
1
|
+
const { Stack, Duration } = require('aws-cdk-lib')
|
|
2
|
+
const {
|
|
3
|
+
HostedZone,
|
|
4
|
+
ARecord,
|
|
5
|
+
MxRecord,
|
|
6
|
+
RecordTarget
|
|
7
|
+
} = require('aws-cdk-lib/aws-route53')
|
|
3
8
|
const { SupportedDeploymentTypes, SupportedEnvironments } = require('../config')
|
|
4
9
|
const { DeploymentTemplateService } = require('../template')
|
|
5
10
|
|
|
@@ -41,21 +46,46 @@ class DnsStack extends Stack {
|
|
|
41
46
|
DeploymentTemplateService
|
|
42
47
|
.groupDeploymentDomainsByRootDomain(containerDeployments)
|
|
43
48
|
.forEach((domains, rootDomain) => {
|
|
44
|
-
const
|
|
49
|
+
const zone = new HostedZone(this, rootDomain, { zoneName: rootDomain })
|
|
45
50
|
|
|
46
51
|
domains.forEach(domain => {
|
|
47
52
|
new ARecord(this, domain, {
|
|
48
|
-
zone
|
|
53
|
+
zone,
|
|
49
54
|
recordName: domain,
|
|
50
|
-
target: RecordTarget.fromIpAddresses(props.containerDeploymentTargetPublicIp)
|
|
55
|
+
target: RecordTarget.fromIpAddresses(props.containerDeploymentTargetPublicIp),
|
|
56
|
+
ttl: Duration.seconds(60)
|
|
51
57
|
})
|
|
52
58
|
})
|
|
53
59
|
|
|
60
|
+
if (props.config.dnsRecords && props.config.dnsRecords[rootDomain]) {
|
|
61
|
+
const records = props.config.dnsRecords[rootDomain] || []
|
|
62
|
+
|
|
63
|
+
records.forEach(({ type, ttl, recordName, values }) => {
|
|
64
|
+
switch (type) {
|
|
65
|
+
|
|
66
|
+
case 'MX':
|
|
67
|
+
new MxRecord(
|
|
68
|
+
this,
|
|
69
|
+
`${recordName}-MX-Record`,
|
|
70
|
+
{ type, recordName, values, ttl: Duration.seconds(ttl), zone }
|
|
71
|
+
)
|
|
72
|
+
break
|
|
73
|
+
|
|
74
|
+
default:
|
|
75
|
+
throw new Error(`Unsupported record type: ${type}`)
|
|
76
|
+
}
|
|
77
|
+
})
|
|
78
|
+
}
|
|
79
|
+
|
|
54
80
|
})
|
|
55
81
|
|
|
56
82
|
}
|
|
57
83
|
}
|
|
58
84
|
|
|
85
|
+
function createDnsRecords(zone, records) {
|
|
86
|
+
|
|
87
|
+
}
|
|
88
|
+
|
|
59
89
|
module.exports = {
|
|
60
90
|
DnsStack
|
|
61
91
|
}
|
|
@@ -33,8 +33,10 @@ class TrustCiStack extends Stack {
|
|
|
33
33
|
const GitHubPrincipal = new OpenIdConnectPrincipal(provider)
|
|
34
34
|
.withConditions({
|
|
35
35
|
StringLike: {
|
|
36
|
-
'token.actions.githubusercontent.com:sub':
|
|
37
|
-
|
|
36
|
+
'token.actions.githubusercontent.com:sub': `repo:${props.config.ciGithubActionsRepo}:*`
|
|
37
|
+
},
|
|
38
|
+
StringEquals: {
|
|
39
|
+
'token.actions.githubusercontent.com:aud': 'sts.amazonaws.com'
|
|
38
40
|
}
|
|
39
41
|
})
|
|
40
42
|
|