Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ To perform manual generation, you'll need access to the container directly. You
can get a shell inside the container by running the following command:

```sh
podman compose run --build rpi_imagegen bash
podman compose run rpi_imagegen bash
```

If running on a non-ARM host, from within the container, run the following
Expand Down
6 changes: 3 additions & 3 deletions compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ services:
image: rpi-imagegen:latest
working_dir: /home/imagegen/rpi-image-gen
volumes:
- ./build:/home/imagegen/build
- ./scripts:/home/imagegen/scripts
- ./uniclogs:/home/imagegen/uniclogs
- ./build:/home/imagegen/build:z
- ./scripts:/home/imagegen/scripts:ro
- ./uniclogs:/home/imagegen/uniclogs:ro
16 changes: 7 additions & 9 deletions container/Containerfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,15 @@ RUN curl -L -o rpi-image-gen.tar.gz https://github.com/raspberrypi/rpi-image-gen
&& mv rpi-image-gen-${RPIIG_GIT_SHA} /rpi-image-gen \
&& rm rpi-image-gen.tar.gz

RUN <<EOF
arch=$(uname -m);
if [ "$arch" != "aarch64" ] || [ "$arch" != "arm64" ]; then
apt-get install --no-install-recommends -y qemu-user-static;
RUN arch=$(uname -m) \
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was having issues with the <<EOF syntax and got tired of wrestling with it, which is why this chunk of code got modified.

# the binfmt_misc check in install_deps.sh will fail since it is not
# mounted; suppress the error.
/rpi-image-gen/install_deps.sh || true;
else
/rpi-image-gen/install_deps.sh;
fi
EOF
&& if [ "$arch" != "aarch64" ] || [ "$arch" != "arm64" ]; then \
apt-get install --no-install-recommends -y qemu-user-static \
&& /rpi-image-gen/install_deps.sh || true; \
else \
/rpi-image-gen/install_deps.sh; \
fi

ENV USER=imagegen
RUN useradd -u 4000 -ms /bin/bash "$USER" \
Expand Down
12 changes: 9 additions & 3 deletions scripts/build-env.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,15 @@ main() {
PROJECT_ROOT="$SCRIPT_DIR/.."

cd "$PROJECT_ROOT"
exec podman compose run --build rpi_imagegen bash -c "
/home/imagegen/scripts/generate-image.sh
"

sudo podman run --rm --privileged docker.io/multiarch/qemu-user-static --reset -p yes -c yes
sudo podman build -t rpi-imagegen:latest -f container/Containerfile .

mkdir -p "$PROJECT_ROOT/build"
sudo chmod 777 "$PROJECT_ROOT/build"

print_info "Running image generation (requires sudo for privileged operations) ..."
exec sudo podman compose run --rm rpi_imagegen bash -c "/home/imagegen/scripts/generate-image.sh"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On macOS, this was not required, but on a linux host, it is necessary.

}

main "$@"
22 changes: 19 additions & 3 deletions scripts/generate-image.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,31 @@ print_error() {
}

mount_binfmt_misc() {
if [ -f /proc/sys/fs/binfmt_misc/status ] 2>/dev/null;
then
print_info "binfmt_misc is already available."
return 0
fi

print_info "Mounting binfmt_misc ..."
print_warning "Enter the imagegen user's password (imagegen)!"

if sudo mount binfmt_misc -t binfmt_misc /proc/sys/fs/binfmt_misc;
mount_output=$(sudo mount binfmt_misc -t binfmt_misc /proc/sys/fs/binfmt_misc 2>&1)
mount_status=$?

if [ $mount_status -eq 0 ];
then
print_success "binfmt_misc mounted successfully."
else
print_error "Failed to mount binfmt_misc."
exit 1
if echo "$mount_output" | grep -iq "already mounted" || [ -f /proc/sys/fs/binfmt_misc/status ];
then
print_info "binfmt_misc is already mounted."
return 0
else
print_error "Failed to mount binfmt_misc."
echo "$mount_output"
exit 1
fi
fi
}

Expand Down