@ossy/deployment-tools 0.0.76 → 0.0.79

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 CHANGED
@@ -37,111 +37,6 @@ npx --yes @ossy/deployment-tools deploy \
37
37
  --ossyfile packages/${{ github.event.inputs.packageName }}/ossy.json \
38
38
  ```
39
39
 
40
- ## Concepts
41
-
42
- **Workspace**
43
-
44
- A workspace is an umbrella for our services.
45
- It needs to be associated with at least one billable account.
46
- The workspace holds information like what tools and services are in use and should
47
- be billed, and what users have access to these tools and services.
48
-
49
- ```
50
- id: string;
51
- name: string;
52
- participants: WorkspaceParticipant[];
53
- services: ServiceDefinition[];
54
- billingInformation
55
-
56
- ```
57
-
58
- ## Our domains
59
-
60
- ossy.se
61
- www.ossy.se
62
- test.ossy.se
63
-
64
- api.ossy.se
65
- api.test.ossy.se
66
-
67
- plexus.ossy.se
68
- plexus.test.ossy.se
69
-
70
- oskarssylwan.se
71
- www.oskarssylwan.se
72
- test.oskarssylwan.se
73
-
74
-
75
- ## Overview of our infrastructure
76
-
77
- We use AWS to host our infrastructure and all of it is defined in JavaScript with the help of
78
- (AWS CDK)[https://aws.amazon.com/cdk/].
79
-
80
- **Static content**
81
-
82
- We use a s3 bucket for static content.
83
- This bucket is used to host websites, images, videos and other static content.
84
- On root level you'll find directories that represent one workspace each.
85
-
86
- /<workspacId>/<service>/
87
- /<workspacId>/websites/website-id
88
-
89
- The bucket have directories for each workspace that is the workspaceID.
90
-
91
- The bucket have directories for each workspace that contains a media directory and website directories
92
-
93
- - a place to host media files like images, videos, pdf documents etc.
94
- - a platform to host different docker images to
95
- - a mongodb database that can ensure data persistance without much effort from our our side
96
- - an email service
97
- - an easy way to host multiple single page applications
98
-
99
- Stacks
100
-
101
- - email service stack per env
102
- - media bucket stack per env
103
- - stack for dns records with the account that holds domain names
104
-
105
- ### Adding a new AWS account
106
- We have a different account for each service and environment.
107
- To add a new account follow the steps below.
108
-
109
- - Create an email group in GoogleAdmin with **public post access**.
110
- The email should follow the pattern <service-name>-<env>@ossy.se.
111
- If it's an account for prod use <service-name>@ossy.se.
112
- Don't forgett to add yourself and other relevant people to the group.
113
- - Log into our root organisation account and create a new aws account
114
- with the same naming pattern and email as described above.
115
- - Log out of the organisation account then send a password reset request to the
116
- newly created account using the new email.
117
- - Create a new user in the account with the same name as the account.
118
- In the same process add the AdministratorAccess managed policy to the user.
119
- - Create an access key to the account and add it as a (named profile)[https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-profiles.html] on your computer
120
- - Create a keypair in the correct region and download it
121
- - Add the new environment to the platforms.json file in this repository
122
- - don't forget to add the keypair
123
- - run the cdk ls command to make sure the new stack is picked up
124
- - run cdk bootstrap for the account and region. This will create necessary resources like roles used by aws cdk.
125
- - run deploy for all stacks
126
- - add the instanceIp, awsRoleToAssume, and staticBucket name to the platforms.json file
127
-
128
-
129
- <!-- Deploys AWS infrastructure
130
- ```
131
- npx --yes @ossy/deployment-tools infrastructure deploy
132
- ```
133
-
134
- Destroys AWS infrastructure
135
- ```
136
- npx --yes @ossy/deployment-tools infrastructure destroy
137
- ```
138
-
139
- Prints AWS infrastructure stacks
140
- ```
141
- npx --yes @ossy/deployment-tools infrastructure ls
142
- ``` -->
143
-
144
-
145
40
  The `cdk.json` file tells the CDK Toolkit how to execute your app.
146
41
 
147
42
  * `cdk deploy` deploy this stack to your default AWS account/region
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ossy/deployment-tools",
3
- "version": "0.0.76",
3
+ "version": "0.0.79",
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",
@@ -18,16 +18,16 @@
18
18
  "@aws-sdk/client-sqs": "^3.245.0",
19
19
  "@aws-sdk/client-sts": "^3.245.0",
20
20
  "arg": "^5.0.2",
21
- "aws-cdk-lib": "^2.59.0",
22
- "constructs": "^10.1.211",
21
+ "aws-cdk": "^2.73.0",
22
+ "aws-cdk-lib": "^2.73.0",
23
+ "constructs": "^10.1.304",
23
24
  "express": "^4.18.1",
24
25
  "glob": "^9.3.2",
25
26
  "nanoid": "^3.3.4",
26
27
  "node-fetch": "^2.6.7"
27
28
  },
28
29
  "devDependencies": {
29
- "aws-cdk": "^2.59.0",
30
30
  "jest": "^27.5.1",
31
- "jsdoc": "^3.6.11"
31
+ "jsdoc": "^4.0.2"
32
32
  }
33
33
  }
package/src/deploy/cli.js CHANGED
@@ -22,8 +22,8 @@ const deploy = options => {
22
22
  '--platforms-path': String,
23
23
  '-pp': '--platforms-path',
24
24
 
25
- '--ossy-files': String,
26
- '-o': '--ossy-files',
25
+ '--deployments-path': String,
26
+ '-dp': '--deployments-path',
27
27
 
28
28
 
29
29
  }, { argv: options })
@@ -34,7 +34,7 @@ const deploy = options => {
34
34
  targetDomain: parsedArgs['--domain'],
35
35
  targetPlatform: parsedArgs['--platform'],
36
36
  pathToPlatformTemplates: parsedArgs['--platforms-path'],
37
- globPatternForOssyFiles: parsedArgs['--ossy-files']
37
+ pathToDeploymentTemplates: parsedArgs['--deployments-path']
38
38
  })
39
39
  }
40
40
 
@@ -17,11 +17,11 @@ class PlatformDeploymentService {
17
17
  targetDomain,
18
18
  targetPlatform,
19
19
  pathToPlatformTemplates,
20
- globPatternForOssyFiles
20
+ pathToDeploymentTemplates
21
21
  }) {
22
22
 
23
23
  return Promise.all([
24
- DeploymentTemplateService.readOssyFiles(globPatternForOssyFiles),
24
+ DeploymentTemplateService.readFromFiles(pathToDeploymentTemplates),
25
25
  PlatformTemplateService.readFromFile(pathToPlatformTemplates)
26
26
  .then(templates => templates.map(PlatformConfigService.from))
27
27
  ])
@@ -16,22 +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(logErrorAndReject('[DockerService] Could not start mongodb container'))
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 fils it's probably because the network already exists*/})
25
+ .catch(() => {/* if it fails it's probably because the network already exists*/ })
26
26
  }
27
27
 
28
28
  static stopContainer(deploymentRequest) {
29
29
  const name = deploymentRequest.image.replaceAll('/', '_')
30
- logInfo({ message: `[DockerService] Running docker stop for image with the name of ${name}` })
30
+ logInfo({ message: `[DockerService] Stopping container for ${name}` })
31
31
  return exec(`docker stop ${name}`)
32
32
  .catch(() => {}) // no worries if container isn't there
33
33
  }
34
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
+
35
42
  static startContainer(platformConfig, { image, containerPort, hostPort, registry, env }) {
36
43
  const name = image.replaceAll('/', '_')
37
44
  const imageUrl = !!registry ? `${registry}/${image}` : image
@@ -60,6 +67,7 @@ class DockerService {
60
67
 
61
68
  return DockerService.resolveCredentials(deploymentRequest)
62
69
  .then(() => DockerService.stopContainer(deploymentRequest))
70
+ .then(() => DockerService.removeImage(deploymentRequest))
63
71
  .then(() => DockerService.startContainer(platformConfig, deploymentRequest))
64
72
  }
65
73
 
@@ -1,19 +1,4 @@
1
1
  const { DockerService } = require('./docker-service')
2
2
 
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
3
 
19
- DockerService.createDockerNetworkForContainerManagerServer({ ciDockerNetworkName: 'foo' })
4
+ DockerService.removeImage({ ciDockerNetworkName: 'foo', image: 'mongo' })
@@ -9,7 +9,7 @@ const { PlatformConfigService } = require('../config')
9
9
  const { PlatformDeploymentService } = require('../deploy')
10
10
 
11
11
  Promise.all([
12
- DeploymentTemplateService.readOssyFiles(process.env.OSSY_FILES),
12
+ DeploymentTemplateService.readFromFiles(process.env.DEPLOYMENTS),
13
13
  PlatformTemplateService
14
14
  .readFromFile(process.env.PLATFORMS)
15
15
  .then(templates => templates.map(PlatformConfigService.from))
@@ -52,7 +52,8 @@ class DnsStack extends Stack {
52
52
  new ARecord(this, domain, {
53
53
  zone,
54
54
  recordName: domain,
55
- target: RecordTarget.fromIpAddresses(props.containerDeploymentTargetPublicIp)
55
+ target: RecordTarget.fromIpAddresses(props.containerDeploymentTargetPublicIp),
56
+ ttl: Duration.seconds(60)
56
57
  })
57
58
  })
58
59
 
@@ -25,16 +25,14 @@ class DeploymentTemplateService {
25
25
  /**
26
26
  * Read and and group deployments by targetDeploymentPlatform
27
27
  *
28
- * @param {string} blob - blob pattern for ossy.json files
28
+ * @param {string} blob - blob pattern for deployments.json files
29
29
  */
30
- static readOssyFiles(blob) {
30
+ static readFromFiles(blob) {
31
31
  return glob(blob, { ignore: 'node_modules/**' })
32
32
  .then(filePaths => filePaths
33
33
  .map(path => readFileSync(path, 'utf-8'))
34
- .map(json => JSON.parse(json))
35
- .flatMap(ossyFileContent => ossyFileContent.deployments)
34
+ .flatMap(json => JSON.parse(json))
36
35
  .reduce((deploymentsMap, deployment) => {
37
-
38
36
  if (!!deploymentsMap[deployment.targetDeploymentPlatform]) {
39
37
  return {
40
38
  ...deploymentsMap,
@@ -0,0 +1,5 @@
1
+ const { DeploymentTemplateService } = require('./deployment-template')
2
+
3
+ DeploymentTemplateService.readFromFiles('../infrastructure/deployment*.json')
4
+ // .then(console.log)
5
+ // .catch(console.log)