Skip to content

Commit

Permalink
Add an alternative error message to curl command
Browse files Browse the repository at this point in the history
This work was triggered by KFLUXBUGS-1285.
User was trying to use dockerfile from an url, but it was failing for a
uknown reason and there was not any information as to why it might be
failing. It only showed the last successful log:

"Fetch Dockerfile from <URL>".

The true reason behind that failure is that the user was trying to fetch
the Dockerfile from an internal gitlab. To be able to connect to that
instance, a certificate issued by Red Hat is needed. In that particular
case it was not provided, so the curl command that was fetching the
Dockerfile failed "violently" instead of returning any http code.

When this failed (returned an error code) the task failed immediately due to our setup - we are using "set -e".
This commit makes sure that at least some message is returned.

The "exit 1" is also added. Without it, the code would now not try to
quit immediately, but would try to check the http response code and
would return nonsensical results such as:

"No Dockerfile is fetched. Server responds 000"

Signed-off-by: mkosiarc <mkosiarc@redhat.com>
  • Loading branch information
mkosiarc committed Oct 16, 2024
1 parent 04f1bc8 commit 9d1295e
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 8 deletions.
4 changes: 2 additions & 2 deletions task/buildah-oci-ta/0.2/buildah-oci-ta.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -260,12 +260,12 @@ spec:
elif echo "$DOCKERFILE" | grep -q "^https\?://"; then
echo "Fetch Dockerfile from $DOCKERFILE"
dockerfile_path=$(mktemp --suffix=-Dockerfile)
http_code=$(curl -s -L -w "%{http_code}" --output "$dockerfile_path" "$DOCKERFILE")
http_code=$(curl -s -L -w "%{http_code}" --output "$dockerfile_path" "$DOCKERFILE" || echo "Download of the Dockerfile failed due to connection issues" >&2 && exit 1)
if [ $http_code != 200 ]; then
echo "No Dockerfile is fetched. Server responds $http_code"
exit 1
fi
http_code=$(curl -s -L -w "%{http_code}" --output "$dockerfile_path.dockerignore.tmp" "$DOCKERFILE.dockerignore")
http_code=$(curl -s -L -w "%{http_code}" --output "$dockerfile_path.dockerignore.tmp" "$DOCKERFILE.dockerignore" || echo "Download of the .dockerignore file failed due to connection issues" >&2 && exit 1)
if [ $http_code = 200 ]; then
echo "Fetched .dockerignore from $DOCKERFILE.dockerignore"
mv "$dockerfile_path.dockerignore.tmp" $SOURCE_CODE_DIR/$CONTEXT/.dockerignore
Expand Down
4 changes: 2 additions & 2 deletions task/buildah-remote-oci-ta/0.2/buildah-remote-oci-ta.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -295,12 +295,12 @@ spec:
elif echo "$DOCKERFILE" | grep -q "^https\?://"; then
echo "Fetch Dockerfile from $DOCKERFILE"
dockerfile_path=$(mktemp --suffix=-Dockerfile)
http_code=$(curl -s -L -w "%{http_code}" --output "$dockerfile_path" "$DOCKERFILE")
http_code=$(curl -s -L -w "%{http_code}" --output "$dockerfile_path" "$DOCKERFILE" || echo "Download of the Dockerfile failed due to connection issues" >&2 && exit 1)
if [ $http_code != 200 ]; then
echo "No Dockerfile is fetched. Server responds $http_code"
exit 1
fi
http_code=$(curl -s -L -w "%{http_code}" --output "$dockerfile_path.dockerignore.tmp" "$DOCKERFILE.dockerignore")
http_code=$(curl -s -L -w "%{http_code}" --output "$dockerfile_path.dockerignore.tmp" "$DOCKERFILE.dockerignore" || echo "Download of the .dockerignore file failed due to connection issues" >&2 && exit 1)
if [ $http_code = 200 ]; then
echo "Fetched .dockerignore from $DOCKERFILE.dockerignore"
mv "$dockerfile_path.dockerignore.tmp" $SOURCE_CODE_DIR/$CONTEXT/.dockerignore
Expand Down
4 changes: 2 additions & 2 deletions task/buildah-remote/0.2/buildah-remote.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -277,12 +277,12 @@ spec:
elif echo "$DOCKERFILE" | grep -q "^https\?://"; then
echo "Fetch Dockerfile from $DOCKERFILE"
dockerfile_path=$(mktemp --suffix=-Dockerfile)
http_code=$(curl -s -L -w "%{http_code}" --output "$dockerfile_path" "$DOCKERFILE")
http_code=$(curl -s -L -w "%{http_code}" --output "$dockerfile_path" "$DOCKERFILE" || echo "Download of the Dockerfile failed due to connection issues" >&2 && exit 1)
if [ $http_code != 200 ]; then
echo "No Dockerfile is fetched. Server responds $http_code"
exit 1
fi
http_code=$(curl -s -L -w "%{http_code}" --output "$dockerfile_path.dockerignore.tmp" "$DOCKERFILE.dockerignore")
http_code=$(curl -s -L -w "%{http_code}" --output "$dockerfile_path.dockerignore.tmp" "$DOCKERFILE.dockerignore" || echo "Download of the .dockerignore file failed due to connection issues" >&2 && exit 1)
if [ $http_code = 200 ]; then
echo "Fetched .dockerignore from $DOCKERFILE.dockerignore"
mv "$dockerfile_path.dockerignore.tmp" $SOURCE_CODE_DIR/$CONTEXT/.dockerignore
Expand Down
4 changes: 2 additions & 2 deletions task/buildah/0.2/buildah.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -197,12 +197,12 @@ spec:
elif echo "$DOCKERFILE" | grep -q "^https\?://"; then
echo "Fetch Dockerfile from $DOCKERFILE"
dockerfile_path=$(mktemp --suffix=-Dockerfile)
http_code=$(curl -s -L -w "%{http_code}" --output "$dockerfile_path" "$DOCKERFILE")
http_code=$(curl -s -L -w "%{http_code}" --output "$dockerfile_path" "$DOCKERFILE" || echo "Download of the Dockerfile failed due to connection issues" >&2 && exit 1)
if [ $http_code != 200 ]; then
echo "No Dockerfile is fetched. Server responds $http_code"
exit 1
fi
http_code=$(curl -s -L -w "%{http_code}" --output "$dockerfile_path.dockerignore.tmp" "$DOCKERFILE.dockerignore")
http_code=$(curl -s -L -w "%{http_code}" --output "$dockerfile_path.dockerignore.tmp" "$DOCKERFILE.dockerignore" || echo "Download of the .dockerignore file failed due to connection issues" >&2 && exit 1)
if [ $http_code = 200 ]; then
echo "Fetched .dockerignore from $DOCKERFILE.dockerignore"
mv "$dockerfile_path.dockerignore.tmp" $SOURCE_CODE_DIR/$CONTEXT/.dockerignore
Expand Down

0 comments on commit 9d1295e

Please sign in to comment.