Skip to content

Commit 4491005

Browse files
authored
Fix snyk container run on a Dockerfile with a custom name (#46)
### Description There was an issue when user tries to run `snyk-container` hook with a dockerfile with a custom name, e.g. `Containerfile` or `arm64.dockerfile`, etc.
1 parent 9b618ed commit 4491005

1 file changed

Lines changed: 6 additions & 6 deletions

File tree

hooks/snyk-container.sh

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ container_build() {
1313
tag="$1"
1414
path="$2"
1515
if command -v docker &> /dev/null; then
16-
docker build -t "$tag" "$path"
16+
docker build -t "$tag" -f "$path" .
1717
elif command -v podman &> /dev/null; then
18-
podman build -t "$tag" "$path"
18+
podman build -t "$tag" -f "$path" .
1919
else
2020
echo "$prefix docker or podman are not found. Please install one of these tools and try again"
2121
exit 1
@@ -37,10 +37,10 @@ container_rmi() {
3737
snyk_args=()
3838
dockerfiles=()
3939
for arg in "$@"; do
40-
if [[ $arg == *Dockerfile ]]; then
41-
dockerfiles+=("$arg")
42-
else
40+
if [ "${arg#-}" != "$arg" ]; then
4341
snyk_args+=("$arg")
42+
else
43+
dockerfiles+=("$arg")
4444
fi
4545
done
4646

@@ -53,7 +53,7 @@ for file_path in "${dockerfiles[@]}"; do
5353
echo ""
5454
fi
5555
printf "%s Building %s from %s\n\n" "$prefix" "$image" "$file_path"
56-
container_build "$image" "$(echo "$file_path" | rev | cut -d'/' -f2- | rev)"
56+
container_build "$image" "$file_path"
5757
printf "\n%s Testing %s\n" "$prefix" "$image"
5858
snyk container test "$image" "--file=$file_path" "${snyk_args[*]}"
5959
printf "\n%s Removing %s" "$prefix" "$image"

0 commit comments

Comments
 (0)