Page MenuHomePhabricator

Add a bypass for the ci-src-setup script
Closed, ResolvedPublic

Description

Subscribed @Legoktm and @Addshore which were involved in the migration toward Docker images and should have some familiarity with the ci-src-setup script.

Following a conversation with @dcaro we have the use case for reusing a CI docker image locally. Some of our images have an entry point invoking ci-src-setup.sh which initializes a git repository. It is handy when the image is run by Jenkins/Zuul since all parameters are set and there are no preexisting code, but for local use the script complains about lack of ZUUL_* environment variables and most probably one wants to run the image against local code rather than a patch in Gerrit.

This task is to have the ci-src-setup to only run its operations when it is executed under the CI environment. Jenkins always inject JENKINS_URL and our Jenkins instance also set the CI environment variable which might be easier to remember. So I guess we can have the script to skip its operations when either is set.

The script is defined in dockerfiles/ci-common/content/ci-src-setup.sh. It is included in the CI base images releng/ci-stretch and releng/ci-buster and placed under /utils. Thus images entry points usually invoke /utils/ci-src-setup.sh.

I guess we can do something such as:

ci-src-setup.sh
if [[ ! -v JENKINS_URL && ! -v CI && ! -v ZUUL_URL ]]; then
  echo "Not in CI, skipping fetching the repository assuming code is mounted."
  echo "Set CI and ZUUL_* environment variables to force."
  exit 0
fi
... rest of the logic

Then when one runs the image locally, it would be expected the code has been mounted under WORKDIR (typically that is set to /src).

And if we want to reproduce what CI is doing we can locally set CI or the set of Zuul environment variables required by the script (ZUUL_URL, ZUUL_PROJECT, ZUUL_BRANCH, ZUUL_REF).

The example run scripts (dockerfiles/*/example-run.sh) should hopefully by fine since they set the Zuul environments variables in order to checkout code.

Event Timeline

Change 663202 had a related patch set uploaded (by David Caro; owner: David Caro):
[integration/config@master] ci-common: Add a bypass for the ci-src-setup script

https://gerrit.wikimedia.org/r/663202

Change 663203 had a related patch set uploaded (by David Caro; owner: David Caro):
[integration/config@master] tox: Add a bypass for the ci-src-setup script

https://gerrit.wikimedia.org/r/663203

dcaro triaged this task as Medium priority.Feb 11 2021, 5:24 PM

Most new jobs have a different pattern:

  • Run ci-src-setup-simple docker image to clone repos
  • Run tox/composer/etc. image to run tests against cloned repos

I think we should just migrate whatever is still calling ci-src-setup in the entrypoint to the new format instead.

Change 663202 merged by jenkins-bot:
[integration/config@master] ci-common: Add a bypass for the ci-src-setup script

https://gerrit.wikimedia.org/r/663202

Successfully published image docker-registry.discovery.wmnet/releng/ci-common:0.4
Successfully published image docker-registry.discovery.wmnet/releng/ci-stretch:0.4.0
Successfully published image docker-registry.discovery.wmnet/releng/ci-buster:0.3.0

And rest of the fleet will eventually be rebuild later on. The ci-src-setup.sh will then requires either CI or JENKINS_URL environment variables to be set to process. Else it will just exit 0 early on.

Change 663203 merged by jenkins-bot:
[integration/config@master] tox: Add a bypass for the ci-src-setup script

https://gerrit.wikimedia.org/r/663203

Successfully published image docker-registry.discovery.wmnet/releng/tox:0.5.0
Successfully published image docker-registry.discovery.wmnet/releng/tox-mysqld:0.6.0
Successfully published image docker-registry.discovery.wmnet/releng/tox-buster:0.2.0
Successfully published image docker-registry.discovery.wmnet/releng/tox-poolcounter:0.5.0
Successfully published image docker-registry.discovery.wmnet/releng/tox-homer:0.2.0
Successfully published image docker-registry.discovery.wmnet/releng/tox-pyspark:0.7.0
Successfully published image docker-registry.discovery.wmnet/releng/tox-conftool:0.5.0
Successfully published image docker-registry.discovery.wmnet/releng/tox-acme-chief:0.6.0
Successfully published image docker-registry.discovery.wmnet/releng/tox-censorshipmonitoring:0.2.0
Successfully published image docker-registry.discovery.wmnet/releng/tox-pywikibot:0.6.0
Successfully published image docker-registry.discovery.wmnet/releng/tox-labs-striker:0.6.0
Successfully published image docker-registry.discovery.wmnet/releng/tox-cergen:0.5.0
Successfully published image docker-registry.discovery.wmnet/releng/tox-eventlogging:0.5.0

Should be good enough now, at least that makes it possible to run the releng/tox* images locally notably for spicerack in the parent task ( T274338 ).

I will look at having all the CI images to use the same model. Filed as T274812. Thank you @dcaro !

Marking resolved.

This really seems like a step in the wrong direction.

Successfully published image docker-registry.discovery.wmnet/releng/tox:0.5.0
...

These images don't appear to work. Ci is failing. A simple reproduction seems to be:

docker run -it --rm --entrypoint /usr/bin/env docker-registry.wikimedia.org/releng/tox:0.5.0 tox
Traceback (most recent call last):
  File "/usr/local/bin/tox", line 7, in <module>
    from tox import cmdline
  File "/usr/local/lib/python3.5/dist-packages/tox/__init__.py", line 9, in <module>
    import pluggy
  File "/usr/local/lib/python3.5/dist-packages/pluggy/__init__.py", line 16, in <module>
    from .manager import PluginManager, PluginValidationError
  File "/usr/local/lib/python3.5/dist-packages/pluggy/manager.py", line 11, in <module>
    import importlib_metadata
  File "/usr/local/lib/python3.5/dist-packages/importlib_metadata/__init__.py", line 88
    dist: Optional['Distribution'] = None
        ^
SyntaxError: invalid syntax

Patch for failing tox: https://gerrit.wikimedia.org/r/c/integration/config/+/664680

I didn't attach it to this ticket since it seems that while this update triggered the error downstream, it's not directly related to this ticket.

This really seems like a step in the wrong direction.

I have filed another task with the reasoning: T274812

Patch for failing tox: https://gerrit.wikimedia.org/r/c/integration/config/+/664680

I didn't attach it to this ticket since it seems that while this update triggered the error downstream, it's not directly related to this ticket.

I have filed a task for it: T275049 . The reason seems to be importlib-metadata / importlib-resources got updated in the process..