GoogleCloudPlatform / gcpdiag

gcpdiag is a command-line diagnostics tool for GCP customers.
https://gcpdiag.dev/
Apache License 2.0
288 stars 67 forks source link

"docker: invalid reference format." during Github Actions usage #39

Closed nbali closed 2 years ago

nbali commented 2 years ago

I tried to use it with Github Actions - minimalistic setup to reproduce (I know configs like credentials are missing, but it's not required for the reproduction):

name: GCP Diag

on:
  push:

jobs:
  build:
    runs-on: ubuntu-latest

    steps:
    - name: Run GCP diag
      run: |
        curl https://gcpdiag.dev/gcpdiag.sh > gcpdiag
        chmod +x gcpdiag
        ./gcpdiag lint --project=dummy-non-existing-project

Output:

Run
  curl https://gcpdiag.dev/gcpdiag.sh > gcpdiag
  chmod +x gcpdiag
  ./gcpdiag lint --project=dummy-non-existing-project
  shell: /usr/bin/bash -e {0}
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
100  4382  100  4382    0     0  20381      0 --:--:-- --:--:-- --:--:-- 20381
docker: invalid reference format.
See 'docker run --help'.
Error: Process completed with exit code 125.

I think "docker: invalid reference format." isn't an intended error message.

dawidmalina commented 2 years ago

HI @nbali,

This message is raised by docker client not code itself. Usually it relates to mismatch between docker image and docker host architecture. Currently we are providing only amd64 type of image.

You can use uname -a to get the architecture of the infrastructure used by GitHub actions. This would help us define what type of docker image should be used.

dawidmalina commented 2 years ago

@nbali I found the problem.

exec "$RUNTIME" run "$USE_TTY" \
  --rm \
  -u "$(id -u):$(id -g)" \

When we run gcpdiag script in the GH runner environment "$USE_TTY" variable is empty but quoted so final exec commend is invalid:

exec docker run '' --rm -u 1001:121 -e USER=runner -e GROUP=docker -e SHELL=/bin/bash ...

But when I run same script locally or in the Cloud Shell exec comment quotas are removed by shell:

exec docker run --rm -u 1001:121 -e USER=runner -e GROUP=docker -e SHELL=/bin/bash ...

As a workaround you can execute this combo to move forward and final script will be fixed in the script code:

curl https://gcpdiag.dev/gcpdiag.sh > gcpdiag
sed -i 's/run "\$USE_TTY"/run \$USE_TTY/' gcpdiag
bash -x ./gcpdiag lint --project=dummy-non-existing-project