Browse Source

build: rm need for sudo in most places; and do not run as root

This includes two logically separate changes:
- on the host, try not to require sudo when running the build scripts
    - namely when interacting with the docker daemon, this requires
      the unix user on the host to be part of the `docker` group
    - this solves part of https://github.com/spesmilo/electrum/issues/7602
- while running inside the docker containers, do not run as root
    - this means that e.g. files created in mounted folders should
      no longer be owned by root on the host
    - there is some code duplication involved here - not sure
      how it could be deduped.
patch-4
SomberNight 3 years ago
parent
commit
0df8392c86
No known key found for this signature in database GPG Key ID: B33B5F232C6271E9
  1. 17
      contrib/android/Dockerfile
  2. 8
      contrib/android/build.sh
  3. 12
      contrib/build-linux/appimage/Dockerfile
  4. 8
      contrib/build-linux/appimage/build.sh
  5. 12
      contrib/build-linux/sdist/Dockerfile
  6. 8
      contrib/build-linux/sdist/build.sh
  7. 15
      contrib/build-wine/Dockerfile
  8. 4
      contrib/build-wine/build-electrum-git.sh
  9. 8
      contrib/build-wine/build.sh
  10. 2
      contrib/build-wine/make_win.sh
  11. 2
      contrib/make_libusb.sh

17
contrib/android/Dockerfile

@ -94,11 +94,6 @@ RUN curl --location --progress-bar \
&& rm -rf "${APACHE_ANT_ARCHIVE}" && rm -rf "${APACHE_ANT_ARCHIVE}"
ENV USER="user"
ENV HOME_DIR="/home/${USER}"
ENV WORK_DIR="${HOME_DIR}/wspace" \
PATH="${HOME_DIR}/.local/bin:${PATH}"
# install system/build dependencies # install system/build dependencies
# https://github.com/kivy/buildozer/blob/master/docs/source/installation.rst#android-on-ubuntu-2004-64bit # https://github.com/kivy/buildozer/blob/master/docs/source/installation.rst#android-on-ubuntu-2004-64bit
# TODO probably need to pin versions of at least some of these for over-time reproducibility? # TODO probably need to pin versions of at least some of these for over-time reproducibility?
@ -136,17 +131,15 @@ RUN apt -y update -qq \
&& apt -y clean && apt -y clean
# prepare non root env # create new user to avoid using root; but with sudo access and no password for convenience.
ENV USER="user"
ENV HOME_DIR="/home/${USER}"
ENV WORK_DIR="${HOME_DIR}/wspace" \
PATH="${HOME_DIR}/.local/bin:${PATH}"
RUN useradd --create-home --shell /bin/bash ${USER} RUN useradd --create-home --shell /bin/bash ${USER}
# with sudo access and no password
RUN usermod -append --groups sudo ${USER} RUN usermod -append --groups sudo ${USER}
RUN echo "%sudo ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers RUN echo "%sudo ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers
WORKDIR ${WORK_DIR} WORKDIR ${WORK_DIR}
# user needs ownership/write access to these directories
RUN chown --recursive ${USER} ${WORK_DIR} ${ANDROID_SDK_HOME} RUN chown --recursive ${USER} ${WORK_DIR} ${ANDROID_SDK_HOME}
RUN chown ${USER} /opt RUN chown ${USER} /opt
USER ${USER} USER ${USER}

8
contrib/android/build.sh

