Skip to content

Commit

Permalink
unified Dockerfile. renamed workflow files
Browse files Browse the repository at this point in the history
  • Loading branch information
AlvinSchiller committed Oct 19, 2023
1 parent aba7e9f commit 99393b6
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 112 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ on:
# let only one instance run the test so cache is not corrupted.
# cancel already running instances as only the last run will be relevant
concurrency:
group: ${{ github.ref }}-debian
group: ${{ github.ref }}-test-debian
cancel-in-progress: true

jobs:
Expand All @@ -26,12 +26,12 @@ jobs:
fail-fast: false
matrix:
debian_version_name: ['bullseye', 'buster']
uses: ./.github/workflows/docker_debian_versionname_sub.yml
uses: ./.github/workflows/test_docker_debian_versionname_sub.yml
with:
runs_on: ubuntu-latest
platform: linux/arm/v7
docker_image_name: rpi-jukebox-rfid
cache_scope: ${{ github.ref }}-debian
cache_scope: ${{ github.ref }}-test-debian
matrix_usernames: "['pi', 'hans']"
matrix_test_scripts: "['run_installation_tests.sh', 'run_installation_tests2.sh', 'run_installation_tests3.sh']"
debian_version_name: ${{ matrix.debian_version_name }}
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@ jobs:
context: .
load: false
push: true
file: ./ci/Dockerfile.debian.test_install.armv7
target: test
file: ./ci/Dockerfile.debian
target: test-code
platforms: ${{ inputs.platform }}
tags: ${{ steps.vars.outputs.image_tag_name_local_base }}
cache-from: type=gha,scope=${{ steps.vars.outputs.cache_scope }}
Expand All @@ -113,7 +113,7 @@ jobs:
context: .
load: false
push: false
file: ./ci/Dockerfile.debian.test_install.armv7
file: ./ci/Dockerfile.debian
target: test-update
platforms: ${{ inputs.platform }}
tags: ${{ steps.vars.outputs.image_tag_name }}
Expand Down
32 changes: 0 additions & 32 deletions ci/Dockerfile.buster.amd64

This file was deleted.

32 changes: 0 additions & 32 deletions ci/Dockerfile.buster.armv7

This file was deleted.

56 changes: 40 additions & 16 deletions ci/Dockerfile.debian.test_install.armv7 → ci/Dockerfile.debian
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
# Target to build and install all needed base configuration and packages
# Base Target to build and install all needed base configuration and packages. Specifie the needed platform with the docker '--platform XXX' option
ARG DEBIAN_VERSION_NAME=bullseye
ARG BASE_TEST_IMAGE=test
ARG BASE_TEST_IMAGE=test-code
FROM debian:${DEBIAN_VERSION_NAME}-slim as base
ARG DEBIAN_VERSION_NAME

ENV DOCKER_RUNNING=true
RUN touch /boot/cmdlinetxt

ENV DEBIAN_FRONTEND=noninteractive

