Fix cleanup of official images, and allow passing Name in container options

This commit is contained in:
Pablo Carranza Velez 2016-07-22 16:50:12 +00:00
parent e41ebbb52b
commit 1d16941a2d
2 changed files with 10 additions and 9 deletions

View File

@ -109,21 +109,20 @@ do ->
Promise.join( Promise.join(
knex('image').select('repoTag') knex('image').select('repoTag')
.map (image) -> .map (image) ->
image.repoTag # Docker sometimes prepends 'docker.io/' to official images
return [ image.repoTag, 'docker.io/' + image.repoTag ]
.then(_.flatten)
knex('app').select() knex('app').select()
.map (app) -> .map (app) ->
app.imageId + ':latest' app.imageId + ':latest'
docker.listImagesAsync() docker.listImagesAsync()
(localTags, apps, images) -> (locallyCreatedTags, apps, images) ->
imageTags = _.map(images, 'RepoTags') imageTags = _.map(images, 'RepoTags')
supervisorTags = _.filter imageTags, (tags) -> supervisorTags = _.filter imageTags, (tags) ->
_.contains(tags, supervisorTag) _.contains(tags, supervisorTag)
appTags = _.filter imageTags, (tags) -> appTags = _.filter imageTags, (tags) ->
_.any tags, (tag) -> _.any tags, (tag) ->
_.contains(apps, tag) _.contains(apps, tag)
locallyCreatedTags = _.filter imageTags, (tags) ->
_.any tags, (tag) ->
_.contains(localTags, tag)
supervisorTags = _.flatten(supervisorTags) supervisorTags = _.flatten(supervisorTags)
appTags = _.flatten(appTags) appTags = _.flatten(appTags)
locallyCreatedTags = _.flatten(locallyCreatedTags) locallyCreatedTags = _.flatten(locallyCreatedTags)
@ -182,8 +181,7 @@ do ->
exports.createImage = (req, res) -> exports.createImage = (req, res) ->
{ registry, repo, tag, fromImage } = req.query { registry, repo, tag, fromImage } = req.query
if fromImage? if fromImage?
repoTag = fromImage repoTag = buildRepoTag(fromImage, tag)
repoTag += ':' + tag if tag?
else else
repoTag = buildRepoTag(repo, tag, registry) repoTag = buildRepoTag(repo, tag, registry)
Promise.using writeLockImages(), -> Promise.using writeLockImages(), ->
@ -261,8 +259,10 @@ do ->
options.Volumes ?= {} options.Volumes ?= {}
_.assign(options.Volumes, utils.defaultVolumes) _.assign(options.Volumes, utils.defaultVolumes)
options.HostConfig.Binds = utils.defaultBinds("containers/#{id}") options.HostConfig.Binds = utils.defaultBinds("containers/#{id}")
query = ''
query = "name=#{options.Name}&" if options.Name?
optsf = optsf =
path: '/containers/create?' path: "/containers/create?#{query}"
method: 'POST' method: 'POST'
options: options options: options
statusCodes: statusCodes:
@ -349,7 +349,7 @@ do ->
deleteContainer(oldContainerId, v: true) deleteContainer(oldContainerId, v: true)
.then -> .then ->
createContainer(req.body, oldContainer.id) createContainer(req.body, oldContainer.id)
.then (data) -> .tap (data) ->
startContainer(data.Id) startContainer(data.Id)
.then (data) -> .then (data) ->
res.json(data) res.json(data)

View File

@ -283,6 +283,7 @@ exports.validContainerOptions = [
'NetworkDisabled' 'NetworkDisabled'
'ExposedPorts' 'ExposedPorts'
'HostConfig' 'HostConfig'
'Name'
] ]
exports.validHostConfigOptions = [ exports.validHostConfigOptions = [