diff mbox series

[4/7] tests/docker: add USER stanzas to non-lci images

Message ID 20230224180857.1050220-5-alex.bennee@linaro.org
State Superseded
Headers show
Series testing/next: docker.py removal and kaniko updates | expand

Commit Message

Alex Bennée Feb. 24, 2023, 6:08 p.m. UTC
These are flat but not generated by lcitool so we need to manually
update them with the `useradd` stanza.

Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
---
 tests/docker/dockerfiles/debian-all-test-cross.docker     | 5 +++++
 tests/docker/dockerfiles/debian-alpha-cross.docker        | 5 +++++
 tests/docker/dockerfiles/debian-hexagon-cross.docker      | 5 +++++
 tests/docker/dockerfiles/debian-hppa-cross.docker         | 5 +++++
 tests/docker/dockerfiles/debian-loongarch-cross.docker    | 5 +++++
 tests/docker/dockerfiles/debian-m68k-cross.docker         | 5 +++++
 tests/docker/dockerfiles/debian-mips-cross.docker         | 5 +++++
 tests/docker/dockerfiles/debian-mips64-cross.docker       | 5 +++++
 tests/docker/dockerfiles/debian-native.docker             | 5 +++++
 tests/docker/dockerfiles/debian-powerpc-test-cross.docker | 6 +++++-
 tests/docker/dockerfiles/debian-riscv64-cross.docker      | 5 +++++
 tests/docker/dockerfiles/debian-riscv64-test-cross.docker | 5 +++++
 tests/docker/dockerfiles/debian-sh4-cross.docker          | 5 +++++
 tests/docker/dockerfiles/debian-sparc64-cross.docker      | 5 +++++
 tests/docker/dockerfiles/debian-toolchain.docker          | 5 +++++
 tests/docker/dockerfiles/debian-tricore-cross.docker      | 5 +++++
 tests/docker/dockerfiles/debian-xtensa-cross.docker       | 5 +++++
 tests/docker/dockerfiles/fedora-cris-cross.docker         | 5 +++++
 tests/docker/dockerfiles/fedora-i386-cross.docker         | 5 +++++
 tests/docker/dockerfiles/python.docker                    | 5 +++++
 20 files changed, 100 insertions(+), 1 deletion(-)

Comments

Daniel P. Berrangé Feb. 28, 2023, 10:40 a.m. UTC | #1
On Fri, Feb 24, 2023 at 06:08:54PM +0000, Alex Bennée wrote:
> These are flat but not generated by lcitool so we need to manually
> update them with the `useradd` stanza.
> 
> Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
> ---
>  tests/docker/dockerfiles/debian-all-test-cross.docker     | 5 +++++
>  tests/docker/dockerfiles/debian-alpha-cross.docker        | 5 +++++
>  tests/docker/dockerfiles/debian-hexagon-cross.docker      | 5 +++++
>  tests/docker/dockerfiles/debian-hppa-cross.docker         | 5 +++++
>  tests/docker/dockerfiles/debian-loongarch-cross.docker    | 5 +++++
>  tests/docker/dockerfiles/debian-m68k-cross.docker         | 5 +++++
>  tests/docker/dockerfiles/debian-mips-cross.docker         | 5 +++++
>  tests/docker/dockerfiles/debian-mips64-cross.docker       | 5 +++++
>  tests/docker/dockerfiles/debian-native.docker             | 5 +++++
>  tests/docker/dockerfiles/debian-powerpc-test-cross.docker | 6 +++++-
>  tests/docker/dockerfiles/debian-riscv64-cross.docker      | 5 +++++
>  tests/docker/dockerfiles/debian-riscv64-test-cross.docker | 5 +++++
>  tests/docker/dockerfiles/debian-sh4-cross.docker          | 5 +++++
>  tests/docker/dockerfiles/debian-sparc64-cross.docker      | 5 +++++
>  tests/docker/dockerfiles/debian-toolchain.docker          | 5 +++++
>  tests/docker/dockerfiles/debian-tricore-cross.docker      | 5 +++++
>  tests/docker/dockerfiles/debian-xtensa-cross.docker       | 5 +++++
>  tests/docker/dockerfiles/fedora-cris-cross.docker         | 5 +++++
>  tests/docker/dockerfiles/fedora-i386-cross.docker         | 5 +++++

Unrelated to this, but I mentioned in another thread, that we
should really drop the fedora-i386 and tell lcitool to generate
a debian-i386 docker file one day. There's no compelling reason
for it to be an exception and use Fedora instead of Debian.

>  tests/docker/dockerfiles/python.docker                    | 5 +++++
>  20 files changed, 100 insertions(+), 1 deletion(-)

Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>


