firecow / gitlab-ci-local

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

setting the docker container MAC address #1144

Closed sh-cau closed 6 months ago

sh-cau commented 6 months ago

Is your feature request related to a problem? Please describe. I want to pass additional options, that is to say, especially setting the MAC address, of the docker container like I would with, e.g.,

gitlab-runner exec docker --docker-mac-address=AA:BB:CC:DD:EE:FF <JOB_NAME>

Describe the solution you'd like I would like to achieve the above equivalent like so

gitlab-ci-local --docker-mac-addres=AA:BB:CC:DD:EE:FF <JOB_NAME>

Describe alternatives you've considered I tried manipulating the --container-executable, i.e.,

gitlab-ci-local --container-executable="docker run --mac-address=AA:BB:CC:DD:EE:FF"

and

gitlab-ci-local --container-executable="docker --mac-address=AA:BB:CC:DD:EE:FF"

to no avail.

Additional context I need this feature since the docker container runs a MATLAB instance, the license of which is linked to a fixed MAC address.

Thank you!

ANGkeith commented 6 months ago

We can add support for this, but my question is how do you then, plan to run this via the actual gitlab runnner ?

Maybe you can give the following a try?

#.gitlab-ci.yml
job:
  image: bash
  script:
    - ifconfig eth0 hw ether "AA:BB:CC:DD:EE:FF"
    - ip a show eth0

image

Addtional info: Until https://gitlab.com/gitlab-org/gitlab-runner/-/issues/27863 is implemented, you might want to go with the hacky workaround as recommended here https://gitlab.com/gitlab-org/gitlab-runner/-/issues/2344#note_95853536

sh-cau commented 6 months ago

The actual gitlab runner is registered using gitlab-runner register --docker-mac-address AA:BB:CC:DD:EE:FF ..., which writes the mac address in the config.toml of the gitlab runner much like described in your second reference. Unfortunately, gitlab-runner exec ignores this configuration entirely (but it doesn't when its being called by GitLab).

You solution works, however, this requires me to adjust the .gitlab-ci.yaml everytime I want to test locally and this, in fact, is the reason I quit using gitlab-runner exec because with that you can't pass CI-specific environment variables, say, CI_JOB_TOKEN or CI_PIPELINE_SOURCE, which also leads to me having to rename these variables for the testing time.