Fix newline issue in reproduce_ci_env.py

MR !2598 introduced some fixes to `reproduce_ci_env.py`. One of
them handled newlines in command lists by separating the command
lists by newlines in the Dockerfile (which generated a script).
Although this worked for some of the docker containers, I found
others, like rhel8, where the newlines were not escaped correctly.

Correct this problem by moving back to separating commands with
`&&`. This requires replacing newlines in commands with `&&`.
That in itself is no problem except that if you have a blank
line, you get `&& &&`, which is a syntax error for the shell.
So, avoid this by stripping newlines from commands.
This commit is contained in:
Kenneth Moreland 2021-10-13 14:39:16 -06:00
parent 4314b730e3
commit 475261370d

@ -200,9 +200,9 @@ def create_container(ci_file_path, *args):
script_search_locations = [ci_state, subset, runner]
for loc in script_search_locations:
if 'before_script' in loc:
before_script = loc['before_script']
before_script = [command.strip() for command in loc['before_script']]
if 'script' in loc:
script = loc['script']
script = [command.strip() for command in loc['script']]
docker_template = string.Template('''
FROM $image
@ -223,10 +223,10 @@ RUN echo "$before_script" >> /setup-gitlab-env.sh && \
job_name='local-build'+runner_name,
src_dir=src_dir,
gitlab_env= " ".join(gitlab_env),
before_script="\n".join(before_script)
.replace('\n', '\\n\\\n')
before_script=" && ".join(before_script)
.replace('\n', ' && ')
.replace('"', '\\"'),
script="\n".join(script).replace('\n', '\\n\\\n')
script=" && ".join(script).replace('\n', ' && ')
.replace('"', '\\"'))
# Write out the file