RUN apt-get update \
RUN export DEBIAN_FRONTEND=noninteractive \
&& apt-get update \
&& apt-get -y install \
apt-utils \
curl \
Expand All @@ -35,18 +34,42 @@ RUN apt-get update \
&& rm -rf /var/lib/apt/lists/*
# ------


# Target for setting up user for test. user can be selected with the docker '--user $USERNAME' option
# Base Target for setting up the default user. user can be selected with the docker '--user YYY' option
FROM base as user
ENV TEST_USER_GROUP=test
ARG USER=pi
ARG USER_GROUP=$USER

ENV USER=$USER USER_GROUP=$USER_GROUP

RUN groupadd --gid 1000 $USER_GROUP \
&& useradd -u 1000 -g $USER_GROUP -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
# ------



####### Code Targets #######

RUN groupadd --gid 1002 $TEST_USER_GROUP
# Target for adding code from the repo. Set Default User
FROM user as code

RUN export USER_PI=pi \
&& export USER_PI_GROUP=$USER_PI \
&& groupadd --gid 1000 $USER_PI_GROUP \
&& useradd -u 1000 -g $USER_PI_GROUP -G sudo,$TEST_USER_GROUP -d /home/$USER_PI -m -s /bin/bash -p '$1$iV7TOwOe$6ojkJQXyEA9bHd/SqNLNj0' $USER_PI \
&& echo "$USER_PI ALL=(ALL) NOPASSWD: ALL" > /etc/sudoers.d/$USER_PI
COPY --chown=$USER:$USER_GROUP --chmod=770 . /code
WORKDIR /code

USER $USER
# ------



####### Test Targets #######

# Target for setting up an alternativ user 'hans:wurst'. user can be selected with the docker '--user YYY' option
FROM user as test-user

ENV TEST_USER_GROUP=test

RUN groupadd --gid 1002 $TEST_USER_GROUP \
&& usermod -a -G $TEST_USER_GROUP $USER

RUN export USER_ALT=hans \
&& export USER_ALT_GROUP=wurst \
Expand All @@ -57,7 +80,7 @@ RUN export USER_ALT=hans \


# Target for adding envs and scripts from the repo to test installation
FROM user as test
FROM test-user as test-code
ARG GIT_BRANCH
ARG GIT_URL

Expand All @@ -71,7 +94,8 @@ COPY --chown=root:$TEST_USER_GROUP --chmod=770 scripts/installscripts/tests/*.sh

# Target for applying latest updates (should not be cached!)
FROM $BASE_TEST_IMAGE as test-update
RUN apt-get update \
RUN export DEBIAN_FRONTEND=noninteractive \
&& apt-get update \
&& apt-get -y upgrade \
&& rm -rf /var/lib/apt/lists/*
# ------
45 changes: 19 additions & 26 deletions ci/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,48 +19,41 @@ This is a work in progress so expect things to fail or being flaky.
sudo reboot
```
* login to your RPi
* clone this repo and cd into its local clone:
* clone the repo and cd into its local clone:
```bash
cd /home/pi/
# optional: change to your fork appropriately
git clone https://github.com/MiczFlor/RPi-Jukebox-RFID.git
cd /home/pi/RPi-Jukebox-RFID/
cd RPi-Jukebox-RFID/
# optional: switch to another branch
git checkout <branch_name>
```
* build the docker image:
* **on normal PCs:**
```bash
docker build -t rpi-jukebox-rfid-buster:latest -f ci/Dockerfile.buster.amd64 .
```
```bash
docker build -t rpi-jukebox-rfid:buster-latest -f ci/Dockerfile.debian --platform=linux/arm/v7 --target=code --build-arg="DEBIAN_VERSION_NAME=buster" .
```
* additional arguments
* for builds
on normal PCs use `--platform=linux/amd64`
on a raspberry pi use `--platform=linux/arm/v7`
* to use a different debian version change `--build-arg="DEBIAN_VERSION_NAME=buster"` appropriately.

* **on a raspberry pi:**
```bash
docker build -t rpi-jukebox-rfid-buster:latest -f ci/Dockerfile.buster.armv7 .
```
* get something to drink or eat
* run the freshly built docker image and start testing. For example:
```bash
docker run --rm -ti rpi-jukebox-rfid-buster:latest /bin/bash
docker run --rm -ti rpi-jukebox-rfid:buster-latest /bin/bash
cd /home/pi/
cp /code/scripts/installscripts/buster-install-default.sh /home/pi/
bash buster-install-default.sh
# set GIT_URL and GIT_BRANCH appropriately to your checkout
bash GIT_URL=https://github.com/MiczFlor/RPi-Jukebox-RFID.git GIT_BRANCH=main buster-install-default.sh
```

NOTE: Get familiar with docker and its flags - `--rm` for example will remove the
container after you log out of it and all changes will be lost.

### mount hosts code as volume

The created image now contains all the code in the directory `/code` - if you do not want to
rebuild the image after each code-change you can 'mount' the RPi's code version into the
container:
```bash
git clone https://github.com/MiczFlor/RPi-Jukebox-RFID.git
cd /home/pi/RPi-Jukebox-RFID/
docker build -t rpi-jukebox-rfid-buster:latest -f ci/Dockerfile .
docker run --rm -ti -w /code -v $PWD:/code rpi-jukebox-rfid-buster:latest /bin/bash
cd /home/pi/
cp /code/scripts/installscripts/buster-install-default.sh /home/pi/
bash buster-install-default.sh
```
The created image now contains all the code in the directory `/code` - if you do not want to rebuild the image after each code-change you can 'mount' the RPi's code version into the container.
Add `-w /code -v $PWD:/code` to the `docker run` parameter.
In that way every change to the code in the container will be available on the RPi as well as vice versa.

0 comments on commit 99393b6

Please sign in to comment.