mirror of
https://github.com/renovatebot/renovate.git
synced 2025-01-11 14:36:25 +00:00
feat(docker): add depType for multi-stage Dockerfiles (#3385)
This commit is contained in:
parent
940d3c4721
commit
3e788c783a
3 changed files with 81 additions and 0 deletions
|
@ -102,5 +102,7 @@ function extractPackageFile(content) {
|
|||
if (!deps.length) {
|
||||
return null;
|
||||
}
|
||||
for (const d of deps) d.depType = 'stage';
|
||||
deps[deps.length - 1].depType = 'final';
|
||||
return { deps };
|
||||
}
|
||||
|
|
|
@ -1,5 +1,47 @@
|
|||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`lib/manager/dockerfile/extract extractPackageFile() detects ["stage"] and ["final"] deps of docker multi-stage build. 1`] = `
|
||||
Array [
|
||||
Object {
|
||||
"commitMessageTopic": "Node.js",
|
||||
"currentDepTag": "node:8.15.1-alpine",
|
||||
"currentDigest": undefined,
|
||||
"currentFrom": "node:8.15.1-alpine",
|
||||
"currentValue": "8.15.1-alpine",
|
||||
"datasource": "docker",
|
||||
"depName": "node",
|
||||
"depType": "stage",
|
||||
"fromPrefix": "FROM",
|
||||
"fromSuffix": "as skippedfrom",
|
||||
"lineNumber": 0,
|
||||
},
|
||||
Object {
|
||||
"currentDepTag": "golang:1.7.3",
|
||||
"currentDigest": undefined,
|
||||
"currentFrom": "golang:1.7.3",
|
||||
"currentValue": "1.7.3",
|
||||
"datasource": "docker",
|
||||
"depName": "golang",
|
||||
"depType": "stage",
|
||||
"fromPrefix": "FROM",
|
||||
"fromSuffix": "as builder",
|
||||
"lineNumber": 1,
|
||||
},
|
||||
Object {
|
||||
"currentDepTag": "alpine:latest",
|
||||
"currentDigest": undefined,
|
||||
"currentFrom": "alpine:latest",
|
||||
"currentValue": "latest",
|
||||
"datasource": "docker",
|
||||
"depName": "alpine",
|
||||
"depType": "final",
|
||||
"fromPrefix": "FROM",
|
||||
"fromSuffix": "",
|
||||
"lineNumber": 9,
|
||||
},
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`lib/manager/dockerfile/extract extractPackageFile() extracts images on adjacent lines 1`] = `
|
||||
Array [
|
||||
Object {
|
||||
|
@ -10,6 +52,7 @@ Array [
|
|||
"currentValue": "8.11.3-alpine",
|
||||
"datasource": "docker",
|
||||
"depName": "node",
|
||||
"depType": "stage",
|
||||
"fromPrefix": "FROM",
|
||||
"fromSuffix": "AS node",
|
||||
"lineNumber": 2,
|
||||
|
@ -21,6 +64,7 @@ Array [
|
|||
"currentValue": "1.1.1",
|
||||
"datasource": "docker",
|
||||
"depName": "buildkite/puppeteer",
|
||||
"depType": "final",
|
||||
"fromPrefix": "FROM",
|
||||
"fromSuffix": "AS puppeteer",
|
||||
"lineNumber": 3,
|
||||
|
@ -38,6 +82,7 @@ Array [
|
|||
"currentValue": "6.12.3",
|
||||
"datasource": "docker",
|
||||
"depName": "node",
|
||||
"depType": "stage",
|
||||
"fromPrefix": "FROM",
|
||||
"fromSuffix": "as frontend",
|
||||
"lineNumber": 0,
|
||||
|
@ -49,6 +94,7 @@ Array [
|
|||
"currentValue": "3.6-slim",
|
||||
"datasource": "docker",
|
||||
"depName": "python",
|
||||
"depType": "final",
|
||||
"fromPrefix": "FROM",
|
||||
"fromSuffix": "",
|
||||
"lineNumber": 4,
|
||||
|
@ -65,6 +111,7 @@ Array [
|
|||
"currentValue": "v0.11.0",
|
||||
"datasource": "docker",
|
||||
"depName": "gcr.io/k8s-skaffold/skaffold",
|
||||
"depType": "final",
|
||||
"fromPrefix": "COPY --from=",
|
||||
"fromSuffix": "/usr/bin/skaffold /usr/bin/skaffold",
|
||||
"lineNumber": 1,
|
||||
|
@ -81,6 +128,7 @@ Array [
|
|||
"currentValue": "5005/node",
|
||||
"datasource": "docker",
|
||||
"depName": "registry.allmine.info",
|
||||
"depType": "final",
|
||||
"fromPrefix": "FROM",
|
||||
"fromSuffix": "",
|
||||
"lineNumber": 0,
|
||||
|
@ -97,6 +145,7 @@ Array [
|
|||
"currentValue": undefined,
|
||||
"datasource": "docker",
|
||||
"depName": "calico/node",
|
||||
"depType": "final",
|
||||
"fromPrefix": "FROM",
|
||||
"fromSuffix": "",
|
||||
"lineNumber": 0,
|
||||
|
@ -114,6 +163,7 @@ Array [
|
|||
"currentValue": undefined,
|
||||
"datasource": "docker",
|
||||
"depName": "node",
|
||||
"depType": "final",
|
||||
"fromPrefix": "FROM",
|
||||
"fromSuffix": "",
|
||||
"lineNumber": 3,
|
||||
|
@ -131,6 +181,7 @@ Array [
|
|||
"currentValue": "8",
|
||||
"datasource": "docker",
|
||||
"depName": "registry2.something.info/node",
|
||||
"depType": "final",
|
||||
"fromPrefix": "FROM",
|
||||
"fromSuffix": "",
|
||||
"lineNumber": 0,
|
||||
|
@ -148,6 +199,7 @@ Array [
|
|||
"currentValue": "8-alpine",
|
||||
"datasource": "docker",
|
||||
"depName": "registry2.something.info/node",
|
||||
"depType": "final",
|
||||
"fromPrefix": "FROM",
|
||||
"fromSuffix": "",
|
||||
"lineNumber": 0,
|
||||
|
@ -165,6 +217,7 @@ Array [
|
|||
"currentValue": "8",
|
||||
"datasource": "docker",
|
||||
"depName": "registry2.something.info/someaccount/node",
|
||||
"depType": "final",
|
||||
"fromPrefix": "FROM",
|
||||
"fromSuffix": "",
|
||||
"lineNumber": 0,
|
||||
|
@ -181,6 +234,7 @@ Array [
|
|||
"currentValue": "5005/node",
|
||||
"datasource": "docker",
|
||||
"depName": "registry2.something.info",
|
||||
"depType": "final",
|
||||
"fromPrefix": "FROM",
|
||||
"fromSuffix": "",
|
||||
"lineNumber": 0,
|
||||
|
@ -198,6 +252,7 @@ Array [
|
|||
"currentValue": undefined,
|
||||
"datasource": "docker",
|
||||
"depName": "node",
|
||||
"depType": "final",
|
||||
"fromPrefix": "FROM",
|
||||
"fromSuffix": "",
|
||||
"lineNumber": 0,
|
||||
|
@ -215,6 +270,7 @@ Array [
|
|||
"currentValue": "8.9.0-alpine",
|
||||
"datasource": "docker",
|
||||
"depName": "node",
|
||||
"depType": "final",
|
||||
"fromPrefix": "FROM",
|
||||
"fromSuffix": "as base",
|
||||
"lineNumber": 0,
|
||||
|
@ -232,6 +288,7 @@ Array [
|
|||
"currentValue": undefined,
|
||||
"datasource": "docker",
|
||||
"depName": "node",
|
||||
"depType": "final",
|
||||
"fromPrefix": "FROM",
|
||||
"fromSuffix": "",
|
||||
"lineNumber": 0,
|
||||
|
@ -249,6 +306,7 @@ Array [
|
|||
"currentValue": "8",
|
||||
"datasource": "docker",
|
||||
"depName": "mynamespace/node",
|
||||
"depType": "final",
|
||||
"fromPrefix": "FROM",
|
||||
"fromSuffix": "",
|
||||
"lineNumber": 0,
|
||||
|
@ -266,6 +324,7 @@ Array [
|
|||
"currentValue": "8.9.0-alpine",
|
||||
"datasource": "docker",
|
||||
"depName": "node",
|
||||
"depType": "final",
|
||||
"fromPrefix": "FROM",
|
||||
"fromSuffix": "",
|
||||
"lineNumber": 0,
|
||||
|
@ -283,6 +342,7 @@ Array [
|
|||
"currentValue": "8.9.0",
|
||||
"datasource": "docker",
|
||||
"depName": "node",
|
||||
"depType": "final",
|
||||
"fromPrefix": "FROM",
|
||||
"fromSuffix": "",
|
||||
"lineNumber": 0,
|
||||
|
@ -300,6 +360,7 @@ Array [
|
|||
"currentValue": undefined,
|
||||
"datasource": "docker",
|
||||
"depName": "node",
|
||||
"depType": "final",
|
||||
"fromPrefix": "From",
|
||||
"fromSuffix": "",
|
||||
"lineNumber": 0,
|
||||
|
@ -317,6 +378,7 @@ Array [
|
|||
"currentValue": "6.12.3",
|
||||
"datasource": "docker",
|
||||
"depName": "node",
|
||||
"depType": "final",
|
||||
"fromPrefix": "FROM",
|
||||
"fromSuffix": "as frontend",
|
||||
"lineNumber": 0,
|
||||
|
@ -334,6 +396,7 @@ Array [
|
|||
"currentValue": "6.12.3",
|
||||
"datasource": "docker",
|
||||
"depName": "node",
|
||||
"depType": "final",
|
||||
"fromPrefix": "FROM",
|
||||
"fromSuffix": "as frontend",
|
||||
"lineNumber": 0,
|
||||
|
@ -351,6 +414,7 @@ Array [
|
|||
"currentValue": "6.12.3",
|
||||
"datasource": "docker",
|
||||
"depName": "node",
|
||||
"depType": "final",
|
||||
"fromPrefix": "FROM",
|
||||
"fromSuffix": "as frontend",
|
||||
"lineNumber": 0,
|
||||
|
|
|
@ -137,6 +137,21 @@ describe('lib/manager/dockerfile/extract', () => {
|
|||
expect(res).toMatchSnapshot();
|
||||
expect(res).toHaveLength(1);
|
||||
});
|
||||
it('detects ["stage"] and ["final"] deps of docker multi-stage build.', () => {
|
||||
const res = extractPackageFile(
|
||||
'FROM node:8.15.1-alpine as skippedfrom\nFROM golang:1.7.3 as builder\n\n# comment\nWORKDIR /go/src/github.com/alexellis/href-counter/\nRUN go get -d -v golang.org/x/net/html \nCOPY app.go .\nRUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o app .\n\nFROM alpine:latest \nRUN apk --no-cache add ca-certificates\nWORKDIR /root/\nCOPY --from=builder /go/src/github.com/alexellis/href-counter/app .\nCMD ["./app"]\n',
|
||||
config
|
||||
).deps;
|
||||
expect(res).toMatchSnapshot();
|
||||
const passed = [
|
||||
res[2].depType === 'final',
|
||||
res[1].depType === 'stage',
|
||||
res[0].depType === 'stage',
|
||||
res[2].lineNumber > res[1].lineNumber,
|
||||
res[2].lineNumber > res[0].lineNumber,
|
||||
].every(Boolean);
|
||||
expect(passed).toBe(true);
|
||||
});
|
||||
it('extracts images on adjacent lines', () => {
|
||||
const res = extractPackageFile(d1, config).deps;
|
||||
expect(res).toMatchSnapshot();
|
||||
|
|
Loading…
Reference in a new issue