Implement #Image

Signed-off-by: guillaume <guillaume.derouville@gmail.com>
This commit is contained in:
guillaume
2021-10-21 19:19:06 +02:00
parent aac70c2f17
commit 701be92dad
5 changed files with 103 additions and 31 deletions

59
stdlib/trivy/image.cue Normal file
View File

@@ -0,0 +1,59 @@
package trivy
import (
"encoding/json"
"alpha.dagger.io/os"
)
// Scan an Image
#Image: {
// Trivy configuration
config: #Config
// Image source (AWS, GCP, Docker Hub, Self hosted)
source: string
// Trivy Image arguments
args: [arg=string]: string
// Enforce args best practices
args: {
"--exit-code": *"1" | string
"--severity": *"HIGH,CRITICAL" | string
"--format": *"table" | string
"--ignore-unfixed": *"true" | string
}
ctr: os.#Container & {
image: #CLI & {
"config": config
}
shell: {
path: "/bin/bash"
args: ["--noprofile", "--norc", "-eo", "pipefail", "-c"]
}
command: #"""
trivyArgs="$(
echo "$ARGS" |
jq -c '
to_entries |
map(.key + " " + (.value | tostring) + " ") |
add
')"
trivy image "$trivyArgs" "$SOURCE"
echo "$SOURCE" > /ref
"""#
env: ARGS: json.Marshal(args)
env: SOURCE: source
}
// Export ref to create dependency (wait for the check to finish)
ref: {
os.#File & {
from: ctr
path: "/ref"
}
}.contents @dagger(output)
}