@ossy/deployment-tools 0.0.89 → 0.0.91

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
51
- ```
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
+ **Update Nodejs on the server**
77
+ ```
78
+ # Remove old NodeSource repository if it exists
79
+ sudo rm -f /etc/apt/sources.list.d/nodesource.list
80
+
81
+ # Download and run the Node.js 24.x setup script
82
+ curl -fsSL https://deb.nodesource.com/setup_24.x | sudo -E bash -
83
+
84
+ # Install Node.js 24
85
+ sudo apt-get install -y nodejs
86
+
87
+ # Verify the installation
88
+ node --version
89
+ npm --version
90
+ ```
91
+
92
+ **Upgrade deployment-tools server version**
93
+
94
+ - 1 release new version of the npm package with `npm publish`
95
+ - 2 ssh into the instance with `ssh -i path/to/keys ubuntu@<ip>`
96
+ - 3 stop the deployment-tools services with `sudo systemctl stop deployment-tools.service`
97
+ - 4 remove the old version of the tool woth `rm -rf ~/.npm/_npx`
98
+ - 5 start the deployment-tools services again with `sudo systemctl start deployment-tools.service`
99
+
100
+ That's it, the service will download the latest version of the package.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ossy/deployment-tools",
3
- "version": "0.0.89",
3
+ "version": "0.0.91",
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",
@@ -60,6 +60,7 @@ class CaddyService {
60
60
  }
61
61
 
62
62
  static getProxyConfig(containerDeploymentTemplate) {
63
+ logInfo({ message: `[CaddyService] Checking if a proxy for ${containerDeploymentTemplate.domain} exists` })
63
64
  return fetch(`http://localhost:2019/id/${containerDeploymentTemplate.domain}`, {
64
65
  method: 'GET',
65
66
  headers: { 'Content-Type': 'application/json' }
@@ -82,6 +83,7 @@ class CaddyService {
82
83
  }
83
84
 
84
85
  static addProxyConfig(containerDeploymentTemplate) {
86
+ logInfo({ message: `[CaddyService] Adding proxy for ${containerDeploymentTemplate.domain}` })
85
87
  const proxyConfig = CaddyConfigService.createProxyConfig(containerDeploymentTemplate)
86
88
  return fetch('http://localhost:2019/config/apps/http/servers/deployment-tools/routes', {
87
89
  method: 'POST',
@@ -93,6 +95,7 @@ class CaddyService {
93
95
  }
94
96
 
95
97
  static replaceProxyConfig(containerDeploymentTemplate) {
98
+ logInfo({ message: `[CaddyService] Replacing proxy for ${containerDeploymentTemplate.domain}` })
96
99
  const proxyConfig = CaddyConfigService.createProxyConfig(containerDeploymentTemplate)
97
100
  return fetch(`http://localhost:2019/id/${containerDeploymentTemplate.domain}`, {
98
101
  method: 'POST',
@@ -1,9 +1,9 @@
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)
6
+ if (error || stderr) return reject({ error, stderr })
7
7
  // if (stderr) return reject(stderr)
8
8
  resolve(stdout, stderr)
9
9
  })
@@ -15,20 +15,28 @@ const exec = command => new Promise((resolve, reject) => {
15
15
  class DockerService {
16
16
 
17
17
  static startDefaultContainers(platformConfig) {
18
+ logInfo({ message: '[DockerService] Starting default containers' })
18
19
  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*/})
20
+ .catch(() => {
21
+ logError({ message: '[DockerService] Faild to start default containers' })
22
+ })
20
23
  }
21
24
 
22
25
  static createDockerNetworkForContainerManagerServer(platformConfig) {
23
26
  logInfo({ message: '[DockerService] Creating docker network for comunication between containers' })
24
27
  return exec(`docker network create ${platformConfig.ciDockerNetworkName}`)
25
- .catch(() => {/* if it fails it's probably because the network already exists*/ })
28
+ .catch(() => {
29
+ /* if it fails it's probably because the network already exists*/
30
+ logError({ message: '[DockerService] Faild to start default containers' })
31
+ })
26
32
  }
27
33
 
28
34
  static stopContainer(deploymentRequest) {
29
35
  logInfo({ message: `[DockerService] Stopping container for ${deploymentRequest.domain}` })
30
36
  return exec(`docker stop c-${deploymentRequest.domain}`)
31
- .catch(() => {}) // no worries if container isn't there
37
+ .catch(() => {
38
+ logError({ message: `[DockerService] Faild to stop container for ${deploymentRequest.domain}` })
39
+ }) // no worries if container isn't there
32
40
  }
33
41
 
34
42
  static removeImage(deploymentRequest) {
@@ -36,7 +44,9 @@ class DockerService {
36
44
  const name = !!registry ? `${registry}/${image}` : image
37
45
  logInfo({ message: `[DockerService] Removing image ${name}` })
38
46
  return exec(`docker image rm -f ${name}`)
39
- .catch(() => {}) // no worries if container isn't there
47
+ .catch(() => {
48
+ logError({ message: `[DockerService] Faild to remove image for ${deploymentRequest.domain}` })
49
+ }) // no worries if container isn't there
40
50
  }
41
51
 
42
52
  static pullImage({ image, registry }) {
@@ -82,6 +92,7 @@ class DockerService {
82
92
  .then(() => DockerService.removeImage(deploymentRequest))
83
93
  .then(() => DockerService.pullImage(deploymentRequest))
84
94
  .then(() => DockerService.startContainer(platformConfig, deploymentRequest))
95
+ .catch(logErrorAndReject('[DockerService] Deployment failed'))
85
96
  }
86
97
 
87
98
  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",