With regards,
Daniel
Philippe Mathieu-Daudé Feb. 28, 2023, 11:43 a.m. UTC | #2
On 24/2/23 19:08, Alex Bennée wrote:
> These are flat but not generated by lcitool so we need to manually
> update them with the `useradd` stanza.
> 
> Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
> ---
>   tests/docker/dockerfiles/debian-all-test-cross.docker     | 5 +++++
>   tests/docker/dockerfiles/debian-alpha-cross.docker        | 5 +++++
>   tests/docker/dockerfiles/debian-hexagon-cross.docker      | 5 +++++
>   tests/docker/dockerfiles/debian-hppa-cross.docker         | 5 +++++
>   tests/docker/dockerfiles/debian-loongarch-cross.docker    | 5 +++++
>   tests/docker/dockerfiles/debian-m68k-cross.docker         | 5 +++++
>   tests/docker/dockerfiles/debian-mips-cross.docker         | 5 +++++
>   tests/docker/dockerfiles/debian-mips64-cross.docker       | 5 +++++
>   tests/docker/dockerfiles/debian-native.docker             | 5 +++++
>   tests/docker/dockerfiles/debian-powerpc-test-cross.docker | 6 +++++-
>   tests/docker/dockerfiles/debian-riscv64-cross.docker      | 5 +++++
>   tests/docker/dockerfiles/debian-riscv64-test-cross.docker | 5 +++++
>   tests/docker/dockerfiles/debian-sh4-cross.docker          | 5 +++++
>   tests/docker/dockerfiles/debian-sparc64-cross.docker      | 5 +++++
>   tests/docker/dockerfiles/debian-toolchain.docker          | 5 +++++
>   tests/docker/dockerfiles/debian-tricore-cross.docker      | 5 +++++
>   tests/docker/dockerfiles/debian-xtensa-cross.docker       | 5 +++++
>   tests/docker/dockerfiles/fedora-cris-cross.docker         | 5 +++++
>   tests/docker/dockerfiles/fedora-i386-cross.docker         | 5 +++++
>   tests/docker/dockerfiles/python.docker                    | 5 +++++
>   20 files changed, 100 insertions(+), 1 deletion(-)
> 
> diff --git a/tests/docker/dockerfiles/debian-all-test-cross.docker b/tests/docker/dockerfiles/debian-all-test-cross.docker
> index 8dc5e1b5de..981e9bdc7b 100644
> --- a/tests/docker/dockerfiles/debian-all-test-cross.docker
> +++ b/tests/docker/dockerfiles/debian-all-test-cross.docker
> @@ -61,3 +61,8 @@ RUN DEBIAN_FRONTEND=noninteractive eatmydata \
>   
>   ENV QEMU_CONFIGURE_OPTS --disable-system --disable-docs --disable-tools
>   ENV DEF_TARGET_LIST aarch64-linux-user,alpha-linux-user,arm-linux-user,hppa-linux-user,i386-linux-user,m68k-linux-user,mips-linux-user,mips64-linux-user,mips64el-linux-user,mipsel-linux-user,ppc-linux-user,ppc64-linux-user,ppc64le-linux-user,riscv64-linux-user,s390x-linux-user,sh4-linux-user,sparc64-linux-user
> +# As a final step configure the user (if env is defined)
> +ARG USER
> +ARG UID
> +RUN if [ "${USER}" ]; then \
> +  id ${USER} 2>/dev/null || useradd -u ${UID} -U ${USER}; fi

Is that intended for local image building?

