faas-cli icon indicating copy to clipboard operation
faas-cli copied to clipboard

build command doesn't return non-zero exit code when image is not built

Open burtonr opened this issue 7 years ago • 3 comments

The build command returns exit code 0 even though an image was not created/built.

In this particular example, the path in the handler property of the function's .yml file was invalid/not found

Expected Behaviour

The build command should return a non-zero exit status when the image cannot be built

Current Behaviour

Running faas-cli build -f test-fn.yml with an invalid handler path returns a message, but no error

 $ faas-cli build -f stack.yml
[0] > Building spacex-info.
Unable to build burtonr/spacex-info, ./spacex-info is an invalid path
Image: burtonr/spacex-info not built.
[0] < Building spacex-info done.
[0] worker done.

Possible Solution

If the image cannot be built, return non-zero exit code to fail the command

Steps to Reproduce (for bugs)

  1. create a new function: faas-cli new test-fn --lang go
  2. alter the handler path in the generated yml to and invalid path:
provider:
  name: faas
  gateway: http://127.0.0.1:8080

functions:
  test-fn:
    lang: go
    handler: ./test-fn-invalid
    image: test-fn
  1. run the build command: faas-cli build -f test-fn.yml
  2. run echo $? to observe that the command does not return an error code

Context

This was discovered in testing the OpenFaas-Cloud where I had copied a function repo to a new repo without renaming the handler path.

This resulted in the shrinkwrap function to pass without error, but the image was not built.

Your Environment

  • FaaS-CLI version ( Full output from: faas-cli version ):

  • Docker version ( Full output from: docker version ):

$ faas-cli version
  ___                   _____           ____
 / _ \ _ __   ___ _ __ |  ___|_ _  __ _/ ___|
| | | | '_ \ / _ \ '_ \| |_ / _` |/ _` \___ \
| |_| | |_) |  __/ | | |  _| (_| | (_| |___) |
 \___/| .__/ \___|_| |_|_|  \__,_|\__,_|____/
      |_|

Commit: 8c7ebc3e7304873ba42b8d8e95d492499935f278
Version: 0.6.4
  • Are you using Docker Swarm (FaaS-swarm ) or Kubernetes (FaaS-netes)? FaaS-Swarm

  • Operating System and version (e.g. Linux, Windows, MacOS): Linux -> Ubuntu 18.04

  • Link to your project or a code example to reproduce issue: https://github.com/burtonr/test-function

Issue can easily be reproduced by following the "Steps to Reproduce" section. It's more obvious when you run echo $? just after the faas-cli build command

burtonr avatar Aug 09 '18 02:08 burtonr

Looking into this.

warunsl avatar Aug 09 '18 03:08 warunsl

This is a hard problem to solve @burtonr @warunsl due to needing to track the status across N parallel and concurrent tasks. I wrote a fix for this but never published it due to the work involved.

Can you confirm that when Docker executes and produces an error that it returns a non-zero exit code? I can see only one test-case failure here.. how about looking into different errors and reporting back?

2 functions - passes, one fails 1 function - docker build fails, not stack validation fails

etc.

alexellis avatar Aug 14 '18 08:08 alexellis

This is open for anyone who wants to work on it.

warunsl avatar Aug 15 '18 19:08 warunsl