Skip to content

faas build fails with tox error #44

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
3 tasks done
saikiran2603 opened this issue Mar 31, 2021 · 7 comments
Closed
3 tasks done

faas build fails with tox error #44

saikiran2603 opened this issue Mar 31, 2021 · 7 comments

Comments

@saikiran2603
Copy link
Contributor

saikiran2603 commented Mar 31, 2021

My actions before raising this issue

When building a function with faas build , build fails with below error
ERROR: tox config file (either pyproject.toml, tox.ini, setup.cfg) not found
The command '/bin/sh -c if [ "$TEST_ENABLED" == "false" ]; then echo "skipping tests"; else eval "$TEST_COMMAND"; fi' returned a non-zero code: 1
[0] < Building test-tox done in 8.28s.
[0] Worker done.

Total build time: 8.28s
Errors received during build:

  • [test-tox] received non-zero exit code from build, error: The command '/bin/sh -c if [ "$TEST_ENABLED" == "false" ]; then echo "skipping tests"; else eval "$TEST_COMMAND"; fi' returned a non-zero code: 1

Expected Behaviour

Function build should complete successfully.

Current Behaviour

Build completes in error. When TEST_ENABLED is set to false , build completes successfully. But default mode when TEST_ENABLED is set to true , the build fails to find tox.ini , although the file is created by default by the cli.

Possible Solution

Steps to Reproduce (for bugs)

  1. create a new function using python-flask-template repo "faas new --lang python3-http test-tox"
  2. Build function using faas build -f test-tox.yml
  3. Function build fails with above error

Context

trying to use new template format.

Your Environment

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

  • Docker version docker version (e.g. Docker 17.0.05 ):
    19.03.8

  • Are you using Docker Swarm or Kubernetes (FaaS-netes)?
    Kubernetes

  • Operating System and version (e.g. Linux, Windows, MacOS):
    Linux (CentOS)

  • Code example or link to GitHub repo or gist to reproduce problem:
    n/A

  • Other diagnostic information / logs from troubleshooting guide
    Step 27/35 : ARG TEST_ENABLED=true
    ---> Using cache
    ---> c38444c37ac6
    Step 28/35 : RUN if [ "$TEST_ENABLED" == "false" ]; then echo "skipping tests"; else eval "$TEST_COMMAND"; fi
    ---> Running in c1b290bd6c83
    ERROR: tox config file (either pyproject.toml, tox.ini, setup.cfg) not found
    The command '/bin/sh -c if [ "$TEST_ENABLED" == "false" ]; then echo "skipping tests"; else eval "$TEST_COMMAND"; fi' returned a non-zero code: 1
    [0] < Building test-tox done in 2.11s.
    [0] Worker done.

Total build time: 2.11s
Errors received during build:

  • [test-tox] received non-zero exit code from build, error: The command '/bin/sh -c if [ "$TEST_ENABLED" == "false" ]; then echo "skipping tests"; else eval "$TEST_COMMAND"; fi' returned a non-zero code: 1

Next steps

You may join Slack for community support.

@saikiran2603
Copy link
Contributor Author

saikiran2603 commented Mar 31, 2021

Possible solution ??

From the docker compose , it looks like the work dir is /home/app when the tox command is getting executed

`WORKDIR /home/app/

#install function code
USER root
COPY function function
RUN chown -R app:app ./

ARG TEST_COMMAND=tox
ARG TEST_ENABLED=true
RUN if [ "$TEST_ENABLED" == "false" ]; then
echo "skipping tests";
else
eval "$TEST_COMMAND";
fi
eval "$TEST_COMMAND"; ` is eventually running command tox , but the tox.ini file is not in current directory , but inside function folder , so instead of just tox command should it be "tox -c function/tox.ini"

Proposed change to docker file

ARG TEST_COMMAND="tox -c function/tox.ini"
ARG TEST_ENABLED=true
RUN if [ "$TEST_ENABLED" == "false" ]; then
echo "skipping tests";
else
eval "$TEST_COMMAND";
fi