Personally I only use the image built by gitlab and mount the containers
with -u $UID -v $HOME/.ccache -v $HOME/source/qemu. Would that still
keep working, or do I have to map from gitlab user to mine?
Daniel P. Berrangé Feb. 28, 2023, 11:45 a.m. UTC | #3
On Tue, Feb 28, 2023 at 12:43:01PM +0100, Philippe Mathieu-Daudé wrote:
> On 24/2/23 19:08, Alex Bennée wrote:
> > These are flat but not generated by lcitool so we need to manually
> > update them with the `useradd` stanza.
> > 
> > Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
> > ---
> >   tests/docker/dockerfiles/debian-all-test-cross.docker     | 5 +++++
> >   tests/docker/dockerfiles/debian-alpha-cross.docker        | 5 +++++
> >   tests/docker/dockerfiles/debian-hexagon-cross.docker      | 5 +++++
> >   tests/docker/dockerfiles/debian-hppa-cross.docker         | 5 +++++
> >   tests/docker/dockerfiles/debian-loongarch-cross.docker    | 5 +++++
> >   tests/docker/dockerfiles/debian-m68k-cross.docker         | 5 +++++
> >   tests/docker/dockerfiles/debian-mips-cross.docker         | 5 +++++
> >   tests/docker/dockerfiles/debian-mips64-cross.docker       | 5 +++++
> >   tests/docker/dockerfiles/debian-native.docker             | 5 +++++
> >   tests/docker/dockerfiles/debian-powerpc-test-cross.docker | 6 +++++-
> >   tests/docker/dockerfiles/debian-riscv64-cross.docker      | 5 +++++
> >   tests/docker/dockerfiles/debian-riscv64-test-cross.docker | 5 +++++
> >   tests/docker/dockerfiles/debian-sh4-cross.docker          | 5 +++++
> >   tests/docker/dockerfiles/debian-sparc64-cross.docker      | 5 +++++
> >   tests/docker/dockerfiles/debian-toolchain.docker          | 5 +++++
> >   tests/docker/dockerfiles/debian-tricore-cross.docker      | 5 +++++
> >   tests/docker/dockerfiles/debian-xtensa-cross.docker       | 5 +++++
> >   tests/docker/dockerfiles/fedora-cris-cross.docker         | 5 +++++
> >   tests/docker/dockerfiles/fedora-i386-cross.docker         | 5 +++++
> >   tests/docker/dockerfiles/python.docker                    | 5 +++++
> >   20 files changed, 100 insertions(+), 1 deletion(-)
> > 
> > diff --git a/tests/docker/dockerfiles/debian-all-test-cross.docker b/tests/docker/dockerfiles/debian-all-test-cross.docker
> > index 8dc5e1b5de..981e9bdc7b 100644
> > --- a/tests/docker/dockerfiles/debian-all-test-cross.docker
> > +++ b/tests/docker/dockerfiles/debian-all-test-cross.docker
> > @@ -61,3 +61,8 @@ RUN DEBIAN_FRONTEND=noninteractive eatmydata \
> >   ENV QEMU_CONFIGURE_OPTS --disable-system --disable-docs --disable-tools
> >   ENV DEF_TARGET_LIST aarch64-linux-user,alpha-linux-user,arm-linux-user,hppa-linux-user,i386-linux-user,m68k-linux-user,mips-linux-user,mips64-linux-user,mips64el-linux-user,mipsel-linux-user,ppc-linux-user,ppc64-linux-user,ppc64le-linux-user,riscv64-linux-user,s390x-linux-user,sh4-linux-user,sparc64-linux-user
> > +# As a final step configure the user (if env is defined)
> > +ARG USER
> > +ARG UID
> > +RUN if [ "${USER}" ]; then \
> > +  id ${USER} 2>/dev/null || useradd -u ${UID} -U ${USER}; fi
> 
> Is that intended for local image building?
> 
> Personally I only use the image built by gitlab and mount the containers
> with -u $UID -v $HOME/.ccache -v $HOME/source/qemu. Would that still
> keep working, or do I have to map from gitlab user to mine?

The images fetched from gitlab already have this present, as the
current docker.py  adds it to all our containers. So this should
essentially be a no functional change.

With regards,
Daniel
Alex Bennée Feb. 28, 2023, 12:18 p.m. UTC | #4
Philippe Mathieu-Daudé <philmd@linaro.org> writes:

> On 24/2/23 19:08, Alex Bennée wrote:
>> These are flat but not generated by lcitool so we need to manually
>> update them with the `useradd` stanza.
>> Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
>> ---
>>   tests/docker/dockerfiles/debian-all-test-cross.docker     | 5 +++++
>>   tests/docker/dockerfiles/debian-alpha-cross.docker        | 5 +++++
>>   tests/docker/dockerfiles/debian-hexagon-cross.docker      | 5 +++++
>>   tests/docker/dockerfiles/debian-hppa-cross.docker         | 5 +++++
>>   tests/docker/dockerfiles/debian-loongarch-cross.docker    | 5 +++++
>>   tests/docker/dockerfiles/debian-m68k-cross.docker         | 5 +++++
>>   tests/docker/dockerfiles/debian-mips-cross.docker         | 5 +++++
>>   tests/docker/dockerfiles/debian-mips64-cross.docker       | 5 +++++
>>   tests/docker/dockerfiles/debian-native.docker             | 5 +++++
>>   tests/docker/dockerfiles/debian-powerpc-test-cross.docker | 6 +++++-
>>   tests/docker/dockerfiles/debian-riscv64-cross.docker      | 5 +++++
>>   tests/docker/dockerfiles/debian-riscv64-test-cross.docker | 5 +++++
>>   tests/docker/dockerfiles/debian-sh4-cross.docker          | 5 +++++
>>   tests/docker/dockerfiles/debian-sparc64-cross.docker      | 5 +++++
>>   tests/docker/dockerfiles/debian-toolchain.docker          | 5 +++++
>>   tests/docker/dockerfiles/debian-tricore-cross.docker      | 5 +++++
>>   tests/docker/dockerfiles/debian-xtensa-cross.docker       | 5 +++++
>>   tests/docker/dockerfiles/fedora-cris-cross.docker         | 5 +++++
>>   tests/docker/dockerfiles/fedora-i386-cross.docker         | 5 +++++
>>   tests/docker/dockerfiles/python.docker                    | 5 +++++
>>   20 files changed, 100 insertions(+), 1 deletion(-)
>> diff --git a/tests/docker/dockerfiles/debian-all-test-cross.docker
>> b/tests/docker/dockerfiles/debian-all-test-cross.docker
>> index 8dc5e1b5de..981e9bdc7b 100644
>> --- a/tests/docker/dockerfiles/debian-all-test-cross.docker
>> +++ b/tests/docker/dockerfiles/debian-all-test-cross.docker
>> @@ -61,3 +61,8 @@ RUN DEBIAN_FRONTEND=noninteractive eatmydata \
>>     ENV QEMU_CONFIGURE_OPTS --disable-system --disable-docs
>> --disable-tools
>>   ENV DEF_TARGET_LIST aarch64-linux-user,alpha-linux-user,arm-linux-user,hppa-linux-user,i386-linux-user,m68k-linux-user,mips-linux-user,mips64-linux-user,mips64el-linux-user,mipsel-linux-user,ppc-linux-user,ppc64-linux-user,ppc64le-linux-user,riscv64-linux-user,s390x-linux-user,sh4-linux-user,sparc64-linux-user
>> +# As a final step configure the user (if env is defined)
>> +ARG USER
>> +ARG UID
>> +RUN if [ "${USER}" ]; then \
>> +  id ${USER} 2>/dev/null || useradd -u ${UID} -U ${USER}; fi
>
> Is that intended for local image building?

