python-openapi / openapi-spec-validator

OpenAPI Spec Validator is a CLI, pre-commit hook and python package that validates OpenAPI Specs against the OpenAPI 2.0 (aka Swagger), OpenAPI 3.0 and OpenAPI 3.1 specification.
Apache License 2.0
324 stars 61 forks source link

Docker image can't be used in CI #287

Closed elafontaine closed 9 months ago

elafontaine commented 9 months ago

Can't run this image as part of a CI as the sh isn't working for some reason.

I have a team using the python module, but, do to our corporate policies, they have to do a lot of gymnastics to make it work. If the docker image were to work with sh, we would be able to use it in our CI directly.

The error I get locally when trying to start the sh program is ;

➜  .ssh docker run -it pythonopenapi/openapi-spec-validator /bin/sh
unacceptable character #x00b7: invalid start byte
  in "<urllib response>", position 18

On a x86 PC of a colleague, he gets ;

unacceptable character #x00f1: invalid continuation byte
  in "<urllib response>", position 24

On the gitlab-ci run we get a different error, my guess being that gitlab runs the script outside the image to find the right binary to execute from within the image ;

Using docker image sha256:1426762d856b5cf5f4925b968d6bb3057c17bb256cc84d5e18adaa9445808baa for pythonopenapi/openapi-spec-validator with digest pythonopenapi/openapi-spec-validator@sha256:82c40fa489cd58d1c6b9cfa5cff5d7c41fd1290e3be57ff4c9f208e87ea97456 ...
usage: openapi-spec-validator [-h] [--errors {best-match,all}]
                              [--schema {2.0,3.0.0,3.1.0,detect}]
                              filename
openapi-spec-validator: error: unrecognized arguments: -c if [ -x /usr/local/bin/bash ]; then
    exec /usr/local/bin/bash 
elif [ -x /usr/bin/bash ]; then
    exec /usr/bin/bash 
elif [ -x /bin/bash ]; then
    exec /bin/bash 
elif [ -x /usr/local/bin/sh ]; then
    exec /usr/local/bin/sh 
elif [ -x /usr/bin/sh ]; then
    exec /usr/bin/sh 
elif [ -x /bin/sh ]; then
    exec /bin/sh 
elif [ -x /busybox/sh ]; then
    exec /busybox/sh 
else
    echo shell not found
    exit 1
fi

Please let me know if you can reproduce or not. I'm just wondering what I'm doing wrong if I'm doing something wrong.

BTW, running the image on a specific file returns a "OK" message, but I don't get what's going on.

➜   docker run -v $(pwd):/data -w /data --rm pythonopenapi/openapi-spec-validator <redacted_filename>
OK
p1c2u commented 9 months ago

hi @elafontaine

entrypoint for the docker image is openapi-spec-validator command.

When you run the following:

docker run -it pythonopenapi/openapi-spec-validator /bin/sh

you run openapi-spec-validator command with /bin/sh as filename argument to validation. This will of course fail.

If you want to override entry point to use shell you need to use --entrypoint option:

docker run --entrypoint /bin/sh -it pythonopenapi/openapi-spec-validator

Read more about docker run command and --entrypoint option: https://docs.docker.com/engine/reference/commandline/run/

elafontaine commented 9 months ago

Yup, just realized. Thanks a lot for your time, really sorry about this.

elafontaine commented 9 months ago

the solution ;

  image:
    name: pythonopenapi/openapi-spec-validator
    entrypoint: [""]