openfaas / faas-cli

Official CLI for OpenFaaS
https://www.openfaas.com/
Other
794 stars 226 forks source link

Non-git directories should error on tags #769

Open andrew-s opened 4 years ago

andrew-s commented 4 years ago

This happened because of an edge case with a git binary version on a self-hosted runner.

When using tags of branch or sha on a directory that isn't a git repository, you get a complete error as an image name, e.g; eu.gcr.io/project/image:0.1-fatal: not a git repository (or any parent up to mount point /github) Stopping at filesystem boundary (GIT_DISCOVERY_ACROSS_FILESYSTEM not set).-fatal: not a git repository (or any parent up to mount point /github) Stopping at filesystem boundary (GIT_DISCOVERY_ACROSS_FILESYSTEM not set).

This is an invalid image name, and kubernetes had some issues with this.

Expected Behaviour

Should fatal or exit back to the user (with a non zero exit code)

Current Behaviour

Creates invalid image names

Possible Solution

Exit with a non-zero exit code (so that a pipeline can exit too, in this case, the runner had checked the code out as a zip instead of git without any notice)

Steps to Reproduce (for bugs)

  1. Run faas-cli build --parallel 5 --tag=sha -f faas-stack.yml on a non-git directory

Context

Runner had changed the checkout method without notification

martindekov commented 4 years ago

I get exit code 1 on failure as you described it:

$ sudo faas-cli build --tag=sha
[sudo] password for mdekov: 
Pulling template: perl-alpine from configuration file: stack.yml
Fetch templates from repository: https://github.com/tmiklas/openfaas-perl-templates at master
...
[0] > Building newnew.
Clearing temporary build folder: ./build/newnew/
Preparing: ./newnew/ build/newnew/function
Building: newnew:latest-fatal: not a git repository (or any parent up to mount point /)
Stopping at filesystem boundary (GIT_DISCOVERY_ACROSS_FILESYSTEM not set). with go template. Please wait..
invalid argument "newnew:latest-fatal: not a git repository (or any parent up to mount point /)\nStopping at filesystem boundary (GIT_DISCOVERY_ACROSS_FILESYSTEM not set)." for "-t, --tag" flag: invalid reference format: repository name must be lowercase
See 'docker build --help'.
[0] < Building newnew done in 0.43s.
[0] Worker done.

Total build time: 0.43s
Errors received during build:
- [newnew] received non-zero exit code from build, error: invalid argument "newnew:latest-fatal: not a git repository (or any parent up to mount point /)\nStopping at filesystem boundary (GIT_DISCOVERY_ACROSS_FILESYSTEM not set)." for "-t, --tag" flag: invalid reference format: repository name must be lowercase
See 'docker build --help'.

mdekov@mdekov-Lenovo-Y520-15IKBN:~/go/src/github.com/martindekov/newnew$ echo $?
1

it returns 1 isn't this the proposed solution?

andrew-s commented 4 years ago

@martindekov So I went back and took a look at our pipeline, turns out we built on one machine (with the correct git version) and deployed on one that ended up with the zip, looks like build does indeed fail correctly but deploy does not.