mirror of
https://github.com/linuxkit/linuxkit.git
synced 2025-09-10 19:29:46 +00:00
validate yaml for extraneous fields in pkg build
Signed-off-by: Avi Deitcher <avi@deitcher.net>
This commit is contained in:
committed by
Avi Deitcher
parent
9da6903609
commit
358803fcc7
@@ -1,3 +1,4 @@
|
|||||||
image: memlogd
|
image: memlogd
|
||||||
binds:
|
config:
|
||||||
|
binds:
|
||||||
- /var/run:/var/run
|
- /var/run:/var/run
|
||||||
|
@@ -10,7 +10,7 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"text/template"
|
"text/template"
|
||||||
|
|
||||||
"gopkg.in/yaml.v2"
|
"gopkg.in/yaml.v3"
|
||||||
|
|
||||||
"github.com/linuxkit/linuxkit/src/cmd/linuxkit/moby"
|
"github.com/linuxkit/linuxkit/src/cmd/linuxkit/moby"
|
||||||
"github.com/linuxkit/linuxkit/src/cmd/linuxkit/util"
|
"github.com/linuxkit/linuxkit/src/cmd/linuxkit/util"
|
||||||
@@ -157,7 +157,9 @@ func NewFromConfig(cfg PkglibConfig, args ...string) ([]Pkg, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := yaml.Unmarshal(b, &pi); err != nil {
|
dec := yaml.NewDecoder(bytes.NewReader(b))
|
||||||
|
dec.KnownFields(true)
|
||||||
|
if err := dec.Decode(&pi); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
2
test/cases/000_build/090_validate_build_yaml/Dockerfile
Normal file
2
test/cases/000_build/090_validate_build_yaml/Dockerfile
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
FROM alpine:3.22
|
||||||
|
|
7
test/cases/000_build/090_validate_build_yaml/build.yml
Normal file
7
test/cases/000_build/090_validate_build_yaml/build.yml
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
image: build-args-test
|
||||||
|
network: true
|
||||||
|
arches:
|
||||||
|
- amd64
|
||||||
|
- arm64
|
||||||
|
# should error out on this unknown field
|
||||||
|
unknownField: "abc"
|
19
test/cases/000_build/090_validate_build_yaml/test.sh
Executable file
19
test/cases/000_build/090_validate_build_yaml/test.sh
Executable file
@@ -0,0 +1,19 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
# SUMMARY: Check that the build-args are correctly passed to Dockerfiles
|
||||||
|
# LABELS:
|
||||||
|
# REPEAT:
|
||||||
|
|
||||||
|
set -ex
|
||||||
|
|
||||||
|
# Source libraries. Uncomment if needed/defined
|
||||||
|
#. "${RT_LIB}"
|
||||||
|
. "${RT_PROJECT_ROOT}/_lib/lib.sh"
|
||||||
|
|
||||||
|
# Test code goes here
|
||||||
|
RESULT=$(linuxkit pkg build --force . 2>&1 || echo FAILED)
|
||||||
|
if [ "${RESULT}" != "FAILED" ]; then
|
||||||
|
echo "Build should have failed with invalid yaml, instead was ${RESULT}"
|
||||||
|
fi
|
||||||
|
echo "Summary: correctly detected invalid yaml"
|
||||||
|
|
||||||
|
exit 0
|
Reference in New Issue
Block a user