-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
rely on dockerfil but support multiple args and ubuntu
- Loading branch information
1 parent
be7ace4
commit 47a2fc3
Showing
13 changed files
with
166 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
FROM alpine:latest | ||
|
||
RUN apk add curl |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
FROM alpine:latest | ||
|
||
RUN apk-add curl |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
FROM debian:bullseye-slim | ||
|
||
RUN apt-get install |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,18 @@ | ||
{ | ||
"image": "alpine", | ||
"dependencies": [ | ||
{ | ||
"name": "git", | ||
"version": "2.34.1-r0" | ||
}, | ||
{ | ||
"name": "make", | ||
"version": "4.3-r0" | ||
}, | ||
{ | ||
"name": "protoc", | ||
"version": "3.18.1-r1" | ||
}, | ||
{ | ||
"name": "protobuf-dev", | ||
"version": "3.18.1-r1" | ||
} | ||
] | ||
} | ||
[ | ||
{ | ||
"name": "git", | ||
"version": "2.34.1-r0" | ||
}, | ||
{ | ||
"name": "make", | ||
"version": "4.3-r0" | ||
}, | ||
{ | ||
"name": "protoc", | ||
"version": "3.18.1-r1" | ||
}, | ||
{ | ||
"name": "protobuf-dev", | ||
"version": "3.18.1-r1" | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import {test, expect} from '@jest/globals' | ||
import * as path from 'path' | ||
import {load} from '../src/dockerfile' | ||
import {AlpineImage, DebImage} from '../src/image' | ||
|
||
test('load invalid dockerfile', () => { | ||
let dockerfilePath = path.join(__dirname, 'data', 'InvalidDockerfile') | ||
function loadInvalid() { | ||
load(dockerfilePath) | ||
} | ||
expect(loadInvalid).toThrowError('Unable to extract image from Dockerfile') | ||
}) | ||
|
||
test('load alpine dockerfile', () => { | ||
const dockerfilePath = path.join(__dirname, 'data', 'Dockerfile') | ||
const dockerfile = load(dockerfilePath) | ||
expect(dockerfile).toBeInstanceOf(AlpineImage) | ||
expect(dockerfile.name).toBe('alpine:latest') | ||
}) | ||
|
||
test('load debian dockerfile', () => { | ||
const dockerfilePath = path.join(__dirname, 'data', 'debianDockerfile') | ||
const dockerfile = load(dockerfilePath) | ||
expect(dockerfile).toBeInstanceOf(DebImage) | ||
expect(dockerfile.name).toBe('debian:bullseye-slim') | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import * as image from './image' | ||
import fs from 'fs' | ||
|
||
export function load(dockerfile: string): image.Image { | ||
const content = fs.readFileSync(dockerfile).toString('utf-8') | ||
return extract_docker_image(content) | ||
} | ||
|
||
function extract_docker_image(dockerfile_content: string): image.Image { | ||
let imageName = '' | ||
const dockerfileLines = dockerfile_content.split('\n') | ||
for (const line of dockerfileLines) { | ||
if (line.includes('FROM')) { | ||
imageName = line.split(' ')[1].trim() | ||
} | ||
if (line.includes('apk add') || line.includes('apt-get install')) { | ||
return image.factory(imageName) | ||
} | ||
} | ||
throw Error('Unable to extract image from Dockerfile') | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters