Skip to content

Commit 6d8b2fd

Browse files
committed
Merge pull request #439 from CodeNow/image-pull-changes
pull image fixes
2 parents dd3ebf9 + 9ca4ff3 commit 6d8b2fd

4 files changed

Lines changed: 28 additions & 20 deletions

File tree

lib/models/mongo/instance.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,9 @@ InstanceSchema.methods.modifyUnsetContainer = function (cb) {
240240
InstanceSchema.methods.modifyContainerCreateErr = function (err, cb) {
241241
Instance.findByIdAndUpdate(this._id, {
242242
$set: {
243-
'container.error': pick(err, ['message', 'stack', 'data'])
243+
container: {
244+
error: pick(err, ['message', 'stack', 'data', 'imageIsPulling'])
245+
}
244246
}
245247
}, cb);
246248
};

lib/models/mongo/schemas/instance.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,8 @@ var InstanceSchema = module.exports = new Schema({
130130
type: {
131131
message: String,
132132
stack: String,
133-
data: Schema.Types.Mixed
133+
data: Schema.Types.Mixed,
134+
imageIsPulling: Boolean
134135
}
135136
}
136137
}

lib/routes/instances/index.js

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -127,24 +127,31 @@ var createSaveAndNetworkContainer = flow.series(
127127
.catch(
128128
mw.req().setToErr('containerCreateErr'),
129129
mw.req('containerCreateErr.output.statusCode').validate(validations.equals(404))
130+
.then(
131+
mw.req().set('containerCreateErr.imageIsPulling', true)),
132+
instances.model.modifyContainerCreateErr('containerCreateErr'),
133+
mw.req('containerCreateErr.imageIsPulling').validate(validations.equals(true))
130134
.then(
131135
docker.model.pullImage('contextVersion'),
132136
function(req, res, next) {
133137
// emitter.emit('dockerResult') need to emit pull event here
134-
req.dockerResult.on('data', function() {});
138+
req.dockerResult.on('data', function () {
139+
// TODO: pipe to pull-stream
140+
});
141+
// on pull finish, redeploy instance
142+
req.dockerResult.on('end', function () {
143+
flow.series(
144+
runnable.create({}, 'sessionUser'),
145+
runnable.model.redeployInstance('instance', {
146+
forceDock: 'dockerHost',
147+
json: { build: 'build._id.toString()' }
148+
}))(req, res, function (err) {
149+
error.logIfErr(err, req);
150+
});
151+
});
152+
// next immediately, background pull and redeploy
135153
next();
136-
},
137-
runnable.create({}, 'sessionUser'),
138-
// redeploy instance with host. remove lock associated with redeploy route
139-
hosts.model.releaseHostLock('ownerUsername', 'instance.name'),
140-
runnable.model.redeployInstance('instance', {
141-
forceDock: 'dockerHost',
142-
json: { build: 'build._id.toString()' }
143-
}),
144-
hosts.model.acquireHostLock('ownerUsername', 'instance.name'),
145-
instances.findById('instanceId'))
146-
.else(
147-
instances.model.modifyContainerCreateErr('containerCreateErr'))),
154+
})),
148155
mw.req('containerInfo').require()
149156
.then( // container create was successful
150157
docker.model.startUserContainer('containerInfo'),

test/instances/post/201.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -243,11 +243,9 @@ describe('201 POST /instances', {timeout:500}, function () {
243243
beforeEach(function (done) {
244244
extend(ctx.expected, {
245245
containers: exists,
246-
'containers[0]': exists,
247-
'containers[0].ports': exists,
248-
'containers[0].dockerHost': exists,
249-
'containers[0].dockerContainer': exists,
250-
'containers[0].inspect.State.Running': true
246+
'containers[0].error.message': exists,
247+
'containers[0].error.stack': exists,
248+
'containers[0].error.imageIsPulling': true
251249
});
252250
Dockerode.prototype.createContainer = forceImageNotFoundOnCreateErrOnce(Dockerode.prototype.createContainer);
253251
done();

0 commit comments

Comments
 (0)