Skip to content

Commit

Permalink
Release 1.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
sgreben committed Oct 26, 2019
1 parent 9729d4b commit 2688046
Show file tree
Hide file tree
Showing 12 changed files with 410 additions and 254 deletions.
9 changes: 8 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
VERSION = 0.3.5
VERSION = 1.0.0

APP := dockerfile-json
PACKAGES := $(shell go list -f {{.Dir}} ./...)
Expand All @@ -21,6 +21,13 @@ release: README.md zip

README.md:
go get github.com/keilerkonzept/$(APP) && <README.template.md subst \
EXAMPLE_6="$$($(APP) --expand-build-args=false --jsonpath=$$..BaseName examples/Dockerfile.3 | jq .)" \
EXAMPLE_5="$$($(APP) --jsonpath=$$..BaseName examples/Dockerfile.3 | jq .)" \
EXAMPLE_4="$$($(APP) --jsonpath=$$..Image --build-arg ALPINE_TAG=hello-world examples/Dockerfile.3 | jq .)" \
EXAMPLE_3B="$$($(APP) --jsonpath=$$..Image --jsonpath-raw examples/Dockerfile.3)" \
EXAMPLE_3A="$$($(APP) --jsonpath=$$..Image examples/Dockerfile.3 | jq .)" \
EXAMPLE_2="$$($(APP) --jsonpath=$$..As examples/Dockerfile.2 | jq .)" \
EXAMPLE_1="$$($(APP) examples/Dockerfile.1 | jq .)" \
VERSION="$(VERSION)" APP="$(APP)" USAGE="$$($(APP) -h 2>&1)" > README.md

