Skip to content

Commit 447c7cf

Browse files
committed
build: Dockerfile: mod "new user to avoid using root" to support UID=0
Extend "create new user to avoid using root" copypasta to support being run as root (ARG UID=0). When running build.sh directly on a cirrus CI runner, we are running as root.
1 parent b676c1e commit 447c7cf

File tree

4 files changed

+26
-30
lines changed

4 files changed

+26
-30
lines changed

contrib/android/Dockerfile

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -174,17 +174,16 @@ RUN apt -y update -qq \
174174

175175
# create new user to avoid using root; but with sudo access and no password for convenience.
176176
ARG UID=1000
177-
ENV USER="user"
178-
ENV HOME_DIR="/home/${USER}"
177+
RUN if [ "$UID" != "0" ] ; then useradd --uid $UID --create-home --shell /bin/bash "user" ; fi
178+
RUN usermod -append --groups sudo $(id -nu $UID || echo "user")
179+
RUN echo "%sudo ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers
180+
RUN HOME_DIR=$(getent passwd $UID | cut -d: -f6)
179181
ENV WORK_DIR="${HOME_DIR}/wspace" \
180182
PATH="${HOME_DIR}/.local/bin:${PATH}"
181-
RUN useradd --uid $UID --create-home --shell /bin/bash ${USER}
182-
RUN usermod -append --groups sudo ${USER}
183-
RUN echo "%sudo ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers
184183
WORKDIR ${WORK_DIR}
185-
RUN chown --recursive ${USER} ${WORK_DIR} ${ANDROID_SDK_HOME}
186-
RUN chown ${USER} /opt
187-
USER ${USER}
184+
RUN chown --recursive ${UID} ${WORK_DIR} ${ANDROID_SDK_HOME}
185+
RUN chown ${UID} /opt
186+
USER ${UID}
188187

189188
# venv, VIRTUAL_ENV is used by buildozer to indicate a venv environment
190189
ENV VIRTUAL_ENV=/opt/venv

contrib/build-linux/appimage/Dockerfile

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -75,13 +75,12 @@ RUN apt-get update -q && \
7575

7676
# create new user to avoid using root; but with sudo access and no password for convenience.
7777
ARG UID=1000
78-
ENV USER="user"
79-
ENV HOME_DIR="/home/${USER}"
78+
RUN if [ "$UID" != "0" ] ; then useradd --uid $UID --create-home --shell /bin/bash "user" ; fi
79+
RUN usermod -append --groups sudo $(id -nu $UID || echo "user")
80+
RUN echo "%sudo ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers
81+
RUN HOME_DIR=$(getent passwd $UID | cut -d: -f6)
8082
ENV WORK_DIR="${HOME_DIR}/wspace" \
8183
PATH="${HOME_DIR}/.local/bin:${PATH}"
82-
RUN useradd --uid $UID --create-home --shell /bin/bash ${USER}
83-
RUN usermod -append --groups sudo ${USER}
84-
RUN echo "%sudo ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers
8584
WORKDIR ${WORK_DIR}
86-
RUN chown --recursive ${USER} ${WORK_DIR}
87-
USER ${USER}
85+
RUN chown --recursive ${UID} ${WORK_DIR}
86+
USER ${UID}

contrib/build-linux/sdist/Dockerfile

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,12 @@ RUN apt-get update -q && \
1818

1919
# create new user to avoid using root; but with sudo access and no password for convenience.
2020
ARG UID=1000
21-
ENV USER="user"
22-
ENV HOME_DIR="/home/${USER}"
21+
RUN if [ "$UID" != "0" ] ; then useradd --uid $UID --create-home --shell /bin/bash "user" ; fi
22+
RUN usermod -append --groups sudo $(id -nu $UID || echo "user")
23+
RUN echo "%sudo ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers
24+
RUN HOME_DIR=$(getent passwd $UID | cut -d: -f6)
2325
ENV WORK_DIR="${HOME_DIR}/wspace" \
2426
PATH="${HOME_DIR}/.local/bin:${PATH}"
25-
RUN useradd --uid $UID --create-home --shell /bin/bash ${USER}
26-
RUN usermod -append --groups sudo ${USER}
27-
RUN echo "%sudo ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers
2827
WORKDIR ${WORK_DIR}
29-
RUN chown --recursive ${USER} ${WORK_DIR}
30-
USER ${USER}
28+
RUN chown --recursive ${UID} ${WORK_DIR}
29+
USER ${UID}

contrib/build-wine/Dockerfile

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -58,16 +58,15 @@ RUN DEBIAN_CODENAME=$(lsb_release --codename --short) && \
5858

5959
# create new user to avoid using root; but with sudo access and no password for convenience.
6060
ARG UID=1000
61-
ENV USER="user"
62-
ENV HOME_DIR="/home/${USER}"
61+
RUN if [ "$UID" != "0" ] ; then useradd --uid $UID --create-home --shell /bin/bash "user" ; fi
62+
RUN usermod -append --groups sudo $(id -nu $UID || echo "user")
63+
RUN echo "%sudo ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers
64+
RUN HOME_DIR=$(getent passwd $UID | cut -d: -f6)
6365
ENV WORK_DIR="${HOME_DIR}/wspace" \
6466
PATH="${HOME_DIR}/.local/bin:${PATH}"
65-
RUN useradd --uid $UID --create-home --shell /bin/bash ${USER}
66-
RUN usermod -append --groups sudo ${USER}
67-
RUN echo "%sudo ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers
6867
WORKDIR ${WORK_DIR}
69-
RUN chown --recursive ${USER} ${WORK_DIR}
70-
RUN chown ${USER} /opt
71-
USER ${USER}
68+
RUN chown --recursive ${UID} ${WORK_DIR}
69+
RUN chown ${UID} /opt
70+
USER ${UID}
7271

7372
RUN mkdir --parents "/opt/wine64/drive_c/electrum"

0 commit comments

Comments
 (0)