Skip to content

Commit

Permalink
Add support for linking to Docker entrypoint files (OctoLinker#511)
Browse files Browse the repository at this point in the history
Hey OctoLinker team, thank you for the great extension and reviewing my PR. Looking forward to your feedback. :)

Adds support for linking to relative Docker entrypoint files to the Docker plugin using the relative file resolver.

Closes issue OctoLinker#431 

### Checklist:

- [X] If this PR is a new feature, please provide at least one example link

The ENTRYPOINT line in [docker-library/wordpress:php5.6/apache/Dockerfile@6a085d9#L59](https://github.com/docker-library/wordpress/blob/6a085d90853b8baffadbd3f0a41d6814a2513c11/php5.6/apache/Dockerfile#L59) should resolve to [docker-library/wordpress:php5.6/apache/docker-entrypoint.sh@6a085d9](https://github.com/docker-library/wordpress/blob/6a085d90853b8baffadbd3f0a41d6814a2513c11/php5.6/apache/docker-entrypoint.sh)

Official repo links (example: `
FROM php:5.6-apache` on line 1 in the same file) should still resolve to hub.docker.com

- [x] Make sure all of the significant new logic is covered by tests
  • Loading branch information
MatthewDG authored and stefanbuck committed Sep 5, 2018
1 parent 3da6100 commit 37b1356
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 14 deletions.
5 changes: 5 additions & 0 deletions e2e/fixtures/docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// @OctoLinkerResolve(https://hub.docker.com/_/php/)
FROM php:php:5.6-apache

// @OctoLinkerResolve(<root>/docker/docker-entrypoint.sh)
ENTRYPOINT ["docker-entrypoint.sh"]
Empty file.
4 changes: 4 additions & 0 deletions packages/helper-grammar-regex-collection/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ export const DOCKER_FROM = regex`
FROM \s (?<$1>[^\n]*)
`;

export const DOCKER_ENTRYPOINT = regex`
ENTRYPOINT \s \[${captureQuotedWord}\]
`;

export const VIM_PLUGIN = regex`
${diffSigns}
(
Expand Down
4 changes: 4 additions & 0 deletions packages/helper-grammar-regex-collection/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,10 @@ const fixtures = {
// 'FROM\nfoo',
],
},
DOCKER_ENTRYPOINT: {
valid: [['ENTRYPOINT ["foo-bar.sh"]', ['foo-bar.sh']]],
invalid: ['ENTRYPOINTfoobar'],
},
VIM_PLUGIN: {
valid: [
["Plugin 'VundleVim/Vundle.vim'", ['VundleVim/Vundle.vim']],
Expand Down
32 changes: 22 additions & 10 deletions packages/plugin-docker/__tests__/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,44 @@ describe('docker-image', () => {
const path = '/blob/path/dummy';

it('resolves foo to https://hub.docker.com/_/foo', () => {
expect(dockerImage.resolve(path, ['foo'])).toBe(
expect(dockerImage.resolve(path, ['foo'])).toEqual([
'{BASE_URL}/blob/path/foo',
'https://hub.docker.com/_/foo',
);
]);
});

it('resolves foo:1.2.3 to https://hub.docker.com/_/foo', () => {
expect(dockerImage.resolve(path, ['foo:1.2.3'])).toBe(
expect(dockerImage.resolve(path, ['foo:1.2.3'])).toEqual([
'{BASE_URL}/blob/path/foo:1.2.3',
'https://hub.docker.com/_/foo',
);
]);
});

it('resolves foo:1.2.3-alpha to https://hub.docker.com/_/foo', () => {
expect(dockerImage.resolve(path, ['foo:1.2.3-alpha'])).toBe(
expect(dockerImage.resolve(path, ['foo:1.2.3-alpha'])).toEqual([
'{BASE_URL}/blob/path/foo:1.2.3-alpha',
'https://hub.docker.com/_/foo',
);
]);
});

it('resolves foo/bar to https://hub.docker.com/r/foo/bar', () => {
expect(dockerImage.resolve(path, ['foo/bar'])).toBe(
expect(dockerImage.resolve(path, ['foo/bar'])).toEqual([
'{BASE_URL}/blob/path/foo/bar',
'https://hub.docker.com/r/foo/bar',
);
]);
});

it('resolves foo/bar:1.2.3 to https://hub.docker.com/r/foo/bar', () => {
expect(dockerImage.resolve(path, ['foo/bar:1.2.3'])).toBe(
expect(dockerImage.resolve(path, ['foo/bar:1.2.3'])).toEqual([
'{BASE_URL}/blob/path/foo/bar:1.2.3',
'https://hub.docker.com/r/foo/bar',
);
]);
});

it('resolves foobar.sh to "{BASE_URL}/blob/path/foobar.sh" ', () => {
expect(dockerImage.resolve(path, ['foobar.sh'])).toEqual([
'{BASE_URL}/blob/path/foobar.sh',
'https://hub.docker.com/_/foobar.sh',
]);
});
});
13 changes: 10 additions & 3 deletions packages/plugin-docker/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import { DOCKER_FROM } from '@octolinker/helper-grammar-regex-collection';
import {
DOCKER_FROM,
DOCKER_ENTRYPOINT,
} from '@octolinker/helper-grammar-regex-collection';
import relativeFile from '@octolinker/resolver-relative-file';

export default {
name: 'Docker',
Expand All @@ -11,7 +15,10 @@ export default {
isOffical = false;
}

return `https://hub.docker.com/${isOffical ? '_' : 'r'}/${imageName}`;
return [
relativeFile({ path, target }),
`https://hub.docker.com/${isOffical ? '_' : 'r'}/${imageName}`,
];
},

getPattern() {
Expand All @@ -22,6 +29,6 @@ export default {
},

getLinkRegexes() {
return DOCKER_FROM;
return [DOCKER_FROM, DOCKER_ENTRYPOINT];
},
};
3 changes: 2 additions & 1 deletion packages/plugin-docker/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"license": "MIT",
"main": "./index.js",
"dependencies": {
"@octolinker/helper-grammar-regex-collection": "1.0.0"
"@octolinker/helper-grammar-regex-collection": "1.0.0",
"@octolinker/resolver-relative-file": "1.0.0"
}
}

0 comments on commit 37b1356

Please sign in to comment.