Skip to content

Commit

Permalink
fix(docker): honor absolute paths to docker file
Browse files Browse the repository at this point in the history
if the configured docker file option is an absolute path, it should be
used as. Previously this operation used path.join which does not respect
absolute paths. This fix makes used of path.resolve which will use an
absolute path if provided, else resolve the relative location
  • Loading branch information
esatterwhite committed Apr 9, 2021
1 parent 0d7d763 commit 723257b
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 5 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ name: Test + Release
on:
pull_request:
branches:
- master
- main

push:
branch:
- master
- main
jobs:
test:
name: Test Suite
Expand Down
5 changes: 3 additions & 2 deletions lib/docker/image.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,9 @@ class Image {
}

get dockerfile() {
return path.join(this.opts.cwd, this.opts.dockerfile)
return path.resolve(this.opts.cwd, this.opts.dockerfile)
}

arg(key, val) {
this.opts.args.set(key, val)
return this
Expand All @@ -82,7 +83,7 @@ class Image {
'build'
, '--quiet'
, '--tag'
, `${this.name}`
, this.name
, ...args
, '-f'
, this.dockerfile
Expand Down
2 changes: 1 addition & 1 deletion release.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

/* istanbul ignore file */
module.exports = {
branches: ['master']
branches: ['main']
, extends: '@codedependant/release-config-npm'
, changelogFile: 'CHANGELOG.md'
, changelogTitle: '# Semantic Release Docker'
Expand Down
43 changes: 43 additions & 0 deletions test/unit/docker/image.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,49 @@ test('Image', async (t) => {
tt.equal(img.context, '.', 'default image context')
img.context = __dirname
tt.equal(img.context, __dirname, 'context override')
tt.equal(
img.dockerfile
, path.join(__dirname, 'build', 'Dockerfile.test')
, 'docker file path'
)
})

t.test('dockerfile location resolution', async (t) => {
t.test('relative location', async (t) => {
const img = new docker.Image({
name: 'test'
, build_id: 'abc123'
, registry: 'quay.io'
, project: 'esatterwhite'
, name: 'test'
, dockerfile: '../../Dockerfile.test'
, cwd: path.join(__dirname, 'build')
, sha: 'hello'
})
t.equal(
img.dockerfile
, path.join(__dirname, '..', 'Dockerfile.test')
, 'docker file path'
)
})

t.test('absolute path', async (t) => {
const img = new docker.Image({
name: 'test'
, build_id: 'abc123'
, registry: 'quay.io'
, project: 'esatterwhite'
, name: 'test'
, dockerfile: '/var/opt/Dockerfile.test'
, cwd: path.join(__dirname, 'build')
, sha: 'hello'
})
t.equal(
img.dockerfile
, '/var/opt/Dockerfile.test'
, 'docker file path'
)
})
})

t.test('image#id()', async (tt) => {
Expand Down

0 comments on commit 723257b

Please sign in to comment.