@flowfuse/driver-docker 2.0.0 → 2.2.0

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/CHANGELOG.md CHANGED
@@ -1,3 +1,12 @@
1
+ #### 2.2.0: Release
2
+
3
+ - Pull missing Stack containers on first use (#85) @hardillb
4
+ - Change default stack container (#84) @hardillb
5
+
6
+ #### 2.1.0: Release
7
+
8
+ - Add log passthrough support (#82) @hardillb
9
+
1
10
  #### 2.0.0: Release
2
11
 
3
12
 
package/README.md CHANGED
@@ -14,11 +14,13 @@ driver:
14
14
  socket: /var/run/docker.sock
15
15
  registry: containers.flowforge.com
16
16
  privateCA: /full/path/to/chain.pem
17
+ logPassthrough: true
17
18
  ```
18
19
 
19
20
  - `registry` is the Docker Registry to load Stack Containers from (default: Docker Hub)
20
21
  - `socket` is the path to the docker unix domain socket (default: /var/run/docker.sock)
21
- - privateCA: is the fully qualified path to a pem file containing trusted CA cert chain (default: not set)
22
+ - `privateCA`: is the fully qualified path to a pem file containing trusted CA cert chain (default: not set)
23
+ - `logPassthrough` Have Node-RED logs printed in JSON format to container stdout (default: false)
22
24
 
23
25
  ### Configuration via environment variables
24
26
 
package/docker.js CHANGED
@@ -86,13 +86,51 @@ const createContainer = async (project, domain) => {
86
86
  contOptions.Env.push(`FORGE_NR_SECRET=${credentialSecret}`)
87
87
  }
88
88
 
89
- if (this._app.config.driver.options.privateCA && fs.existsSync(this._app.config.driver.options.privateCA)) {
89
+ if (this._options?.logPassthrough) {
90
+ contOptions.Env.push('FORGE_LOG_PASSTHROUGH=true')
91
+ }
92
+
93
+ if (this._app.config.driver.options?.privateCA && fs.existsSync(this._app.config.driver.options?.privateCA)) {
90
94
  contOptions.Binds = [
91
95
  `${this._app.config.driver.options.privateCA}:/usr/local/ssl-certs/chain.pem`
92
96
  ]
93
97
  contOptions.Env.push('NODE_EXTRA_CA_CERTS=/usr/local/ssl-certs/chain.pem')
94
98
  }
95
99
 
100
+ const containerList = await this._docker.listImages()
101
+ let containerFound = false
102
+ for (const cont of containerList) {
103
+ if (cont.RepoTags.includes(stack.container)) {
104
+ containerFound = true
105
+ break
106
+ }
107
+ }
108
+
109
+ if (!containerFound) {
110
+ this._app.log.info(`Container for stack ${stack.name} not found, pulling ${stack.container}`)
111
+ // https://github.com/apocas/dockerode/issues/703
112
+ try {
113
+ await new Promise((resolve, reject) => {
114
+ this._docker.pull(stack.container, (err, stream) => {
115
+ if (!err) {
116
+ this._docker.modem.followProgress(stream, onFinished)
117
+ function onFinished (err, output) {
118
+ if (!err) {
119
+ resolve(true)
120
+ return
121
+ }
122
+ reject(err)
123
+ }
124
+ } else {
125
+ reject(err)
126
+ }
127
+ })
128
+ })
129
+ } catch (err) {
130
+ this._app.log.debug(`Error pulling image ${stack.container} ${err.message}`)
131
+ }
132
+ }
133
+
96
134
  const container = await this._docker.createContainer(contOptions)
97
135
  return container.start()
98
136
  .then(async () => {
@@ -437,7 +475,7 @@ module.exports = {
437
475
  const properties = {
438
476
  cpu: 10,
439
477
  memory: 256,
440
- container: 'flowforge/node-red',
478
+ container: 'flowfuse/node-red',
441
479
  ...this._app.config.driver.options?.default_stack
442
480
  }
443
481
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flowfuse/driver-docker",
3
- "version": "2.0.0",
3
+ "version": "2.2.0",
4
4
  "description": "Docker driver for FlowFuse",
5
5
  "main": "docker.js",
6
6
  "scripts": {