zip: release/$(APP)_$(VERSION)_osx_x86_64.tar.gz release/$(APP)_$(VERSION)_windows_x86_64.zip release/$(APP)_$(VERSION)_linux_x86_64.tar.gz release/$(APP)_$(VERSION)_osx_x86_32.tar.gz release/$(APP)_$(VERSION)_windows_x86_32.zip release/$(APP)_$(VERSION)_linux_x86_32.tar.gz release/$(APP)_$(VERSION)_linux_arm64.tar.gz
Expand Down
104 changes: 65 additions & 39 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,17 @@ Or [download the binary for your platform](https://github.com/keilerkonzept/dock
### CLI

```text
dockerfile-json
dockerfile-json [PATHS...]
Usage of dockerfile-json:
-build-arg value
a key/value pair KEY[=VALUE]
-expand-build-args
expand build args (default true)
-jsonpath string
select parts of the output using JSONPath (https://goessner.net/articles/JsonPath)
-jsonpath-raw
when using JSONPath, output raw strings, not JSON values
-quiet
suppress log output (stderr)
```
Expand Down Expand Up @@ -69,68 +73,77 @@ $ dockerfile-json Dockerfile | jq .
"MetaArgs": [
{
"Key": "ALPINE_TAG",
"DefaultValue": "3.10",
"ProvidedValue": null,
"Value": "3.10"
}
],
"Stages": [
{
"Name": "build",
"BaseName": "alpine:3.10",
"SourceCode": "FROM alpine:$ALPINE_TAG AS build",
"SourceCode": "FROM alpine:${ALPINE_TAG} AS build",
"Platform": "",
"As": "build",
"From": {
"Image": "alpine:3.10"
},
"Commands": [
{
"CmdLine": [
"echo \"Hello world\" > abc"
],
"Name": "run",
"Command": {
"CmdLine": [
"echo \"Hello world\" > abc"
],
"PrependShell": true
}
"PrependShell": true
}
]
},
{
"Name": "test",
"BaseName": "build",
"SourceCode": "FROM build AS test",
"FromStage": true,
"FromStageIndex": 0,
"Platform": "",
"As": "test",
"From": {
"Stage": {
"Named": "build",
"Index": 0
}
},
"Commands": [
{
"CmdLine": [
"echo \"foo\" > bar"
],
"Name": "run",
"Command": {
"CmdLine": [
"echo \"foo\" > bar"
],
"PrependShell": true
}
"PrependShell": true
}
]
},
{
"Name": "",
"BaseName": "scratch",
"SourceCode": "FROM scratch",
"FromScratch": true,
"Platform": "",
"From": {
"Scratch": true
},
"Commands": [
{
"Chown": "nobody:nobody",
"From": "build",
"Name": "copy",
"Command": {
"SourcesAndDest": [
"abc",
"."
],
"From": "",
"Chown": "nobody:nobody"
}
"SourcesAndDest": [
"abc",
"."
]
},
{
"CmdLine": [
"echo"
],
"Name": "cmd",
"Command": {
"CmdLine": [
"echo"
],
"PrependShell": false
}
"PrependShell": false
}
]
}
Expand All @@ -153,7 +166,7 @@ FROM openjdk:jre-alpine
```

```sh
$ dockerfile-json Dockerfile | jq '.Stages[] | .Name | select(.)'
$ dockerfile-json --jsonpath=..As Dockerfile
```
```json
"build"
Expand All @@ -179,19 +192,32 @@ FROM $APP_BASE

#### Expand build args, omit stage aliases and `scratch`

Using `jq`:
```sh
$ dockerfile-json Dockerfile |
jq '.Stages[] | select((.FromStage or .FromScratch)|not) | .BaseName'
jq '.Stages[] | select(.From | .Stage or .Scratch | not) | .BaseName'
```
Using `--jsonpath`:
```sh

$ dockerfile-json --jsonpath=..Image Dockerfile
```
```json
"alpine:3.10"
```

Using `--jsonpath`, `--jsonpath-raw` output:
```sh
$ dockerfile-json --jsonpath=..Image --jsonpath-raw Dockerfile
```
```json
alpine:3.10
```

#### Set build args, omit stage aliases and `scratch`

```sh
$ dockerfile-json --build-arg ALPINE_TAG=hello-world Dockerfile |
jq '.Stages[] | select((.FromStage or .FromScratch)|not) | .BaseName'
$ dockerfile-json --build-arg ALPINE_TAG=hello-world --jsonpath=..Image Dockerfile
```
```json
"alpine:hello-world"
Expand All @@ -200,7 +226,7 @@ $ dockerfile-json --build-arg ALPINE_TAG=hello-world Dockerfile |
#### Expand build args, include all base names

```sh
$ dockerfile-json Dockerfile | jq '.Stages[] | .BaseName'
$ dockerfile-json --jsonpath=..BaseName Dockerfile
```
```json
"alpine:3.10"
Expand All @@ -211,10 +237,10 @@ $ dockerfile-json Dockerfile | jq '.Stages[] | .BaseName'
#### Ignore build args, include all base names

```sh
$ dockerfile-json --expand-build-args=false Dockerfile | jq '.Stages[] | .BaseName'
$ dockerfile-json --expand-build-args=false --jsonpath=..BaseName Dockerfile
```
```json
"alpine:$ALPINE_TAG"
"alpine:${ALPINE_TAG}"
"build"
"$APP_BASE"
"${APP_BASE}"
```
114 changes: 26 additions & 88 deletions README.template.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ Or [download the binary for your platform](https://github.com/keilerkonzept/${AP
### CLI

```text
${APP}
${APP} [PATHS...]
${USAGE}
```
Expand Down Expand Up @@ -59,77 +59,7 @@ CMD ["echo"]
$ dockerfile-json Dockerfile | jq .
```
```json
{
"MetaArgs": [
{
"Key": "ALPINE_TAG",
"Value": "3.10"
}
],
"Stages": [
{
"Name": "build",
"BaseName": "alpine:3.10",
"SourceCode": "FROM alpine:${ALPINE_TAG} AS build",
"Commands": [
{
"Name": "run",
"Command": {
"CmdLine": [
"echo \"Hello world\" > abc"
],
"PrependShell": true
}
}
]
},
{
"Name": "test",
"BaseName": "build",
"SourceCode": "FROM build AS test",
"FromStage": true,
"FromStageIndex": 0,
"Commands": [
{
"Name": "run",
"Command": {
"CmdLine": [
"echo \"foo\" > bar"
],
"PrependShell": true
}
}
]
},
{
"BaseName": "scratch",
"SourceCode": "FROM scratch",
"FromScratch": true,
"Commands": [
{
"Name": "copy",
"Command": {
"SourcesAndDest": [
"abc",
"."
],
"From": "",
"Chown": "nobody:nobody"
}
},
{
"Name": "cmd",
"Command": {
"CmdLine": [
"echo"
],
"PrependShell": false
}
}
]
}
]
}
${EXAMPLE_1}
```

### Extract build stage names
Expand All @@ -147,11 +77,10 @@ FROM openjdk:jre-alpine
```

```sh
$ dockerfile-json Dockerfile | jq '.Stages[] | .Name | select(.)'
$ dockerfile-json --jsonpath=..As Dockerfile
```
```json
"build"
"test"
${EXAMPLE_2}
```

### Extract base images
Expand All @@ -173,42 +102,51 @@ FROM ${APP_BASE}

#### Expand build args, omit stage aliases and `scratch`

Using `jq`:
```sh
$ dockerfile-json Dockerfile |
jq '.Stages[] | select((.FromStage or .FromScratch)|not) | .BaseName'
jq '.Stages[] | select(.From | .Stage or .Scratch | not) | .BaseName'
```
Using `--jsonpath`:
```sh

$ dockerfile-json --jsonpath=..Image Dockerfile
```
```json
${EXAMPLE_3A}
```

Using `--jsonpath`, `--jsonpath-raw` output:
```sh
$ dockerfile-json --jsonpath=..Image --jsonpath-raw Dockerfile
```
```json
"alpine:3.10"
${EXAMPLE_3B}
```

#### Set build args, omit stage aliases and `scratch`

```sh
$ dockerfile-json --build-arg ALPINE_TAG=hello-world Dockerfile |
jq '.Stages[] | select((.FromStage or .FromScratch)|not) | .BaseName'
$ dockerfile-json --build-arg ALPINE_TAG=hello-world --jsonpath=..Image Dockerfile
```
```json
"alpine:hello-world"
${EXAMPLE_4}
```

#### Expand build args, include all base names

```sh
$ dockerfile-json Dockerfile | jq '.Stages[] | .BaseName'
$ dockerfile-json --jsonpath=..BaseName Dockerfile
```
```json
"alpine:3.10"
"build"
"scratch"
${EXAMPLE_5}
```

#### Ignore build args, include all base names

```sh
$ dockerfile-json --expand-build-args=false Dockerfile | jq '.Stages[] | .BaseName'
$ dockerfile-json --expand-build-args=false --jsonpath=..BaseName Dockerfile
```
```json
"alpine:${ALPINE_TAG}"
"build"
"${APP_BASE}"
${EXAMPLE_6}
```
11 changes: 11 additions & 0 deletions examples/Dockerfile.1
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
ARG ALPINE_TAG=3.10

FROM alpine:${ALPINE_TAG} AS build
RUN echo "Hello world" > abc

FROM build AS test
RUN echo "foo" > bar

FROM scratch
COPY --from=build --chown=nobody:nobody abc .
CMD ["echo"]
Loading

0 comments on commit 2688046

Please sign in to comment.