google-github-actions / deploy-cloudrun

A GitHub Action for deploying services to Google Cloud Run.
https://cloud.google.com/run
Apache License 2.0
467 stars 115 forks source link

Cloud run job issue with parsing flags #514

Closed AdeelK93 closed 6 months ago

AdeelK93 commented 6 months ago

TL;DR

This GHA replaces = separated flags with space separate flags, which can cause parsing issues.

Expected behavior

If I add in the flags --command=python --args='-m,job.main', the output gcloud command should also be = separated, which would result in a successful deploy.

Observed behavior

The = gets replaced by a space by GHA, and the resultant flag sent to gcloud looks like --command python --args -m,job.main. That leading dash for -m causes a shell parsing error, which looks like:

ERROR: (gcloud.run.jobs.deploy) argument --args: expected one argument

Action YAML

- name: Deploy to Cloud Run
  uses: google-github-actions/deploy-cloudrun@v2
  with:
    job: test
    region: us-east1
    flags: --command=python --args=-m,job.main

Log output

Error: google-github-actions/deploy-cloudrun failed with: failed to execute gcloud command `gcloud run jobs deploy test ... --command python --args -m,job.main`: ERROR: (gcloud.run.jobs.deploy) argument --args: expected one argument

Additional information

This is only an issue if the first arg starts with a dash

sethvargo commented 6 months ago

I believe you need to quote your command, same as in your shell:

- name: Deploy to Cloud Run
  uses: google-github-actions/deploy-cloudrun@v2
  with:
    job: test
    region: us-east1
    flags: --command="python --args=-m,job.main"
AdeelK93 commented 6 months ago

quoting like that results in the command "python --args=-m,job.main" - but the command and args are distinct components of the cloud run api

AdeelK93 commented 6 months ago

@sethvargo Looking through past issues, it looks like this issue was created twice before (#58 and #444) - but both times the issue was closed. This is a legitimate issue!

sethvargo commented 6 months ago

What is the equivalent gcloud command for what you're trying to do?

AdeelK93 commented 6 months ago

so a gcloud command that i can run that would behave correctly would look like: gcloud run jobs deploy test ... --command=python --args=-m,job.main and when i use this GHA - i delimit using =. However, the GHA replaces the = with spaces, resulting in this invalid command: gcloud run jobs deploy test ... --command python --args -m,job.main which is effectively a shell syntax issue due to this character replacement by the GHA thank you Seth

sethvargo commented 6 months ago

Is the issue specifically because the args start with a dash (-m)?

AdeelK93 commented 6 months ago

correct. if the arg had a dash anywhere but the beginning, this wouldn't be an issue. specifically because a space was used instead of an =

sethvargo commented 6 months ago

Can you try:

flags: --command=python "--args=-m,job.main"

If that doesn't work, please provide the debug logs so I can see the exact command that's being executed.

The reason this is difficult is because we don't actually know the flags gcloud is expecting, so it's impossible to know how each CLI argument expects to be parsed. You can see all the different test cases we have, but the flag parsing is generic and doesn't know whether something expects arguments.

sethvargo commented 6 months ago

And to be clear, we don't "use" a space. We explode the arguments and pass them into exec() (since that's how the syscall expects it).

AdeelK93 commented 6 months ago

This is the error I get - it's being quoted in the final command line

Error: google-github-actions/deploy-cloudrun failed with: failed to execute gcloud command gcloud run jobs deploy test ... --command python "--args=-m,job.main": ERROR: (gcloud.run.jobs.deploy) unrecognized arguments: "--args=-m,job.main" (did you mean '--args'?)

sethvargo commented 6 months ago

Can you try using @main with the fully quoted flag (like I posted above)?

AdeelK93 commented 6 months ago

that worked!! thank you so much @sethvargo!