@ossy/deployment-tools 0.0.90 → 0.0.92

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
@@ -45,7 +45,56 @@ The `cdk.json` file tells the CDK Toolkit how to execute your app.
45
45
 
46
46
  ## Useful commands
47
47
 
48
+
49
+ **SSH into instance**
50
+ ```
51
+ ssh -i path/to/keys ubuntu@<ip>
52
+ ```
53
+
54
+ **View running containers**
55
+ ```
56
+ docker ps
57
+ ```
58
+
59
+ **View logs from docker container**
60
+ ```
61
+ docker logs <id|alias>
62
+ ```
63
+
64
+ **View logs from deployment-tools service**
65
+ ```
66
+ // With last 200 lines and follow new logs
67
+ journalctl -u deployment-tools.service -n 200 -f
48
68
  ```
49
- // journalctl -u deployment-tools.service
50
- // docker logs
69
+
70
+ **View logs from caddy service**
71
+ ```
72
+ // With last 200 lines and follow new logs
73
+ journalctl -u caddy-route53.service -n 200 -f
74
+ ```
75
+
76
+ **Upgrade deployment-tools server version**
77
+
78
+ - 1 release new version of the npm package with `npm publish`
79
+ - 2 ssh into the instance with `ssh -i path/to/keys ubuntu@<ip>`
80
+ - 3 stop the deployment-tools services with `sudo systemctl stop deployment-tools.service`
81
+ - 4 remove the old version of the tool woth `rm -rf ~/.npm/_npx`
82
+ - 5 start the deployment-tools services again with `sudo systemctl start deployment-tools.service`
83
+
84
+ That's it, the service will download the latest version of the package.
85
+
86
+ **Update Nodejs on the server**
87
+ ```
88
+ # Remove old NodeSource repository if it exists
89
+ sudo rm -f /etc/apt/sources.list.d/nodesource.list
90
+
91
+ # Download and run the Node.js 24.x setup script
92
+ curl -fsSL https://deb.nodesource.com/setup_24.x | sudo -E bash -
93
+
94
+ # Install Node.js 24
95
+ sudo apt-get install -y nodejs
96
+
97
+ # Verify the installation
98
+ node --version
99
+ npm --version
51
100
  ```
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ossy/deployment-tools",
3
- "version": "0.0.90",
3
+ "version": "0.0.92",
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",
@@ -74,7 +74,6 @@ class CaddyService {
74
74
  }
75
75
 
