Remove trailing slashes from working directories of services

This is to combat when a working directory is in the compose file for a
service with a trailing slash. Docker will strip this slash and that
means service comparisons will fail going forward - even if they are the
same.

Change-type: patch
Closes: #635
Signed-off-by: Cameron Diver <cameron@resin.io>
This commit is contained in:
Cameron Diver 2018-04-27 16:51:24 +01:00
parent 45cb5b6c07
commit ddbf3418de
No known key found for this signature in database
GPG Key ID: 69264F9C923F55C1
2 changed files with 15 additions and 1 deletions

View File

@ -62,7 +62,7 @@ getUser = (service, imageInfo) ->
return service.user ? imageInfo?.Config?.User ? ''
getWorkingDir = (service, imageInfo) ->
return service.workingDir ? imageInfo?.Config?.WorkingDir ? ''
return (service.workingDir ? imageInfo?.Config?.WorkingDir ? '').replace(/(^.+)\/$/, '$1')
buildHealthcheckTest = (test) ->
if _.isString(test)

View File

@ -147,3 +147,17 @@ describe 'compose/service.cofee', ->
expect(makeComposeServiceWithLimit('64gb').memLimit).to.equal(68719476736)
expect(makeComposeServiceWithLimit('64Gb').memLimit).to.equal(68719476736)
describe 'getWorkingDir', ->
makeComposeServiceWithWorkdir = (workdir) ->
new Service(
appId: 123456,
serviceId: 123456,
serviceName: 'foobar'
workingDir: workdir
)
it 'should remove a trailing slash', ->
expect(makeComposeServiceWithWorkdir('/usr/src/app/').workingDir).to.equal('/usr/src/app')
expect(makeComposeServiceWithWorkdir('/').workingDir).to.equal('/')
expect(makeComposeServiceWithWorkdir('/usr/src/app').workingDir).to.equal('/usr/src/app')
expect(makeComposeServiceWithWorkdir('').workingDir).to.equal('')