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.
This commit is contained in:
@@ -75,13 +75,12 @@ RUN apt-get update -q && \
|
||||
|
||||
# create new user to avoid using root; but with sudo access and no password for convenience.
|
||||
ARG UID=1000
|
||||
ENV USER="user"
|
||||
ENV HOME_DIR="/home/${USER}"
|
||||
RUN if [ "$UID" != "0" ] ; then useradd --uid $UID --create-home --shell /bin/bash "user" ; fi
|
||||
RUN usermod -append --groups sudo $(id -nu $UID || echo "user")
|
||||
RUN echo "%sudo ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers
|
||||
RUN HOME_DIR=$(getent passwd $UID | cut -d: -f6)
|
||||
ENV WORK_DIR="${HOME_DIR}/wspace" \
|
||||
PATH="${HOME_DIR}/.local/bin:${PATH}"
|
||||
RUN useradd --uid $UID --create-home --shell /bin/bash ${USER}
|
||||
RUN usermod -append --groups sudo ${USER}
|
||||
RUN echo "%sudo ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers
|
||||
WORKDIR ${WORK_DIR}
|
||||
RUN chown --recursive ${USER} ${WORK_DIR}
|
||||
USER ${USER}
|
||||
RUN chown --recursive ${UID} ${WORK_DIR}
|
||||
USER ${UID}
|
||||
|
||||
@@ -18,13 +18,12 @@ RUN apt-get update -q && \
|
||||
|
||||
# create new user to avoid using root; but with sudo access and no password for convenience.
|
||||
ARG UID=1000
|
||||
ENV USER="user"
|
||||
ENV HOME_DIR="/home/${USER}"
|
||||
RUN if [ "$UID" != "0" ] ; then useradd --uid $UID --create-home --shell /bin/bash "user" ; fi
|
||||
RUN usermod -append --groups sudo $(id -nu $UID || echo "user")
|
||||
RUN echo "%sudo ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers
|
||||
RUN HOME_DIR=$(getent passwd $UID | cut -d: -f6)
|
||||
ENV WORK_DIR="${HOME_DIR}/wspace" \
|
||||
PATH="${HOME_DIR}/.local/bin:${PATH}"
|
||||
RUN useradd --uid $UID --create-home --shell /bin/bash ${USER}
|
||||
RUN usermod -append --groups sudo ${USER}
|
||||
RUN echo "%sudo ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers
|
||||
WORKDIR ${WORK_DIR}
|
||||
RUN chown --recursive ${USER} ${WORK_DIR}
|
||||
USER ${USER}
|
||||
RUN chown --recursive ${UID} ${WORK_DIR}
|
||||
USER ${UID}
|
||||
|
||||
Reference in New Issue
Block a user