From c10a857c8fbee013b0d1bbd017f35ae9fc42441f Mon Sep 17 00:00:00 2001 From: Alvin Schiller <103769832+AlvinSchiller@users.noreply.github.com> Date: Thu, 12 Oct 2023 03:41:55 +0200 Subject: [PATCH] Performance optimization for container --- .github/workflows/docker_bullseye_altuser.yml | 6 +- ci/Dockerfile.bullseye.test_install.armv7 | 80 +++++++++++-------- .../tests/run_installation_tests.sh | 4 +- .../tests/run_installation_tests2.sh | 4 +- .../tests/run_installation_tests3.sh | 4 +- 5 files changed, 54 insertions(+), 44 deletions(-) diff --git a/.github/workflows/docker_bullseye_altuser.yml b/.github/workflows/docker_bullseye_altuser.yml index 0024ac8df..8d928145f 100644 --- a/.github/workflows/docker_bullseye_altuser.yml +++ b/.github/workflows/docker_bullseye_altuser.yml @@ -50,7 +50,7 @@ jobs: options: --platform linux/arm/v7 name: run_installation_tests.sh args: | - /code/scripts/installscripts/tests/run_installation_tests.sh + run_installation_tests.sh - name: Run run_installation_tests2.sh Bullseye ARMv7 uses: tj-actions/docker-run@v2 @@ -59,7 +59,7 @@ jobs: options: --platform linux/arm/v7 name: run_installation_tests2.sh args: | - /code/scripts/installscripts/tests/run_installation_tests2.sh + run_installation_tests2.sh - name: Run run_installation_tests3.sh Bullseye ARMv7 uses: tj-actions/docker-run@v2 @@ -68,4 +68,4 @@ jobs: options: --platform linux/arm/v7 name: run_installation_tests3.sh args: | - /code/scripts/installscripts/tests/run_installation_tests3.sh + run_installation_tests3.sh diff --git a/ci/Dockerfile.bullseye.test_install.armv7 b/ci/Dockerfile.bullseye.test_install.armv7 index 467dca71b..00f7cfe99 100644 --- a/ci/Dockerfile.bullseye.test_install.armv7 +++ b/ci/Dockerfile.bullseye.test_install.armv7 @@ -1,44 +1,54 @@ FROM --platform=linux/arm/v7 arm32v7/debian:bullseye-slim -ARG USER_NAME=pi -ARG USER_GROUP=$USER_NAME -ARG GIT_BRANCH -ARG GIT_URL +# Define constants ENV DOCKER_RUNNING=true -ENV USER=$USER_NAME -ENV GIT_BRANCH=$GIT_BRANCH -ENV GIT_URL=$GIT_URL +ENV DEBIAN_FRONTEND=noninteractive + +RUN touch /boot/cmdlinetxt -COPY . /code -WORKDIR /code - -RUN groupadd --gid 1000 $USER_GROUP ;\ - useradd -u 1000 -g 1000 -G sudo -d /home/$USER -m -s /bin/bash -p '$1$iV7TOwOe$6ojkJQXyEA9bHd/SqNLNj0' $USER ;\ - chown -R 1000:1000 /code /home/$USER ;\ - chmod +x /code/scripts/installscripts/buster-install-default.sh ;\ - chmod +x /code/scripts/installscripts/tests/run_installation_tests.sh ;\ - chmod +x /code/scripts/installscripts/tests/run_installation_tests2.sh ;\ - chmod +x /code/scripts/installscripts/tests/run_installation_tests3.sh - -RUN export DEBIAN_FRONTEND=noninteractive ;\ - apt-get update ;\ - apt-get -y install curl gnupg sudo nano systemd apt-utils ;\ - echo 'deb http://raspbian.raspberrypi.org/raspbian/ bullseye main contrib non-free rpi' > /etc/apt/sources.list.d/raspi.list ;\ +# Install all packages +RUN echo 'deb http://raspbian.raspberrypi.org/raspbian/ bullseye main contrib non-free rpi' > /etc/apt/sources.list.d/raspi.list ;\ echo 'deb http://archive.raspberrypi.org/debian/ bullseye main' >> /etc/apt/sources.list.d/raspi.list ;\ curl http://raspbian.raspberrypi.org/raspbian.public.key | apt-key add - ;\ curl http://archive.raspberrypi.org/debian/raspberrypi.gpg.key | apt-key add - ;\ - echo "$USER ALL=(ALL) NOPASSWD: ALL" > /etc/sudoers.d/$USER ;\ - apt-get clean ;\ - rm -rf /var/cache/apt/* /var/lib/apt/lists/* - -RUN export DEBIAN_FRONTEND=noninteractive ;\ - apt-get update ;\ - # install here to speed up GitHub Action - apt-get -y install raspberrypi-kernel-headers ;\ - apt-get -y dist-upgrade --auto-remove --purge ;\ - apt-get -y install wget build-essential git iw locales wpasupplicant ;\ - apt-get clean ;\ - touch /boot/cmdlinetxt ;\ - rm -rf /var/cache/apt/* /var/lib/apt/lists/* + apt-get update && \ + apt-get -y install \ + apt-utils \ + build-essential \ + curl \ + git \ + gnupg \ + iw \ + locales \ + nano \ + # install here to speed up GitHub Action + raspberrypi-kernel-headers \ + sudo \ + systemd \ + wget \ + wpasupplicant && \ + apt-get -y dist-upgrade --auto-remove --purge && \ + rm -rf /var/lib/apt/lists/* + +# Define user info that my change. Therefore after package installation +ARG USER_NAME=pi +ARG USER_GROUP=$USER_NAME +ENV USER=$USER_NAME + +RUN groupadd --gid 1000 $USER_GROUP && \ + useradd -u 1000 -g 1000 -G sudo -d /home/$USER -m -s /bin/bash -p '$1$iV7TOwOe$6ojkJQXyEA9bHd/SqNLNj0' $USER && \ + echo "$USER ALL=(ALL) NOPASSWD: ALL" > /etc/sudoers.d/$USER + +# Define need files for installation test +COPY --chown=1000:1000 --chmod=+x scripts/installscripts/tests/run_installation_tests*.sh /test/ +COPY --chown=1000:1000 --chmod=+x scripts/installscripts/buster-install-default.sh / + +WORKDIR /test + +# Define Git Repo variables which frequently change +ARG GIT_BRANCH +ARG GIT_URL +ENV GIT_BRANCH=$GIT_BRANCH +ENV GIT_URL=$GIT_URL USER $USER diff --git a/scripts/installscripts/tests/run_installation_tests.sh b/scripts/installscripts/tests/run_installation_tests.sh index a19261cc8..0b40da315 100644 --- a/scripts/installscripts/tests/run_installation_tests.sh +++ b/scripts/installscripts/tests/run_installation_tests.sh @@ -25,8 +25,8 @@ export DEBIAN_FRONTEND=noninteractive # n no RFID registration # n No reboot -bash ./scripts/installscripts/buster-install-default.sh <<< $'y\nn\n\ny\n\nn\n\ny\n\ny\n\ny\n\ny\nn\nn\n' +bash ./../buster-install-default.sh <<< $'y\nn\n\ny\n\nn\n\ny\n\ny\n\ny\n\ny\nn\nn\n' INSTALLATION_EXITCODE=$? # Test installation -./scripts/installscripts/tests/test_installation.sh $INSTALLATION_EXITCODE +./test_installation.sh $INSTALLATION_EXITCODE diff --git a/scripts/installscripts/tests/run_installation_tests2.sh b/scripts/installscripts/tests/run_installation_tests2.sh index 1beb95a22..f2aae541b 100644 --- a/scripts/installscripts/tests/run_installation_tests2.sh +++ b/scripts/installscripts/tests/run_installation_tests2.sh @@ -27,8 +27,8 @@ export DEBIAN_FRONTEND=noninteractive # yes, reader is connected # n No reboot -bash ./scripts/installscripts/buster-install-default.sh <<< $'y\nn\n\ny\n\nn\n\ny\n\ny\n\ny\n\ny\ny\n2\ny\nn\n' +bash ./../buster-install-default.sh <<< $'y\nn\n\ny\n\nn\n\ny\n\ny\n\ny\n\ny\ny\n2\ny\nn\n' INSTALLATION_EXITCODE=$? # Test installation -./scripts/installscripts/tests/test_installation.sh $INSTALLATION_EXITCODE +./test_installation.sh $INSTALLATION_EXITCODE diff --git a/scripts/installscripts/tests/run_installation_tests3.sh b/scripts/installscripts/tests/run_installation_tests3.sh index 2e0290b27..147be5e32 100644 --- a/scripts/installscripts/tests/run_installation_tests3.sh +++ b/scripts/installscripts/tests/run_installation_tests3.sh @@ -25,8 +25,8 @@ export DEBIAN_FRONTEND=noninteractive # n no RFID registration # n No reboot -bash ./scripts/installscripts/buster-install-default.sh <<< $'y\nn\n\ny\n\ny\nmyuser\nmypassword\nmyclient_id\nmyclient_secret\n\ny\n\ny\n\ny\n\ny\nn\nn\n' +bash ./../buster-install-default.sh <<< $'y\nn\n\ny\n\ny\nmyuser\nmypassword\nmyclient_id\nmyclient_secret\n\ny\n\ny\n\ny\n\ny\nn\nn\n' INSTALLATION_EXITCODE=$? # Test installation -./scripts/installscripts/tests/test_installation.sh $INSTALLATION_EXITCODE +./test_installation.sh $INSTALLATION_EXITCODE