For building tests. When we run the compilers inside the docker
container we want to ensure the final binary is visible and accessible
outside the container.

> Personally I only use the image built by gitlab and mount the containers
> with -u $UID -v $HOME/.ccache -v $HOME/source/qemu. Would that still
> keep working, or do I have to map from gitlab user to mine?

Its only added on for local builds so in theory you should cache all the
layers apart from the last one.
Philippe Mathieu-Daudé Feb. 28, 2023, 12:21 p.m. UTC | #5
On 28/2/23 13:18, Alex Bennée wrote:
> 
> Philippe Mathieu-Daudé <philmd@linaro.org> writes:
> 
>> On 24/2/23 19:08, Alex Bennée wrote:
>>> These are flat but not generated by lcitool so we need to manually
>>> update them with the `useradd` stanza.
>>> Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
>>> ---
>>>    tests/docker/dockerfiles/debian-all-test-cross.docker     | 5 +++++
>>>    tests/docker/dockerfiles/debian-alpha-cross.docker        | 5 +++++
>>>    tests/docker/dockerfiles/debian-hexagon-cross.docker      | 5 +++++
>>>    tests/docker/dockerfiles/debian-hppa-cross.docker         | 5 +++++
>>>    tests/docker/dockerfiles/debian-loongarch-cross.docker    | 5 +++++
>>>    tests/docker/dockerfiles/debian-m68k-cross.docker         | 5 +++++
>>>    tests/docker/dockerfiles/debian-mips-cross.docker         | 5 +++++
>>>    tests/docker/dockerfiles/debian-mips64-cross.docker       | 5 +++++
>>>    tests/docker/dockerfiles/debian-native.docker             | 5 +++++
>>>    tests/docker/dockerfiles/debian-powerpc-test-cross.docker | 6 +++++-
>>>    tests/docker/dockerfiles/debian-riscv64-cross.docker      | 5 +++++
>>>    tests/docker/dockerfiles/debian-riscv64-test-cross.docker | 5 +++++
>>>    tests/docker/dockerfiles/debian-sh4-cross.docker          | 5 +++++
>>>    tests/docker/dockerfiles/debian-sparc64-cross.docker      | 5 +++++
>>>    tests/docker/dockerfiles/debian-toolchain.docker          | 5 +++++
>>>    tests/docker/dockerfiles/debian-tricore-cross.docker      | 5 +++++
>>>    tests/docker/dockerfiles/debian-xtensa-cross.docker       | 5 +++++
>>>    tests/docker/dockerfiles/fedora-cris-cross.docker         | 5 +++++
>>>    tests/docker/dockerfiles/fedora-i386-cross.docker         | 5 +++++
>>>    tests/docker/dockerfiles/python.docker                    | 5 +++++
>>>    20 files changed, 100 insertions(+), 1 deletion(-)
>>> diff --git a/tests/docker/dockerfiles/debian-all-test-cross.docker
>>> b/tests/docker/dockerfiles/debian-all-test-cross.docker
>>> index 8dc5e1b5de..981e9bdc7b 100644
>>> --- a/tests/docker/dockerfiles/debian-all-test-cross.docker
>>> +++ b/tests/docker/dockerfiles/debian-all-test-cross.docker
>>> @@ -61,3 +61,8 @@ RUN DEBIAN_FRONTEND=noninteractive eatmydata \
>>>      ENV QEMU_CONFIGURE_OPTS --disable-system --disable-docs
>>> --disable-tools
>>>    ENV DEF_TARGET_LIST aarch64-linux-user,alpha-linux-user,arm-linux-user,hppa-linux-user,i386-linux-user,m68k-linux-user,mips-linux-user,mips64-linux-user,mips64el-linux-user,mipsel-linux-user,ppc-linux-user,ppc64-linux-user,ppc64le-linux-user,riscv64-linux-user,s390x-linux-user,sh4-linux-user,sparc64-linux-user
>>> +# As a final step configure the user (if env is defined)
>>> +ARG USER
>>> +ARG UID
>>> +RUN if [ "${USER}" ]; then \
>>> +  id ${USER} 2>/dev/null || useradd -u ${UID} -U ${USER}; fi
>>
>> Is that intended for local image building?
> 
> For building tests. When we run the compilers inside the docker
> container we want to ensure the final binary is visible and accessible
> outside the container.
> 
>> Personally I only use the image built by gitlab and mount the containers
>> with -u $UID -v $HOME/.ccache -v $HOME/source/qemu. Would that still
>> keep working, or do I have to map from gitlab user to mine?
> 
> Its only added on for local builds so in theory you should cache all the
> layers apart from the last one.

