firecow / gitlab-ci-local

Tired of pushing to test your .gitlab-ci.yml?
MIT License
2.03k stars 115 forks source link

Unable to run with --network host #1225

Closed octane100 closed 1 month ago

octane100 commented 1 month ago

Minimal .gitlab-ci.yml illustrating the issue

---
image: alpine

job:
  script:
    - ip r

With gitlab-ci-local 4.49.0, the following error is reported when running with parameter --network host :

$gitlab-ci-local --network=host
job starting alpine:latest (test)
job copied to docker volumes in 590 ms
Error: Command failed with exit code 1: docker network connect host c85b4b31fd69350dd7538d4653db289bd5bb2b3d2c4302ab096710fbdf1593f7
Error response from daemon: container cannot be disconnected from host network or connected to host network
    at makeError (/snapshot/firecow-gitlab-ci-local/node_modules/execa/lib/error.js:60:11)
    at handlePromise (/snapshot/firecow-gitlab-ci-local/node_modules/execa/index.js:118:26)
    at processTicksAndRejections (node:internal/process/task_queues:95:5)
    at Job.execScripts (/snapshot/firecow-gitlab-ci-local/src/job.ts:737:17)
    at Job.execPreScripts (/snapshot/firecow-gitlab-ci-local/src/job.ts:602:36)
    at Job.start (/snapshot/firecow-gitlab-ci-local/src/job.ts:499:9)
    at /snapshot/firecow-gitlab-ci-local/node_modules/p-map/index.js:57:22

Expected behavior Being able to run with host networking

Host information Ubuntu 22.04 gitlab-ci-local 4.49.0

Containerd binary docker.io 24.0.5-0ubuntu1~22.04.1

Additional context The same command is working as expected with gitlab-ci-local 4.48.2. Regression may have been introduced by #1205

PigeonF commented 1 month ago

I can reproduce your issue, and you are right about the PR that introduced the issue.

Reading through https://docs.docker.com/network/, the same error happens for

$ gitlab-ci-local --network=host
$ gitlab-ci-local --network=none

Additionally, the following syntax works to connect to a container directly using docker CLI

$ docker run -d --name redis redis --bind 127.0.0.1
$ docker run --rm -it --network container:redis redis redis-cli -h 127.0.0.1 PING

but when used with docker connect, it seems the same syntax does not work

$ docker run -d --name redis redis --bind 127.0.0.1
$ gitlab-ci-local --network container:redis
parsing and downloads finished in 48 ms
job starting alpine:latest (test)
job copied to docker volumes in 1.23 s
job > time="2024-05-17T12:03:03+02:00" level=error msg="error waiting for container: context canceled"
job > Error response from daemon: network container:redis not found
job finished in 1.68 s  FAIL 1 

 FAIL  job
  > time="2024-05-17T12:03:03+02:00" level=error msg="error waiting for container: context canceled"
  > Error response from daemon: network container:redis not found

I am not sure about the last one, but the first two can probably be special-cased in the code and handled that way.