MartinSahlen / cloud-functions-python

Get some python in google cloud functions
203 stars 29 forks source link

Unexpected "(" in dist/func/func #18

Closed mrmacpholea closed 7 years ago

mrmacpholea commented 7 years ago

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

mrmacpholea commented 7 years ago

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

MartinSahlen commented 7 years ago

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

MartinSahlen commented 7 years ago

Closed by #19