OK.

Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
diff mbox series

Patch

diff --git a/tests/docker/dockerfiles/debian-all-test-cross.docker b/tests/docker/dockerfiles/debian-all-test-cross.docker
index 8dc5e1b5de..981e9bdc7b 100644
--- a/tests/docker/dockerfiles/debian-all-test-cross.docker
+++ b/tests/docker/dockerfiles/debian-all-test-cross.docker
@@ -61,3 +61,8 @@  RUN DEBIAN_FRONTEND=noninteractive eatmydata \
 
 ENV QEMU_CONFIGURE_OPTS --disable-system --disable-docs --disable-tools
 ENV DEF_TARGET_LIST aarch64-linux-user,alpha-linux-user,arm-linux-user,hppa-linux-user,i386-linux-user,m68k-linux-user,mips-linux-user,mips64-linux-user,mips64el-linux-user,mipsel-linux-user,ppc-linux-user,ppc64-linux-user,ppc64le-linux-user,riscv64-linux-user,s390x-linux-user,sh4-linux-user,sparc64-linux-user
+# As a final step configure the user (if env is defined)
+ARG USER
+ARG UID
+RUN if [ "${USER}" ]; then \
+  id ${USER} 2>/dev/null || useradd -u ${UID} -U ${USER}; fi
diff --git a/tests/docker/dockerfiles/debian-alpha-cross.docker b/tests/docker/dockerfiles/debian-alpha-cross.docker
index 4eeb43c78a..7fa7bf1bde 100644
--- a/tests/docker/dockerfiles/debian-alpha-cross.docker
+++ b/tests/docker/dockerfiles/debian-alpha-cross.docker
@@ -12,3 +12,8 @@  RUN export DEBIAN_FRONTEND=noninteractive && \
     eatmydata apt-get install --no-install-recommends -y \
         gcc-alpha-linux-gnu \
         libc6.1-dev-alpha-cross
+# As a final step configure the user (if env is defined)
+ARG USER
+ARG UID
+RUN if [ "${USER}" ]; then \
+  id ${USER} 2>/dev/null || useradd -u ${UID} -U ${USER}; fi
diff --git a/tests/docker/dockerfiles/debian-hexagon-cross.docker b/tests/docker/dockerfiles/debian-hexagon-cross.docker
index 8a0d748343..5308ccb8fe 100644
--- a/tests/docker/dockerfiles/debian-hexagon-cross.docker
+++ b/tests/docker/dockerfiles/debian-hexagon-cross.docker
@@ -33,3 +33,8 @@  ENV TOOLCHAIN_URL https://codelinaro.jfrog.io/artifactory/codelinaro-toolchain-f
 
 RUN curl -#SL "$TOOLCHAIN_URL" | tar -xJC "$TOOLCHAIN_INSTALL"
 ENV PATH $PATH:${TOOLCHAIN_INSTALL}/${TOOLCHAIN_BASENAME}/x86_64-linux-gnu/bin
