MartinSahlen/cloud-functions-python

Unexpected "(" in dist/func/func

mrmacpholea opened this issue · 3 comments

Hi there,
Sorry if this is not the right place to post (I searched on stackoverflow but there was no py-cloud-fn tag) I deployed the "storage" sample (as is) and when running it gives this error:

15:45:43.560 test2 155785686371109 ./dist/func/func: 1: ./dist/func/func: Syntax error: "(" unexpected { insertId: "000000-eb6149ef-f09f-48aa-976d-1ec133924c51" labels: {…} logName: "projects/xxxxxxxx/logs/cloudfunctions.googleapis.com%2Fcloud-functions" receiveTimestamp: "2017-09-25T22:45:52.884721958Z" resource: {…} severity: "ERROR" textPayload: "./dist/func/func: 1: ./dist/func/func: Syntax error: "(" unexpected " timestamp: "2017-09-25T22:45:43.560Z" }

Anything I might be doing wrong?
Thanks,

M

Ha! Sorry, my bad - I was building for production but did not include the -p (duh!).
Although I did bump into another issue - I was getting this error when building:

Successfully tagged pycloudfn-builder2.7:latest
docker: invalid reference format: repository name must be lowercase.

Upon some digging, I realized the command in build_function:

def build_in_docker(file_name, python_version):
    return [
        'docker', 'build', '-f', docker_path() + dockerfile(python_version),
        '-t', image_name(python_version), docker_path(), '&&', 'docker', 'run',
        '--rm', '-ti', '-v', '$(pwd):/app', image_name(python_version),
        '/bin/sh', '-c',
        ...

In a OSX environment, $(pwd) returns something like:

Volume/Macintosh HD/Users/Marcelo ....

Note the space in Macintosh and HD ... basically the command is broken by that space, causing the "repository name must be lowercase".

I patched my local copy and it worked fine by using os.getcwd() which will construct the path and escape the spaces properly. Maybe you want to apply this patch if you want to make the library to work properly in OSX (or I can apply the patch myself if you grant me a pull request)?

def build_in_docker(file_name, python_version):
    cwd = os.getcwd()
    return [
        'docker', 'build', '-f', docker_path() + dockerfile(python_version),
        '-t', image_name(python_version), docker_path(), '&&', 'docker', 'run',
        '--rm', '-ti', '-v', cwd + ':/app', image_name(python_version),
    ...

Thanks and thanks for porting CFN to Python on behalf of all Python fans!

M

Thanks! Please make a pull request, and I will review and merge ASAP :D

Closed by #19