Make reproduce_ci_env.py more tolerant of scripts

When `reproduce_ci_env.py` makes its docker container, it creates a pair
of scripts, `setup-gitlab-env.sh` and `run-gitlab-stage.sh`, inside the
container. These scripts came from the `before_script` and `script` CI
configuration parameters, respectively.

These two scripts were created by joining each item in the CI
configuration lists with `&&` onto a single line. However, this meant
that each list item had to be on its own line or it didn't work. A
recent configuration change meant that one of the configurations
contained multiple shell commands separated by newlines. This change
builds the script with multiple lines (which have to be carefully
escaped in the generated dockerfile).

Also modified these strings to escape quotes (`"`). This is important as
the dockerfile generates these scripts using an `echo` command that
needs to quote all of the arguments together.
This commit is contained in:
Kenneth Moreland 2021-10-05 14:17:54 -06:00
parent 28b800d21d
commit ecacc89b7d

@ -214,8 +214,8 @@ ENV GITLAB_CI=1 \
COPY . /src
ENV $gitlab_env
WORKDIR /src
RUN echo "$before_script || true" >> /setup-gitlab-env.sh && \
echo "$script || true" >> /run-gitlab-stage.sh && \
RUN echo "$before_script" >> /setup-gitlab-env.sh && \
echo "$script" >> /run-gitlab-stage.sh && \
bash /setup-gitlab-env.sh
''')
@ -223,8 +223,11 @@ RUN echo "$before_script || true" >> /setup-gitlab-env.sh && \
job_name='local-build'+runner_name,
src_dir=src_dir,
gitlab_env= " ".join(gitlab_env),
before_script=" && ".join(before_script),
script=" && ".join(script))
before_script="\n".join(before_script)
.replace('\n', '\\n\\\n')
.replace('"', '\\"'),
script="\n".join(script).replace('\n', '\\n\\\n')
.replace('"', '\\"'))
# Write out the file
docker_file = tempfile.NamedTemporaryFile(delete=False)