+# As a final step configure the user (if env is defined)
+ARG USER
+ARG UID
+RUN if [ "${USER}" ]; then \
+  id ${USER} 2>/dev/null || useradd -u ${UID} -U ${USER}; fi
diff --git a/tests/docker/dockerfiles/debian-hppa-cross.docker b/tests/docker/dockerfiles/debian-hppa-cross.docker
index af1c8403d8..dd47ffdfa4 100644
--- a/tests/docker/dockerfiles/debian-hppa-cross.docker
+++ b/tests/docker/dockerfiles/debian-hppa-cross.docker
@@ -12,3 +12,8 @@  RUN export DEBIAN_FRONTEND=noninteractive && \
     eatmydata apt-get install --no-install-recommends -y \
         gcc-hppa-linux-gnu \
         libc6-dev-hppa-cross
+# As a final step configure the user (if env is defined)
+ARG USER
+ARG UID
+RUN if [ "${USER}" ]; then \
+  id ${USER} 2>/dev/null || useradd -u ${UID} -U ${USER}; fi
diff --git a/tests/docker/dockerfiles/debian-loongarch-cross.docker b/tests/docker/dockerfiles/debian-loongarch-cross.docker
index a8e8e98909..9d957547b5 100644
--- a/tests/docker/dockerfiles/debian-loongarch-cross.docker
+++ b/tests/docker/dockerfiles/debian-loongarch-cross.docker
@@ -25,3 +25,8 @@  RUN curl -#SL https://github.com/loongson/build-tools/releases/download/2022.05.
 
 ENV PATH $PATH:/opt/cross-tools/bin
 ENV LD_LIBRARY_PATH /opt/cross-tools/lib:/opt/cross-tools/loongarch64-unknown-linux-gnu/lib:$LD_LIBRARY_PATH
+# As a final step configure the user (if env is defined)
+ARG USER
+ARG UID
+RUN if [ "${USER}" ]; then \
+  id ${USER} 2>/dev/null || useradd -u ${UID} -U ${USER}; fi
diff --git a/tests/docker/dockerfiles/debian-m68k-cross.docker b/tests/docker/dockerfiles/debian-m68k-cross.docker
index dded71c5d2..25dd1c1e68 100644
--- a/tests/docker/dockerfiles/debian-m68k-cross.docker
+++ b/tests/docker/dockerfiles/debian-m68k-cross.docker
@@ -12,3 +12,8 @@  RUN export DEBIAN_FRONTEND=noninteractive && \
     eatmydata apt-get install --no-install-recommends -y \
         gcc-m68k-linux-gnu \
         libc6-dev-m68k-cross
+# As a final step configure the user (if env is defined)
+ARG USER
+ARG UID
+RUN if [ "${USER}" ]; then \
+  id ${USER} 2>/dev/null || useradd -u ${UID} -U ${USER}; fi
diff --git a/tests/docker/dockerfiles/debian-mips-cross.docker b/tests/docker/dockerfiles/debian-mips-cross.docker
index 7b55f0f3b2..2cbc568ed1 100644
--- a/tests/docker/dockerfiles/debian-mips-cross.docker
+++ b/tests/docker/dockerfiles/debian-mips-cross.docker
@@ -12,3 +12,8 @@  RUN export DEBIAN_FRONTEND=noninteractive && \
     eatmydata apt-get install --no-install-recommends -y \
             gcc-mips-linux-gnu \
             libc6-dev-mips-cross
+# As a final step configure the user (if env is defined)
+ARG USER
+ARG UID
+RUN if [ "${USER}" ]; then \
+  id ${USER} 2>/dev/null || useradd -u ${UID} -U ${USER}; fi
diff --git a/tests/docker/dockerfiles/debian-mips64-cross.docker b/tests/docker/dockerfiles/debian-mips64-cross.docker
index afcff9726f..ba965cf564 100644
--- a/tests/docker/dockerfiles/debian-mips64-cross.docker
+++ b/tests/docker/dockerfiles/debian-mips64-cross.docker
@@ -12,3 +12,8 @@  RUN export DEBIAN_FRONTEND=noninteractive && \
     eatmydata apt-get install --no-install-recommends -y \
         gcc-mips64-linux-gnuabi64 \
         libc6-dev-mips64-cross
+# As a final step configure the user (if env is defined)
+ARG USER
+ARG UID
+RUN if [ "${USER}" ]; then \
+  id ${USER} 2>/dev/null || useradd -u ${UID} -U ${USER}; fi
diff --git a/tests/docker/dockerfiles/debian-native.docker b/tests/docker/dockerfiles/debian-native.docker
index 8dd033097c..abac7d7cd7 100644
--- a/tests/docker/dockerfiles/debian-native.docker
+++ b/tests/docker/dockerfiles/debian-native.docker
@@ -47,3 +47,8 @@  RUN apt update && \
 
 ENV QEMU_CONFIGURE_OPTS $QEMU_CONFIGURE_OPTS
 ENV DEF_TARGET_LIST "none"