76
76
  static applyProxyConfig(containerDeploymentTemplate) {
77
-
78
77
  return CaddyService.getProxyConfig(containerDeploymentTemplate)
79
78
  .then(proxyConfig => {
80
79
  proxyConfig
@@ -1,10 +1,11 @@
1
1
  const { exec: execBash } = require('child_process')
2
- const { logInfo, logDebug, logErrorAndReject } = require('../log')
2
+ const { logInfo, logError, logDebug, logErrorAndReject } = require('../log')
3
3
 
4
4
  const exec = command => new Promise((resolve, reject) => {
5
5
  execBash(command, (error, stdout, stderr) => {
6
- if (error) return reject(error)
7
- // if (stderr) return reject(stderr)
6
+ logInfo({ message: `[DockerService] ${stderr}` })
7
+
8
+ if (error) return reject({ error, stderr })
8
9
  resolve(stdout, stderr)
9
10
  })
10
11
  })
@@ -15,20 +16,28 @@ const exec = command => new Promise((resolve, reject) => {
15
16
  class DockerService {
16
17
 
17
18
  static startDefaultContainers(platformConfig) {
19
+ logInfo({ message: '[DockerService] Starting default containers' })
18
20
  return exec(`docker run -d --name=mongodb --network=${platformConfig.ciDockerNetworkName} --network-alias=mongodb --rm mongo`)
19
- .catch(() => {/* if it fails it's probably because the network already exists*/})
21
+ .catch(() => {
22
+ logError({ message: '[DockerService] Faild to start default containers' })
23
+ })
20
24
  }
21
25
 
22
26
  static createDockerNetworkForContainerManagerServer(platformConfig) {
23
27
  logInfo({ message: '[DockerService] Creating docker network for comunication between containers' })
24
28
  return exec(`docker network create ${platformConfig.ciDockerNetworkName}`)
25
- .catch(() => {/* if it fails it's probably because the network already exists*/ })
29
+ .catch(() => {
30
+ /* if it fails it's probably because the network already exists*/
31
+ logError({ message: '[DockerService] Faild to start default containers' })
32
+ })
26
33
  }
27
34
 
28
35
  static stopContainer(deploymentRequest) {
29
36
  logInfo({ message: `[DockerService] Stopping container for ${deploymentRequest.domain}` })
30
37
  return exec(`docker stop c-${deploymentRequest.domain}`)
31
- .catch(() => {}) // no worries if container isn't there
38
+ .catch(() => {
39
+ logError({ message: `[DockerService] Faild to stop container for ${deploymentRequest.domain}` })
40
+ }) // no worries if container isn't there
32
41
  }
33
42
 
34
43
  static removeImage(deploymentRequest) {
@@ -36,7 +45,9 @@ class DockerService {
36
45
  const name = !!registry ? `${registry}/${image}` : image
37
46
  logInfo({ message: `[DockerService] Removing image ${name}` })
38
47
  return exec(`docker image rm -f ${name}`)
39
- .catch(() => {}) // no worries if container isn't there
48
+ .catch(() => {
49
+ logError({ message: `[DockerService] Faild to remove image for ${deploymentRequest.domain}` })
50
+ }) // no worries if container isn't there
40
51
  }
41
52
 
42
53
  static pullImage({ image, registry }) {
@@ -82,6 +93,7 @@ class DockerService {
82
93
  .then(() => DockerService.removeImage(deploymentRequest))
83
94
  .then(() => DockerService.pullImage(deploymentRequest))
84
95
  .then(() => DockerService.startContainer(platformConfig, deploymentRequest))
96
+ .catch(logErrorAndReject('[DockerService] Deployment failed'))
85
97
  }
86
98
 
87
99
  static getUnusedPort() {
@@ -3,7 +3,7 @@ const { DockerService } = require('./docker-service')
3
3
 
4
4
  const deploymentTemplate = {
5
5
  "domain": "api.qa.ossy.se",
6
- "image": "ossy-se/cms-api",
6
+ "image": "ossy-se/api",
7
7
  "targetDeploymentPlatform": "ossybot",
8
8
  "type": "CONTAINER",
9
9
  "hostPort": "3001",
@@ -1 +0,0 @@
1
- {"apps":{"http":{"servers":{"deployment-tools":{"listen":[":443"],"routes":[{"@id":"cms.qa.ossy.se","handle":[{"handler":"subroute","routes":[{"handle":[{"handler":"reverse_proxy","upstreams":[{"dial":"localhost:3015"}]}]}]}],"match":[{"host":["cms.qa.ossy.se"]}]},{"@id":"www.plexus-sanitas.com","handle":[{"handler":"subroute","routes":[{"handle":[{"handler":"reverse_proxy","upstreams":[{"dial":"localhost:3000"}]}]}]}],"match":[{"host":["www.plexus-sanitas.com"]}]},{"@id":"www.plexus-sanitas.com","handle":[{"handler":"subroute","routes":[{"handle":[{"handler":"reverse_proxy","upstreams":[{"dial":"localhost:3016"}]}]}]}],"match":[{"host":["www.plexus-sanitas.com"]}]}]}}},"tls":{"automation":{"policies":[{"issuers":[{"challenges":{"dns":{"provider":{"aws_profile":"ci-client","max_retries":10,"name":"route53"}}},"module":"acme"},{"challenges":{"dns":{"provider":{"max_retries":10,"name":"route53"}}},"module":"zerossl"}],"subjects":["cms.qa.ossy.se","www.plexus-sanitas.com"]}]}}}}