Skip to content
This repository has been archived by the owner on Nov 14, 2019. It is now read-only.

Commit

Permalink
Merge pull request #162 from mesg-foundation/feature/auto-update-docker
Browse files Browse the repository at this point in the history
Use minor version of the Engine
  • Loading branch information
Nicolas Mahé authored Sep 18, 2019
2 parents f8064a2 + 6ca9f2d commit 5ba3c0b
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 2 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"axios": "^0.19.0",
"chalk": "^2.4.2",
"cli-ux": "^5.2.1",
"debug": "^4.1.1",
"download-tarball": "^2.0.0",
"git-clone": "^0.1.0",
"handlebars": "^4.1.2",
Expand Down
12 changes: 12 additions & 0 deletions src/commands/daemon/start.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ export default class Start extends Command {
default: 'info',
options: ['debug', 'info', 'warn', 'error', 'fatal', 'panic']
}),
pull: flags.boolean({
description: 'Pull the latest image of the given version',
default: true,
allowNo: true
})
}

async run() {
Expand All @@ -39,6 +44,13 @@ export default class Start extends Command {
this.log('Engine is already started')
return false
}

if (flags.pull) {
this.spinner.start(`Pulling version ${flags.version}`)
await this.pull(flags.version)
this.spinner.stop()
}

this.spinner.start('Starting Engine')
const eventPromise = this.waitForEvent(({Action, Type, from}) =>
Type === 'container' &&
Expand Down
14 changes: 13 additions & 1 deletion src/docker-command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import {Docker} from 'node-docker-api'
import {Network} from 'node-docker-api/lib/network'
import {homedir} from 'os'
import {join} from 'path'
import {Readable} from 'stream'
import {Readable, Stream} from 'stream'
const debug = require('debug')('docker')

import Command from './root-command'

Expand Down Expand Up @@ -132,4 +133,15 @@ export default abstract class extends Command {
}
})
}

async pull(tag: string): Promise<object> {
const stream = (await this.docker.image.create({}, {
fromImage: 'mesg/engine',
tag
})) as Stream
return new Promise((resolve, reject) => stream
.on('data', (x: any) => debug(x.toString())) // For some reason we need to listen to the data to have the end event
.on('error', reject)
.on('end', resolve))
}
}
2 changes: 1 addition & 1 deletion src/version.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export default {
engine: 'v0.14.2'
engine: 'v0.14'
}

0 comments on commit 5ba3c0b

Please sign in to comment.