Skip to content

Commit

Permalink
Merge pull request #289 from zeeke/avoid-sleep
Browse files Browse the repository at this point in the history
Optionally avoid sleeping in `entrypoint.sh`
  • Loading branch information
adrianchiris authored Feb 6, 2024
2 parents 07ecbf9 + c9c49b5 commit 8136d36
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 0 deletions.
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,9 @@ fmt: ; $(info Running gofmt...) @ ## Run gofmt on all source files
image: | $(BASE) ; $(info Building Docker image...) @ ## Build SR-IOV CNI docker image
@$(IMAGE_BUILDER) build -t $(TAG) -f $(DOCKERFILE) $(CURDIR) $(DOCKERARGS)

test-image: image
$Q $(BASE)/images/image_test.sh $(IMAGE_BUILDER) $(TAG)

# Misc

.PHONY: deps-update
Expand Down
9 changes: 9 additions & 0 deletions images/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ set -e
# Set known directories.
CNI_BIN_DIR="/host/opt/cni/bin"
SRIOV_BIN_FILE="/usr/bin/sriov"
NO_SLEEP=0

# Give help text for parameters.
usage()
Expand All @@ -18,6 +19,7 @@ usage()
printf "\t-h --help\n"
printf "\t--cni-bin-dir=%s\n" "$CNI_BIN_DIR"
printf "\t--sriov-bin-file=%s\n" "$SRIOV_BIN_FILE"
printf "\t--no-sleep\n"
}

# Parse parameters given as arguments to this script.
Expand All @@ -35,6 +37,9 @@ while [ "$1" != "" ]; do
--sriov-bin-file)
SRIOV_BIN_FILE=$VALUE
;;
--no-sleep)
NO_SLEEP=1
;;
*)
/bin/echo "ERROR: unknown parameter \"$PARAM\""
usage
Expand All @@ -57,6 +62,10 @@ done
# Copy file into proper place.
cp -f "$SRIOV_BIN_FILE" "$CNI_BIN_DIR"

if [ $NO_SLEEP -eq 1 ]; then
exit 0
fi

echo "Entering sleep... (success)"
trap : TERM INT

Expand Down
22 changes: 22 additions & 0 deletions images/image_test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/bin/sh

set -x

OCI_RUNTIME=$1
IMAGE_UNDER_TEST=$2

OUTPUT_DIR=$(mktemp -d)

"${OCI_RUNTIME}" run -v "${OUTPUT_DIR}:/out" "${IMAGE_UNDER_TEST}" --cni-bin-dir=/out --no-sleep

if [ ! -e "${OUTPUT_DIR}/sriov" ]; then
echo "Output file ${OUTPUT_DIR}/sriov not found"
exit 1
fi

if [ ! -s "${OUTPUT_DIR}/sriov" ]; then
echo "Output file ${OUTPUT_DIR}/sriov is empty"
exit 1
fi

exit 0

0 comments on commit 8136d36

Please # to comment.