ARG TEST_COMMAND="tox -c function/tox.ini" this line would now pass the correct tox.ini path

@LucasRoesler
Copy link
Member

LucasRoesler commented Apr 1, 2021

this is odd, in my function I get a successful build

$ faas-cli new echo1 --lang python3-flask
Folder: echo1 created.
  ___                   _____           ____
 / _ \ _ __   ___ _ __ |  ___|_ _  __ _/ ___|
| | | | '_ \ / _ \ '_ \| |_ / _` |/ _` \___ \
| |_| | |_) |  __/ | | |  _| (_| | (_| |___) |
 \___/| .__/ \___|_| |_|_|  \__,_|\__,_|____/
      |_|


Function created in folder: echo1
Stack file written: echo1.yml
$  faas-cli build -f echo1.yml
[0] > Building echo1.
Clearing temporary build folder: ./build/echo1/
Preparing: ./echo1/ build/echo1/function
Building: echo1:latest with python3-flask template. Please wait..
#1 [internal] load build definition from Dockerfile
#1 sha256:7973ced09bcb3b11faa2b821c273a9863c400d7355500ec79e3953b6964b472e
#1 transferring dockerfile: 1.36kB done
#1 DONE 0.0s

#2 [internal] load .dockerignore
#2 sha256:ec5c1ea1d865323a670f1a875809e038bca199ccf81e8486598f7ddfbad5ec41
#2 transferring context: 2B done
#2 DONE 0.0s

#4 [internal] load metadata for docker.io/openfaas/of-watchdog:0.7.7
#4 sha256:3e12bb1a2b64b86e4ecccd06eee29e6999a8e23263ab922164cd7aa70b607189
#4 ...

#3 [internal] load metadata for docker.io/library/python:3.7-alpine
#3 sha256:6aa3fbe2d5daab236c694fe35aaf5e88aa0902955f2d77235216c44ae1323666
#3 DONE 1.2s

#4 [internal] load metadata for docker.io/openfaas/of-watchdog:0.7.7
#4 sha256:3e12bb1a2b64b86e4ecccd06eee29e6999a8e23263ab922164cd7aa70b607189
#4 DONE 3.7s

#5 [stage-1  1/19] FROM docker.io/library/python:3.7-alpine@sha256:3286e2c3807f68aaa9eee1a0ccb697feede9633e83d328b1e97577ff5f13f6e6
#5 sha256:2559050dda81755dfb6913755bda5ce0ea81970ce87b7279b0c8171f984fd10e
#5 DONE 0.0s

#6 [watchdog 1/1] FROM docker.io/openfaas/of-watchdog:0.7.7@sha256:f988f45b65b0282f457bed763525ec92ca493487cc033c2db0399eac17732ac4
#6 sha256:e644b078777009f27971dfeedd4b328b29700db1b7c51ffeb0807675438bed70
#6 DONE 0.0s

#13 [internal] load build context
#13 sha256:0595dff2355665e8d59895bad997383148018e593ca7f4b1dc676b31ee35fe04
#13 transferring context: 2.87kB done
#13 DONE 0.0s

#15 [stage-1  9/19] COPY requirements.txt   .
#15 sha256:5a0632ee3e4cb86b84a0e5ce6277ab8d8e4008558c5dcba19026f73d0f4e8b45
#15 CACHED

#14 [stage-1  8/19] COPY index.py           .
#14 sha256:7bc5b9b284a45fa1f0ed47dba6c21866e4e91381b76fee544c82d83e9776312d
#14 CACHED

#10 [stage-1  5/19] RUN addgroup -S app && adduser app -S -G app
#10 sha256:beb2818d14f7120d676e74b0a6730439184be6a748f82387b4201043c5e87866
#10 CACHED

#7 [stage-1  2/19] COPY --from=watchdog /fwatchdog /usr/bin/fwatchdog
#7 sha256:534764b002d32b69c7087fe684bfa249098897d403c65584b6b0cc822607e003
#7 CACHED

#9 [stage-1  4/19] RUN apk --no-cache add openssl-dev ${ADDITIONAL_PACKAGE}
#9 sha256:78c08a5ef07731418011351568488f37a40237fba513ff77cdbdcfabbee5c73a
#9 CACHED

#11 [stage-1  6/19] RUN chown app /home/app
#11 sha256:28555c0a46836c53444559c07166f980240a6c845f9bb18d858055ede66656a5
#11 CACHED

#17 [stage-1 11/19] RUN mkdir -p function
#17 sha256:f94c385809da57fe51842b504c9aba0be011978663d9ef575630bf4d5a4d1141
#17 CACHED

#8 [stage-1  3/19] RUN chmod +x /usr/bin/fwatchdog
#8 sha256:e741f1ebdeeb966c7b00acf176100f29906534335f5ab657cca561fdd1e6a6a5
#8 CACHED

#16 [stage-1 10/19] RUN pip install -r requirements.txt
#16 sha256:b357ccc8dc61e81021dc486374720d44e70c3daa1052db313e3c8a5744a9c8a6
#16 CACHED

#20 [stage-1 14/19] COPY function/requirements.txt	.
#20 sha256:b94d8e26d5a16f94853212c58831a5fddced7d2ef2fa4e76b4db1e5830183492
#20 CACHED

#18 [stage-1 12/19] RUN touch ./function/__init__.py
#18 sha256:834387a7b0b5a5d07bf51f538f0b9365ef0b6ed39f2ae0578f9ad7c42ed9d98a
#18 CACHED

#12 [stage-1  7/19] WORKDIR /home/app/
#12 sha256:e0b9e99a8472375bfb0968b143c9ad10cff06a829297428c4f77e76911e770e1
#12 CACHED

#19 [stage-1 13/19] WORKDIR /home/app/function/
#19 sha256:681fff044ae34034a2f850053e4742f5fa51bce999a8820897cfc6b1cafade95
#19 CACHED

#21 [stage-1 15/19] RUN pip install --user -r requirements.txt
#21 sha256:8db889fec68927031426daeb6393b9a4012af9270ee853827bf8e618d9bd1084
#21 CACHED

#22 [stage-1 16/19] COPY function/   .
#22 sha256:d3f64b003c7222b6998bc481c82f29859c88eb8242cea490a2f185c194596c99
#22 DONE 0.0s

#23 [stage-1 17/19] RUN chown -R app:app ../
#23 sha256:3ce59c4b351d1a6eb1d8a219e0e146185e9b6ba9430d044e8ac561a5f4e0c24f
#23 DONE 0.2s

#24 [stage-1 18/19] RUN if [ "true" == "false" ]; then     echo "skipping tests";    else     eval "tox";     fi
#24 sha256:42c807d12cda786e5f5254c7f8aca61dea153d40a74b3c3f9499b757eb65fc1d
#24 0.411 lint create: /home/app/function/.tox/lint
#24 0.856 lint installdeps: flake8
#24 3.308 lint installed: flake8==3.9.0,importlib-metadata==3.10.0,mccabe==0.6.1,pycodestyle==2.7.0,pyflakes==2.3.1,typing-extensions==3.7.4.3,zipp==3.4.1
#24 3.309 lint run-test-pre: PYTHONHASHSEED='2210922628'
#24 3.309 lint run-test: commands[0] | flake8 .
#24 3.606 0
#24 3.619 test create: /home/app/function/.tox/test
#24 3.869 test installdeps: flask, pytest, -rrequirements.txt
#24 7.396 test installed: attrs==20.3.0,click==7.1.2,Flask==1.1.2,importlib-metadata==3.10.0,iniconfig==1.1.1,itsdangerous==1.1.0,Jinja2==2.11.3,MarkupSafe==1.1.1,packaging==20.9,pluggy==0.13.1,py==1.10.0,pyparsing==2.4.7,pytest==6.2.2,toml==0.10.2,typing-extensions==3.7.4.3,Werkzeug==1.0.1,zipp==3.4.1
#24 7.397 test run-test-pre: PYTHONHASHSEED='2210922628'
#24 7.397 test run-test: commands[0] | pytest
#24 7.552 ============================= test session starts ==============================
#24 7.552 platform linux -- Python 3.7.10, pytest-6.2.2, py-1.10.0, pluggy-0.13.1
#24 7.552 cachedir: .tox/test/.pytest_cache
#24 7.552 rootdir: /home/app/function
#24 7.552 collected 1 item
#24 7.552
#24 7.552 handler_test.py .                                                        [100%]
#24 7.554
#24 7.554 ============================== 1 passed in 0.01s ===============================
#24 7.572 ___________________________________ summary ____________________________________
#24 7.572   lint: commands succeeded
#24 7.572   test: commands succeeded
#24 7.572   congratulations :)
#24 DONE 7.6s

#25 [stage-1 19/19] WORKDIR /home/app/
#25 sha256:9bacaa1682e7a20e34174783430818f0be98e25327d081021a5df9394812907f
#25 DONE 0.0s

#26 exporting to image
#26 sha256:e8c613e07b0b7ff33893b694f7759a10d42e180f2b4dc349fb57dc6b71dcab00
#26 exporting layers
#26 exporting layers 0.3s done
#26 writing image sha256:cfb5011652f6969a51c90112222ab0ea74e50dba622ac6259ae297bd74be1978 done
#26 naming to docker.io/library/echo1:latest done
#26 DONE 0.3s
Image: echo1:latest built.
[0] < Building echo1 done in 13.19s.
[0] Worker done.

Total build time: 13.19s
❯  python-flask-template git:(master) ✗

@LucasRoesler
Copy link
Member

Actually i think i realize the difference, i used the flask template not the http template and the python3-http does throw that error for me as well

#27 0.421 ERROR: tox config file (either pyproject.toml, tox.ini, setup.cfg) not found
#27 ERROR: executor failed running [/bin/sh -c if [ "$TEST_ENABLED" == "false" ]; then     echo "skipping tests";    else     eval "$TEST_COMMAND";     fi]: exit code: 1
------
 > [stage-1 19/19] RUN if [ "true" == "false" ]; then     echo "skipping tests";    else     eval "tox";     fi:
------
executor failed running [/bin/sh -c if [ "$TEST_ENABLED" == "false" ]; then     echo "skipping tests";    else     eval "$TEST_COMMAND";     fi]: exit code: 1

@saikiran2603
Copy link
Contributor Author

Yeah, i am predominantly using http templates. I have raised a PR , and fixed the dockerfile. I think i made changes to flask templates as well , i might need to revert it . Could you review the proposed solution ? is that the way you would want it tackled or if you have any suggestions ?

@LucasRoesler
Copy link
Member

@saikiran2603 I think that we need to decide what the working directory should be for that step and then make it consistent in each of the templates. Your fix does work but because the working directory is different in each template it is really hard to document how to customize that command value, because obviously the working directory from where the command is run is very important.

Instead of changing the tox command, we could also ensure that the working directory for that command is the function folder. This feels right to me because that is the folder that contains all of the user edited code and files, so it is natural to write that command value assuming the function folder as the working directory, then your build step and local dev experience should match much more closely.

What do you think?

@saikiran2603
Copy link
Contributor Author

I agree, this makes much more sense. I will make the change , test it and get back . Thanks for your feedback ! :)

@saikiran2603
Copy link
Contributor Author

Hi @LucasRoesler,
I have moved around the workdir change which was happening before the tox execution , to be done after the tox. So that tox command runs from inside the function folder. Also modified copy and chown to be similar to python3-flask (as these would now execute from inside function folder)

Could you please review the PR and suggest if i am missing something

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants