@ossy/deployment-tools 0.0.74 → 0.0.76
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/README.md +2 -1
- package/package.json +1 -1
- package/src/config/platform-config.js +2 -6
- package/src/docker/docker-service.js +1 -0
- package/src/docker/docker-service.playground.js +17 -15
- package/src/infrastructure/cli.js +1 -1
- package/src/infrastructure/container-deployment-target/container-deployment-target.js +1 -7
- package/src/infrastructure/deployment-target-stack.js +21 -1
- package/src/infrastructure/dns-stack.js +33 -4
- package/src/infrastructure/trust-ci-stack.js +4 -2
package/README.md
CHANGED
|
@@ -122,7 +122,8 @@ To add a new account follow the steps below.
|
|
|
122
122
|
- don't forget to add the keypair
|
|
123
123
|
- run the cdk ls command to make sure the new stack is picked up
|
|
124
124
|
- run cdk bootstrap for the account and region. This will create necessary resources like roles used by aws cdk.
|
|
125
|
-
-
|
|
125
|
+
- run deploy for all stacks
|
|
126
|
+
- add the instanceIp, awsRoleToAssume, and staticBucket name to the platforms.json file
|
|
126
127
|
|
|
127
128
|
|
|
128
129
|
<!-- Deploys AWS infrastructure
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ossy/deployment-tools",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.76",
|
|
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 - ?
|
|
@@ -54,15 +55,10 @@ class PlatformConfigService {
|
|
|
54
55
|
const awsDeploymentSqsArn =
|
|
55
56
|
`https://sqs.${withDefaults.awsRegion}.amazonaws.com/${withDefaults.awsAccountId}/${awsDeploymentSqsName}`
|
|
56
57
|
|
|
57
|
-
const awsRoleToAssume = process.env.CI
|
|
58
|
-
? `github-ci-role-${withDefaults.platformName}`
|
|
59
|
-
: undefined
|
|
60
|
-
|
|
61
58
|
return {
|
|
62
59
|
...withDefaults,
|
|
63
60
|
awsDeploymentSqsName,
|
|
64
|
-
awsDeploymentSqsArn
|
|
65
|
-
awsRoleToAssume,
|
|
61
|
+
awsDeploymentSqsArn
|
|
66
62
|
}
|
|
67
63
|
|
|
68
64
|
}
|
|
@@ -22,6 +22,7 @@ class DockerService {
|
|
|
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 fils it's probably because the network already exists*/})
|
|
25
26
|
}
|
|
26
27
|
|
|
27
28
|
static stopContainer(deploymentRequest) {
|
|
@@ -1,17 +1,19 @@
|
|
|
1
1
|
const { DockerService } = require('./docker-service')
|
|
2
2
|
|
|
3
|
-
DockerService.deploy(
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
)
|
|
3
|
+
// DockerService.deploy(
|
|
4
|
+
// { ciDockerNetworkName: 'deployment-tools' },
|
|
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
|
+
// )
|
|
18
|
+
|
|
19
|
+
DockerService.createDockerNetworkForContainerManagerServer({ ciDockerNetworkName: 'foo' })
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
/* eslint-disable no-new */
|
|
3
|
-
const { App } = require('aws-cdk-lib')
|
|
3
|
+
const { App, CfnOutput } = require('aws-cdk-lib')
|
|
4
4
|
const { TrustCiStack } = require('./trust-ci-stack')
|
|
5
5
|
const { DeploymentTargetStack } = require('./deployment-target-stack')
|
|
6
6
|
const { DnsStack } = require('./dns-stack')
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const {
|
|
1
|
+
const { Duration, RemovalPolicy } = require('aws-cdk-lib')
|
|
2
2
|
const { Construct } = require('constructs')
|
|
3
3
|
const {
|
|
4
4
|
Instance,
|
|
@@ -156,12 +156,6 @@ class ContainerDeploymentTarget extends Construct {
|
|
|
156
156
|
|
|
157
157
|
this.instancePublicIp = ec2Instance.instancePublicIp
|
|
158
158
|
|
|
159
|
-
new CfnOutput(this, 'Instance Ip', {
|
|
160
|
-
value: ec2Instance.instancePublicIp,
|
|
161
|
-
description: 'Public ip of the ec2 instance',
|
|
162
|
-
exportName: 'instanceIp'
|
|
163
|
-
})
|
|
164
|
-
|
|
165
159
|
}
|
|
166
160
|
}
|
|
167
161
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/* eslint-disable no-new */
|
|
2
2
|
const { nanoid } = require('nanoid')
|
|
3
|
-
const { Stack, Duration, RemovalPolicy } = require('aws-cdk-lib')
|
|
3
|
+
const { CfnOutput, Stack, Duration, RemovalPolicy } = require('aws-cdk-lib')
|
|
4
4
|
const { HostedZone, ARecord, RecordTarget } = require('aws-cdk-lib/aws-route53')
|
|
5
5
|
const { Bucket, BucketEncryption, BlockPublicAccess } = require('aws-cdk-lib/aws-s3')
|
|
6
6
|
const { ContainerDeploymentTarget } = require('./container-deployment-target')
|
|
@@ -37,6 +37,26 @@ class DeploymentTargetStack extends Stack {
|
|
|
37
37
|
})
|
|
38
38
|
|
|
39
39
|
this.containerDeploymentTargetPublicIp = containerDeploymentTarget.instancePublicIp
|
|
40
|
+
this.staticDeploymentTargetBucketName = staticDeploymentTarget.bucketName
|
|
41
|
+
this.staticDeploymentTargetBucketArn = staticDeploymentTarget.bucketArn
|
|
42
|
+
|
|
43
|
+
new CfnOutput(this, 'ContainerDeploymentTargetPublicIp', {
|
|
44
|
+
value: containerDeploymentTarget.instancePublicIp,
|
|
45
|
+
description: 'Public ip of the ec2 instance',
|
|
46
|
+
exportName: 'awsContainerDeploymentTargetPublicIp'
|
|
47
|
+
})
|
|
48
|
+
|
|
49
|
+
new CfnOutput(this, 'StaticDeploymentTargetBucketName', {
|
|
50
|
+
value: staticDeploymentTarget.bucketName,
|
|
51
|
+
description: 'Name of static deployment target bucket',
|
|
52
|
+
exportName: 'awsStaticDeploymentTargetBucketName'
|
|
53
|
+
})
|
|
54
|
+
|
|
55
|
+
new CfnOutput(this, 'StaticDeploymentTargetBucketArn', {
|
|
56
|
+
value: staticDeploymentTarget.bucketArn,
|
|
57
|
+
description: 'Name of static deployment target bucket',
|
|
58
|
+
exportName: 'awsStaticDeploymentTargetBucketArn'
|
|
59
|
+
})
|
|
40
60
|
|
|
41
61
|
}
|
|
42
62
|
}
|
|
@@ -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,45 @@ 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
55
|
target: RecordTarget.fromIpAddresses(props.containerDeploymentTargetPublicIp)
|
|
51
56
|
})
|
|
52
57
|
})
|
|
53
58
|
|
|
59
|
+
if (props.config.dnsRecords && props.config.dnsRecords[rootDomain]) {
|
|
60
|
+
const records = props.config.dnsRecords[rootDomain] || []
|
|
61
|
+
|
|
62
|
+
records.forEach(({ type, ttl, recordName, values }) => {
|
|
63
|
+
switch (type) {
|
|
64
|
+
|
|
65
|
+
case 'MX':
|
|
66
|
+
new MxRecord(
|
|
67
|
+
this,
|
|
68
|
+
`${recordName}-MX-Record`,
|
|
69
|
+
{ type, recordName, values, ttl: Duration.seconds(ttl), zone }
|
|
70
|
+
)
|
|
71
|
+
break
|
|
72
|
+
|
|
73
|
+
default:
|
|
74
|
+
throw new Error(`Unsupported record type: ${type}`)
|
|
75
|
+
}
|
|
76
|
+
})
|
|
77
|
+
}
|
|
78
|
+
|
|
54
79
|
})
|
|
55
80
|
|
|
56
81
|
}
|
|
57
82
|
}
|
|
58
83
|
|
|
84
|
+
function createDnsRecords(zone, records) {
|
|
85
|
+
|
|
86
|
+
}
|
|
87
|
+
|
|
59
88
|
module.exports = {
|
|
60
89
|
DnsStack
|
|
61
90
|
}
|
|
@@ -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
|
|