Orange-OpenSource / hurl

Hurl, run and test HTTP requests with plain text.
https://hurl.dev
Apache License 2.0
12.89k stars 482 forks source link

How to run an interactive shell in the docker image ? #2943

Closed glb-cblin closed 3 months ago

glb-cblin commented 3 months ago

Usually, I can run a container with /bin/sh or sh or bash or etc...

Nothing works for the hurl image, can you provide any tip ?

docker run --name mycontainer --rm -i -t ghcr.io/orange-opensource/hurl:latest /bin/sh
error: Issue reading from /bin/sh: invalid utf-8 sequence of 1 bytes from index 25

docker run --name mycontainer --rm -i -t ghcr.io/orange-opensource/hurl:latest sh
error: Cannot access 'sh': No such file or directory

docker run --name mycontainer --rm -i -t ghcr.io/orange-opensource/hurl:latest bash
error: Cannot access 'bassh': No such file or directory

the context is that I want to write a sh script in the directory where my hurl tests are located, so I'd like to

  1. easily dev with an interactive shell
  2. easily launch the shell script from CI server

sorry if this is already explained somewhere, I cannot find it in the doc at https://hurl.dev/docs/tutorial/ci-cd-integration.html#running-tests-with-gitlab-cicd (i.e you are using docker-in-docker, this is not what I'd like) or https://about.gitlab.com/blog/2022/12/14/how-to-continously-test-web-apps-apis-with-hurl-and-gitlab-ci-cd/ (where you are directly calling hurl from the gitlab script and not from a shell script inside the docker container)

jcamiel commented 3 months ago

Hi

Hurl is the entrypoint of our Docker image so:

$ docker run --name mycontainer --rm -i -t ghcr.io/orange-opensource/hurl:latest

will run Hurl. For instance, to run hurl --version, you can:

$ docker run --name mycontainer --rm -i -t ghcr.io/orange-opensource/hurl:latest --version
hurl 4.3.0 (aarch64-alpine-linux-musl) libcurl/8.5.0 OpenSSL/3.0.12 zlib/1.2.13 brotli/1.0.9 nghttp2/1.51.0
Features (libcurl):  alt-svc AsynchDNS brotli HSTS HTTP2 IPv6 Largefile libz NTLM SSL TLS-SRP UnixSockets
Features (built-in): brotli

If you want an interactive shell inside the docker container, you can use --entrypoint:

$  docker run --entrypoint /bin/sh --name mycontainer --rm -i -t ghcr.io/orange-opensource/hurl:latest
> hurl --version
hurl 4.3.0 (aarch64-alpine-linux-musl) libcurl/8.5.0 OpenSSL/3.0.12 zlib/1.2.13 brotli/1.0.9 nghttp2/1.51.0
Features (libcurl):  alt-svc AsynchDNS brotli HSTS HTTP2 IPv6 Largefile libz NTLM SSL TLS-SRP UnixSockets
Features (built-in): brotli
>
glb-cblin commented 3 months ago

thanks for the answer of my first point @jcamiel 👍

I did not know about this entrypoint subtelty, thanks

now can you also help with my second problem ?

easily launch the shell script from CI server

at the moment, I'm using gitlab anf I'm doing this

poc-ci-hurl:    
    stage: after-deploy
    image: ghcr.io/orange-opensource/hurl:latest
    script:
        - cd apis/tests/hurl-tests
        - sh run-all.sh

and I have this problem

Executing "step_script" stage of the job script

Using docker image sha256:cb35749cd4fab97d92d566328e10a83d6fbfbad64b66439379fc6d440ab72385 for ghcr.io/orange-opensource/hurl:latest with digest ghcr.io/orange-opensource/hurl@sha256:97f3514133e130a1fc026cda2d6e8fbce2a7e065c54965baca9d70c0d6b5afa6 ...
error: Cannot access 'sh': No such file or directory
jcamiel commented 3 months ago

@glb-cblin not a specialist of CI/CD wbut maybe you could try absolute path to binaries ? (i.e. /bin/sh?)

glb-cblin commented 3 months ago

Ok I've finally found the workaroud in https://forum.gitlab.com/t/how-to-override-entrypoint-in-gitlab-ci-yml/9429

poc-ci-hurl:    
    stage: after-deploy 
    image: 
        name: ghcr.io/orange-opensource/hurl:4.3.0
        entrypoint: [""]
    script:
        - echo test

This is really the first time of my life that I need this ...