+# As a final step configure the user (if env is defined)
+ARG USER
+ARG UID
+RUN if [ "${USER}" ]; then \
+  id ${USER} 2>/dev/null || useradd -u ${UID} -U ${USER}; fi
diff --git a/tests/docker/dockerfiles/debian-powerpc-test-cross.docker b/tests/docker/dockerfiles/debian-powerpc-test-cross.docker
index d6b2909cc4..23779413d3 100644
--- a/tests/docker/dockerfiles/debian-powerpc-test-cross.docker
+++ b/tests/docker/dockerfiles/debian-powerpc-test-cross.docker
@@ -16,4 +16,8 @@  RUN export DEBIAN_FRONTEND=noninteractive && \
         libc6-dev-ppc64-cross \
         gcc-10-powerpc64le-linux-gnu \
         libc6-dev-ppc64el-cross
-
+# As a final step configure the user (if env is defined)
+ARG USER
+ARG UID
+RUN if [ "${USER}" ]; then \
+  id ${USER} 2>/dev/null || useradd -u ${UID} -U ${USER}; fi
diff --git a/tests/docker/dockerfiles/debian-riscv64-cross.docker b/tests/docker/dockerfiles/debian-riscv64-cross.docker
index 3daf93968a..803afb9573 100644
--- a/tests/docker/dockerfiles/debian-riscv64-cross.docker
+++ b/tests/docker/dockerfiles/debian-riscv64-cross.docker
@@ -50,3 +50,8 @@  RUN apt update && \
 # Specify the cross prefix for this image (see tests/docker/common.rc)
 ENV QEMU_CONFIGURE_OPTS --cross-prefix=riscv64-linux-gnu-
 ENV DEF_TARGET_LIST riscv64-softmmu,riscv64-linux-user
+# As a final step configure the user (if env is defined)
+ARG USER
+ARG UID
+RUN if [ "${USER}" ]; then \
+  id ${USER} 2>/dev/null || useradd -u ${UID} -U ${USER}; fi
diff --git a/tests/docker/dockerfiles/debian-riscv64-test-cross.docker b/tests/docker/dockerfiles/debian-riscv64-test-cross.docker
index e5f83a5aeb..6e631295bc 100644
--- a/tests/docker/dockerfiles/debian-riscv64-test-cross.docker
+++ b/tests/docker/dockerfiles/debian-riscv64-test-cross.docker
@@ -12,3 +12,8 @@  RUN export DEBIAN_FRONTEND=noninteractive && \
     eatmydata apt-get install --no-install-recommends -y \
         gcc-riscv64-linux-gnu \
         libc6-dev-riscv64-cross
+# As a final step configure the user (if env is defined)
+ARG USER
+ARG UID
+RUN if [ "${USER}" ]; then \
+  id ${USER} 2>/dev/null || useradd -u ${UID} -U ${USER}; fi
diff --git a/tests/docker/dockerfiles/debian-sh4-cross.docker b/tests/docker/dockerfiles/debian-sh4-cross.docker
index d48ed9065f..6bd8171d33 100644
--- a/tests/docker/dockerfiles/debian-sh4-cross.docker
+++ b/tests/docker/dockerfiles/debian-sh4-cross.docker
@@ -12,3 +12,8 @@  RUN export DEBIAN_FRONTEND=noninteractive && \
     eatmydata apt-get install --no-install-recommends -y \
         gcc-sh4-linux-gnu \
         libc6-dev-sh4-cross
+# As a final step configure the user (if env is defined)
+ARG USER
+ARG UID
+RUN if [ "${USER}" ]; then \
+  id ${USER} 2>/dev/null || useradd -u ${UID} -U ${USER}; fi
diff --git a/tests/docker/dockerfiles/debian-sparc64-cross.docker b/tests/docker/dockerfiles/debian-sparc64-cross.docker
index 8d3d306bc1..1ef735f223 100644
--- a/tests/docker/dockerfiles/debian-sparc64-cross.docker
+++ b/tests/docker/dockerfiles/debian-sparc64-cross.docker
@@ -12,3 +12,8 @@  RUN export DEBIAN_FRONTEND=noninteractive && \
     eatmydata apt-get install --no-install-recommends -y \
         gcc-sparc64-linux-gnu \
         libc6-dev-sparc64-cross
+# As a final step configure the user (if env is defined)
+ARG USER
+ARG UID
+RUN if [ "${USER}" ]; then \
+  id ${USER} 2>/dev/null || useradd -u ${UID} -U ${USER}; fi
diff --git a/tests/docker/dockerfiles/debian-toolchain.docker b/tests/docker/dockerfiles/debian-toolchain.docker
index dc9545857f..687a97fec4 100644
--- a/tests/docker/dockerfiles/debian-toolchain.docker
+++ b/tests/docker/dockerfiles/debian-toolchain.docker
@@ -34,3 +34,8 @@  RUN cd /root && ./build-toolchain.sh
 # then copying the built toolchain from stage 0.
 FROM docker.io/library/debian:11-slim
 COPY --from=0 /usr/local /usr/local