@ -22,7 +22,7 @@ if [ ! -z "$ELECBUILD_NOCACHE" ] ; then
fi fi
info "building docker image." info "building docker image."
sudo docker build \ docker build \
$DOCKER_BUILD_FLAGS \ $DOCKER_BUILD_FLAGS \
-t electrum-android-builder-img \ -t electrum-android-builder-img \
--file "$CONTRIB_ANDROID/Dockerfile" \ --file "$CONTRIB_ANDROID/Dockerfile" \
@ -33,7 +33,7 @@ sudo docker build \
if [ ! -z "$ELECBUILD_COMMIT" ] ; then if [ ! -z "$ELECBUILD_COMMIT" ] ; then
info "ELECBUILD_COMMIT=$ELECBUILD_COMMIT. doing fresh clone and git checkout." info "ELECBUILD_COMMIT=$ELECBUILD_COMMIT. doing fresh clone and git checkout."
FRESH_CLONE="$CONTRIB_ANDROID/fresh_clone/electrum" && \ FRESH_CLONE="$CONTRIB_ANDROID/fresh_clone/electrum" && \
sudo rm -rf "$FRESH_CLONE" && \ rm -rf "$FRESH_CLONE" && \
umask 0022 && \ umask 0022 && \
git clone "$PROJECT_ROOT" "$FRESH_CLONE" && \ git clone "$PROJECT_ROOT" "$FRESH_CLONE" && \
cd "$FRESH_CLONE" cd "$FRESH_CLONE"
@ -51,7 +51,7 @@ fi
info "building binary..." info "building binary..."
mkdir --parents "$PROJECT_ROOT_OR_FRESHCLONE_ROOT"/.buildozer/.gradle mkdir --parents "$PROJECT_ROOT_OR_FRESHCLONE_ROOT"/.buildozer/.gradle
sudo docker run -it --rm \ docker run -it --rm \
--name electrum-android-builder-cont \ --name electrum-android-builder-cont \
-v "$PROJECT_ROOT_OR_FRESHCLONE_ROOT":/home/user/wspace/electrum \ -v "$PROJECT_ROOT_OR_FRESHCLONE_ROOT":/home/user/wspace/electrum \
-v "$PROJECT_ROOT_OR_FRESHCLONE_ROOT"/.buildozer/.gradle:/home/user/.gradle \ -v "$PROJECT_ROOT_OR_FRESHCLONE_ROOT"/.buildozer/.gradle:/home/user/.gradle \
@ -63,5 +63,5 @@ sudo docker run -it --rm \
# make sure resulting binary location is independent of fresh_clone # make sure resulting binary location is independent of fresh_clone
if [ ! -z "$ELECBUILD_COMMIT" ] ; then if [ ! -z "$ELECBUILD_COMMIT" ] ; then
mkdir --parents "$DISTDIR/" mkdir --parents "$DISTDIR/"
sudo cp -f "$FRESH_CLONE/dist"/* "$DISTDIR/" cp -f "$FRESH_CLONE/dist"/* "$DISTDIR/"
fi fi

12
contrib/build-linux/appimage/Dockerfile

@ -56,3 +56,15 @@ RUN apt-get update -q && \
rm -rf /var/lib/apt/lists/* && \ rm -rf /var/lib/apt/lists/* && \
apt-get autoremove -y && \ apt-get autoremove -y && \
apt-get clean apt-get clean
# create new user to avoid using root; but with sudo access and no password for convenience.
ENV USER="user"
ENV HOME_DIR="/home/${USER}"
ENV WORK_DIR="${HOME_DIR}/wspace" \
PATH="${HOME_DIR}/.local/bin:${PATH}"
RUN useradd --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}

8
contrib/build-linux/appimage/build.sh

@ -22,7 +22,7 @@ if [ ! -z "$ELECBUILD_NOCACHE" ] ; then
fi fi
info "building docker image." info "building docker image."
sudo docker build \ docker build \
$DOCKER_BUILD_FLAGS \ $DOCKER_BUILD_FLAGS \
-t electrum-appimage-builder-img \ -t electrum-appimage-builder-img \
"$CONTRIB_APPIMAGE" "$CONTRIB_APPIMAGE"
@ -31,7 +31,7 @@ sudo docker build \
if [ ! -z "$ELECBUILD_COMMIT" ] ; then if [ ! -z "$ELECBUILD_COMMIT" ] ; then
info "ELECBUILD_COMMIT=$ELECBUILD_COMMIT. doing fresh clone and git checkout." info "ELECBUILD_COMMIT=$ELECBUILD_COMMIT. doing fresh clone and git checkout."
FRESH_CLONE="$CONTRIB_APPIMAGE/fresh_clone/electrum" && \ FRESH_CLONE="$CONTRIB_APPIMAGE/fresh_clone/electrum" && \
sudo rm -rf "$FRESH_CLONE" && \ rm -rf "$FRESH_CLONE" && \
umask 0022 && \ umask 0022 && \
git clone "$PROJECT_ROOT" "$FRESH_CLONE" && \ git clone "$PROJECT_ROOT" "$FRESH_CLONE" && \
cd "$FRESH_CLONE" cd "$FRESH_CLONE"
@ -42,7 +42,7 @@ else
fi fi
info "building binary..." info "building binary..."
sudo docker run -it \ docker run -it \
--name electrum-appimage-builder-cont \ --name electrum-appimage-builder-cont \
-v "$PROJECT_ROOT_OR_FRESHCLONE_ROOT":/opt/electrum \ -v "$PROJECT_ROOT_OR_FRESHCLONE_ROOT":/opt/electrum \
--rm \ --rm \
@ -53,5 +53,5 @@ sudo docker run -it \
# make sure resulting binary location is independent of fresh_clone # make sure resulting binary location is independent of fresh_clone
if [ ! -z "$ELECBUILD_COMMIT" ] ; then if [ ! -z "$ELECBUILD_COMMIT" ] ; then
mkdir --parents "$DISTDIR/" mkdir --parents "$DISTDIR/"
sudo cp -f "$FRESH_CLONE/dist"/* "$DISTDIR/" cp -f "$FRESH_CLONE/dist"/* "$DISTDIR/"
fi fi

12
contrib/build-linux/sdist/Dockerfile

@ -16,3 +16,15 @@ RUN apt-get update -q && \
rm -rf /var/lib/apt/lists/* && \ rm -rf /var/lib/apt/lists/* && \
apt-get autoremove -y && \ apt-get autoremove -y && \
apt-get clean apt-get clean
# create new user to avoid using root; but with sudo access and no password for convenience.
ENV USER="user"
ENV HOME_DIR="/home/${USER}"
ENV WORK_DIR="${HOME_DIR}/wspace" \
PATH="${HOME_DIR}/.local/bin:${PATH}"
RUN useradd --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}

8
contrib/build-linux/sdist/build.sh

@ -22,7 +22,7 @@ if [ ! -z "$ELECBUILD_NOCACHE" ] ; then
fi fi
info "building docker image." info "building docker image."
sudo docker build \ docker build \
$DOCKER_BUILD_FLAGS \ $DOCKER_BUILD_FLAGS \
-t electrum-sdist-builder-img \ -t electrum-sdist-builder-img \
"$CONTRIB_SDIST" "$CONTRIB_SDIST"
@ -31,7 +31,7 @@ sudo docker build \
if [ ! -z "$ELECBUILD_COMMIT" ] ; then if [ ! -z "$ELECBUILD_COMMIT" ] ; then
info "ELECBUILD_COMMIT=$ELECBUILD_COMMIT. doing fresh clone and git checkout." info "ELECBUILD_COMMIT=$ELECBUILD_COMMIT. doing fresh clone and git checkout."
FRESH_CLONE="$CONTRIB_SDIST/fresh_clone/electrum" && \ FRESH_CLONE="$CONTRIB_SDIST/fresh_clone/electrum" && \
sudo rm -rf "$FRESH_CLONE" && \ rm -rf "$FRESH_CLONE" && \
umask 0022 && \ umask 0022 && \
git clone "$PROJECT_ROOT" "$FRESH_CLONE" && \ git clone "$PROJECT_ROOT" "$FRESH_CLONE" && \
cd "$FRESH_CLONE" cd "$FRESH_CLONE"
@ -42,7 +42,7 @@ else
fi fi
info "building binary..." info "building binary..."
sudo docker run -it \ docker run -it \
--name electrum-sdist-builder-cont \ --name electrum-sdist-builder-cont \
-v "$PROJECT_ROOT_OR_FRESHCLONE_ROOT":/opt/electrum \ -v "$PROJECT_ROOT_OR_FRESHCLONE_ROOT":/opt/electrum \
--rm \ --rm \
@ -53,5 +53,5 @@ sudo docker run -it \
# make sure resulting binary location is independent of fresh_clone # make sure resulting binary location is independent of fresh_clone
if [ ! -z "$ELECBUILD_COMMIT" ] ; then if [ ! -z "$ELECBUILD_COMMIT" ] ; then
mkdir --parents "$DISTDIR/" mkdir --parents "$DISTDIR/"
sudo cp -f "$FRESH_CLONE/dist"/* "$DISTDIR/" cp -f "$FRESH_CLONE/dist"/* "$DISTDIR/"
fi fi

15
contrib/build-wine/Dockerfile

@ -53,3 +53,18 @@ RUN wget -nc https://dl.winehq.org/wine-builds/Release.key && \
rm -rf /var/lib/apt/lists/* && \ rm -rf /var/lib/apt/lists/* && \
apt-get autoremove -y && \ apt-get autoremove -y && \
apt-get clean apt-get clean
# create new user to avoid using root; but with sudo access and no password for convenience.
ENV USER="user"
ENV HOME_DIR="/home/${USER}"
ENV WORK_DIR="${HOME_DIR}/wspace" \
PATH="${HOME_DIR}/.local/bin:${PATH}"
RUN useradd --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}
RUN chown ${USER} /opt
USER ${USER}
RUN mkdir --parents "/opt/wine64/drive_c/electrum"

4
contrib/build-wine/build-electrum-git.sh

@ -31,7 +31,7 @@ for i in ./locale/*; do
done done
popd popd
find -exec touch -d '2000-11-11T11:11:11+00:00' {} + find -exec touch -h -d '2000-11-11T11:11:11+00:00' {} +
popd popd
@ -60,7 +60,7 @@ wine "$WINE_PYHOME/scripts/pyinstaller.exe" --noconfirm --ascii --clean --name $
# set timestamps in dist, in order to make the installer reproducible # set timestamps in dist, in order to make the installer reproducible
pushd dist pushd dist
find -exec touch -d '2000-11-11T11:11:11+00:00' {} + find -exec touch -h -d '2000-11-11T11:11:11+00:00' {} +
popd popd
info "building NSIS installer" info "building NSIS installer"

8
contrib/build-wine/build.sh

@ -21,7 +21,7 @@ if [ ! -z "$ELECBUILD_NOCACHE" ] ; then
fi fi
info "building docker image." info "building docker image."
sudo docker build \ docker build \
$DOCKER_BUILD_FLAGS \ $DOCKER_BUILD_FLAGS \
-t electrum-wine-builder-img \ -t electrum-wine-builder-img \
"$CONTRIB_WINE" "$CONTRIB_WINE"
@ -30,7 +30,7 @@ sudo docker build \
if [ ! -z "$ELECBUILD_COMMIT" ] ; then if [ ! -z "$ELECBUILD_COMMIT" ] ; then
info "ELECBUILD_COMMIT=$ELECBUILD_COMMIT. doing fresh clone and git checkout." info "ELECBUILD_COMMIT=$ELECBUILD_COMMIT. doing fresh clone and git checkout."
FRESH_CLONE="$CONTRIB_WINE/fresh_clone/electrum" && \ FRESH_CLONE="$CONTRIB_WINE/fresh_clone/electrum" && \
sudo rm -rf "$FRESH_CLONE" && \ rm -rf "$FRESH_CLONE" && \
umask 0022 && \ umask 0022 && \
git clone "$PROJECT_ROOT" "$FRESH_CLONE" && \ git clone "$PROJECT_ROOT" "$FRESH_CLONE" && \
cd "$FRESH_CLONE" cd "$FRESH_CLONE"
@ -41,7 +41,7 @@ else
fi fi
info "building binary..." info "building binary..."
sudo docker run -it \ docker run -it \
--name electrum-wine-builder-cont \ --name electrum-wine-builder-cont \
-v "$PROJECT_ROOT_OR_FRESHCLONE_ROOT":/opt/wine64/drive_c/electrum \ -v "$PROJECT_ROOT_OR_FRESHCLONE_ROOT":/opt/wine64/drive_c/electrum \
--rm \ --rm \
@ -52,5 +52,5 @@ sudo docker run -it \
# make sure resulting binary location is independent of fresh_clone # make sure resulting binary location is independent of fresh_clone
if [ ! -z "$ELECBUILD_COMMIT" ] ; then if [ ! -z "$ELECBUILD_COMMIT" ] ; then
mkdir --parents "$PROJECT_ROOT/contrib/build-wine/dist/" mkdir --parents "$PROJECT_ROOT/contrib/build-wine/dist/"
sudo cp -f "$FRESH_CLONE/contrib/build-wine/dist"/*.exe "$PROJECT_ROOT/contrib/build-wine/dist/" cp -f "$FRESH_CLONE/contrib/build-wine/dist"/*.exe "$PROJECT_ROOT/contrib/build-wine/dist/"
fi fi

2
contrib/build-wine/make_win.sh

@ -64,7 +64,7 @@ fi
info "Resetting modification time in C:\Python..." info "Resetting modification time in C:\Python..."
# (Because of some bugs in pyinstaller) # (Because of some bugs in pyinstaller)
pushd /opt/wine64/drive_c/python* pushd /opt/wine64/drive_c/python*
find -exec touch -d '2000-11-11T11:11:11+00:00' {} + find -exec touch -h -d '2000-11-11T11:11:11+00:00' {} +
popd popd
ls -l /opt/wine64/drive_c/python* ls -l /opt/wine64/drive_c/python*

2
contrib/make_libusb.sh

@ -48,7 +48,7 @@ info "Building $pkgname..."
|| fail "Could not configure $pkgname. Please make sure you have a C compiler installed and try again." || fail "Could not configure $pkgname. Please make sure you have a C compiler installed and try again."
fi fi
make -j4 || fail "Could not build $pkgname" make -j4 || fail "Could not build $pkgname"
make install || fail "Could not install $pkgname" make install || warn "Could not install $pkgname"
. "$here/$pkgname/libusb/.libs/libusb-1.0.la" . "$here/$pkgname/libusb/.libs/libusb-1.0.la"
host_strip "$here/$pkgname/libusb/.libs/$dlname" host_strip "$here/$pkgname/libusb/.libs/$dlname"
TARGET_NAME="$dlname" TARGET_NAME="$dlname"

Loading…
Cancel
Save