Skip to content

Commit

Permalink
Fix incorrect injected USER directive
Browse files Browse the repository at this point in the history
* CLOUDBLD-4939

This bug was introduced in commit 6140b73.

Signed-off-by: Chenxiong Qi <cqi@redhat.com>
  • Loading branch information
tkdchen authored and MartinBasti committed Mar 23, 2021
1 parent 72f869b commit 59f16ce
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 2 deletions.
2 changes: 1 addition & 1 deletion atomic_reactor/plugins/pre_inject_yum_repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class InjectYumRepoPlugin(PreBuildPlugin):
def _final_user_line(self):
user = self._find_final_user()
if user:
return f'USER {user}'
return user

builder = self.workflow.builder
if not builder.dockerfile_images.base_from_scratch:
Expand Down
46 changes: 45 additions & 1 deletion tests/plugins/test_yum_inject.py
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,51 @@ def test_no_base_image_in_dockerfile(tmpdir):
RUN rm -f '/etc/yum.repos.d/custom-{}.repo'
'''),
]
],
# Reset the USER found from the last stage properly.
# `USER 1001` should be reset after the removal commands
[
True, '',
[
(
'http://repos.host/custom.repo',
dedent('''\
[new-packages]
name=repo1
baseurl=http://repo.host/latest/$basearch/os
'''),
dedent(f'''\
[new-packages]
sslcacert=/tmp/{CA_BUNDLE_PEM}
name=repo1
baseurl=http://repo.host/latest/$basearch/os
'''),
),
],
dedent('''\
FROM base
RUN gcc main.c
FROM fedora:33
USER 1001
WORKDIR /src
'''),
dedent(f'''\
FROM base
ADD {CA_BUNDLE_PEM} /tmp/{CA_BUNDLE_PEM}
ADD atomic-reactor-repos/* /etc/yum.repos.d/
RUN gcc main.c
FROM fedora:33
ADD {CA_BUNDLE_PEM} /tmp/{CA_BUNDLE_PEM}
ADD atomic-reactor-repos/* /etc/yum.repos.d/
USER 1001
WORKDIR /src
USER root
RUN rm -f '/etc/yum.repos.d/custom-{{}}.repo'
RUN rm -f /tmp/{CA_BUNDLE_PEM}
USER 1001
'''),
],
]
)
@responses.activate
Expand Down

0 comments on commit 59f16ce

Please sign in to comment.