+# As a final step configure the user (if env is defined)
+ARG USER
+ARG UID
+RUN if [ "${USER}" ]; then \
+  id ${USER} 2>/dev/null || useradd -u ${UID} -U ${USER}; fi
diff --git a/tests/docker/dockerfiles/debian-tricore-cross.docker b/tests/docker/dockerfiles/debian-tricore-cross.docker
index 82e4576485..cfd2faf9a8 100644
--- a/tests/docker/dockerfiles/debian-tricore-cross.docker
+++ b/tests/docker/dockerfiles/debian-tricore-cross.docker
@@ -41,3 +41,8 @@  RUN curl -#SL https://github.com/bkoppelmann/package_940/releases/download/trico
 # This image can only build a very minimal QEMU as well as the tests
 ENV DEF_TARGET_LIST tricore-softmmu
 ENV QEMU_CONFIGURE_OPTS --disable-user --disable-tools --disable-fdt
+# As a final step configure the user (if env is defined)
+ARG USER
+ARG UID
+RUN if [ "${USER}" ]; then \
+  id ${USER} 2>/dev/null || useradd -u ${UID} -U ${USER}; fi
diff --git a/tests/docker/dockerfiles/debian-xtensa-cross.docker b/tests/docker/dockerfiles/debian-xtensa-cross.docker
index 2f11b3b7bc..082b50da19 100644
--- a/tests/docker/dockerfiles/debian-xtensa-cross.docker
+++ b/tests/docker/dockerfiles/debian-xtensa-cross.docker
@@ -27,3 +27,8 @@  RUN for cpu in $CPU_LIST; do \
     done
 
 ENV PATH $PATH:/opt/$TOOLCHAIN_RELEASE/xtensa-dc232b-elf/bin:/opt/$TOOLCHAIN_RELEASE/xtensa-dc233c-elf/bin:/opt/$TOOLCHAIN_RELEASE/xtensa-de233_fpu-elf/bin:/opt/$TOOLCHAIN_RELEASE/xtensa-dsp3400-elf/bin
+# As a final step configure the user (if env is defined)
+ARG USER
+ARG UID
+RUN if [ "${USER}" ]; then \
+  id ${USER} 2>/dev/null || useradd -u ${UID} -U ${USER}; fi
diff --git a/tests/docker/dockerfiles/fedora-cris-cross.docker b/tests/docker/dockerfiles/fedora-cris-cross.docker
index 91c373fdd3..f2899af410 100644
--- a/tests/docker/dockerfiles/fedora-cris-cross.docker
+++ b/tests/docker/dockerfiles/fedora-cris-cross.docker
@@ -6,3 +6,8 @@  FROM registry.fedoraproject.org/fedora:33
 ENV PACKAGES gcc-cris-linux-gnu
 RUN dnf install -y $PACKAGES
 RUN rpm -q $PACKAGES | sort > /packages.txt
+# As a final step configure the user (if env is defined)
+ARG USER
+ARG UID
+RUN if [ "${USER}" ]; then \
+  id ${USER} 2>/dev/null || useradd -u ${UID} -U ${USER}; fi
diff --git a/tests/docker/dockerfiles/fedora-i386-cross.docker b/tests/docker/dockerfiles/fedora-i386-cross.docker
index f58b64dc3e..14c1fb2c93 100644
--- a/tests/docker/dockerfiles/fedora-i386-cross.docker
+++ b/tests/docker/dockerfiles/fedora-i386-cross.docker
@@ -32,3 +32,8 @@  ENV PKG_CONFIG_LIBDIR /usr/lib/pkgconfig
 
 RUN dnf update -y && dnf install -y $PACKAGES
 RUN rpm -q $PACKAGES | sort > /packages.txt
+# As a final step configure the user (if env is defined)
+ARG USER
+ARG UID
+RUN if [ "${USER}" ]; then \
+  id ${USER} 2>/dev/null || useradd -u ${UID} -U ${USER}; fi
diff --git a/tests/docker/dockerfiles/python.docker b/tests/docker/dockerfiles/python.docker
index 56d88417df..708ebbed75 100644
--- a/tests/docker/dockerfiles/python.docker
+++ b/tests/docker/dockerfiles/python.docker
@@ -16,3 +16,8 @@  ENV PACKAGES \
 
 RUN dnf install -y $PACKAGES
 RUN rpm -q $PACKAGES | sort > /packages.txt
+# As a final step configure the user (if env is defined)
+ARG USER
+ARG UID
+RUN if [ "${USER}" ]; then \
+  id ${USER} 2>/dev/null || useradd -u ${UID} -U ${USER}; fi