Skip to content

Commit 263e27c

Browse files
authored
Merge pull request #21 from learningequality/rebase_upstream
Update image
2 parents adc0ced + 4105a6e commit 263e27c

File tree

84 files changed

+1441
-611
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

84 files changed

+1441
-611
lines changed

.buildkite/build.sh

Lines changed: 0 additions & 34 deletions
This file was deleted.

.buildkite/pipeline.yaml

Lines changed: 0 additions & 10 deletions
This file was deleted.

.github/workflows/build_zip.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,13 @@ jobs:
4444
with:
4545
repository: learningequality/pi-gen
4646
ref: ${{ inputs.ref }}
47+
- name: Set up QEMU
48+
uses: docker/setup-qemu-action@v2
49+
- name: Download the debfile from URL and install
50+
if: ${{ inputs.deb-url }}
51+
run: |
52+
sudo apt-get update
53+
sudo apt-get install -y qemu-user-static
4754
- name: Download the debfile from URL and install
4855
if: ${{ inputs.deb-url }}
4956
run: make get-deb deb=${{ inputs.deb-url }}

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,3 @@ dist/*
44
postrun.sh
55
.pc
66
*-pc
7-
apt-cacher-ng/

.gitlab-ci.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
include:
2+
- project: serge/pi-gen
3+
ref: ci
4+
file: 'pi-gen.yml'

Dockerfile

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
1-
FROM i386/debian:buster
2-
LABEL build=pigen
3-
ENV DEBIAN_FRONTEND noninteractive
1+
FROM i386/debian:bullseye
2+
ENV DEBIAN_FRONTEND=noninteractive
43

54
RUN apt-get -y update && \
6-
apt-get -y install \
5+
apt-get -y install --no-install-recommends \
76
git vim parted \
87
quilt coreutils qemu-user-static debootstrap zerofree zip dosfstools \
9-
bsdtar libcap2-bin rsync grep udev xz-utils curl xxd file kmod\
8+
libarchive-tools libcap2-bin rsync grep udev xz-utils curl xxd file kmod bc \
9+
binfmt-support ca-certificates fdisk gpg pigz arch-test \
1010
&& rm -rf /var/lib/apt/lists/*
1111

12+
COPY --from=multiarch/qemu-user-static:latest /usr/bin/qemu-arm-static /usr/bin/
13+
1214
COPY . /pi-gen/
1315

1416
VOLUME [ "/pi-gen/work", "/pi-gen/deploy"]

Makefile

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,16 @@ get-deb: clean-deb
2323
fi
2424

2525
rename-zip:
26+
# Get current date in YYYY-MM-DD format
27+
$(eval DATE := $(shell date +%Y-%m-%d))
2628
# Unzip the file so we can rename the image file
27-
unzip -o deploy/image_Kolibri-lite.zip -d deploy
29+
unzip -o deploy/image_$(DATE)-Kolibri-lite.zip -d deploy
2830
# Clean up the original zip file
29-
rm deploy/image_Kolibri-lite.zip
31+
rm deploy/image_$(DATE)-Kolibri-lite.zip
3032
# Get the version based on the debian file name kolibri_<version>-0ubuntu1_all.deb
3133
$(eval VERSION=$(shell ls ${DIST_DIR} | grep kolibri | sed 's/kolibri_\(.*\)-0ubuntu1_all.deb/\1/'))
3234
# Rename the image file to include the version
33-
mv deploy/Kolibri-lite.img deploy/kolibri-pi-image-$(VERSION).img
35+
mv deploy/$(DATE)-Kolibri-lite.img deploy/kolibri-pi-image-$(VERSION).img
3436
# Zip the image file back up
3537
zip -j deploy/kolibri-pi-image-$(VERSION).zip deploy/kolibri-pi-image-$(VERSION).img
3638
# Clean up the extracted image file

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,17 @@
1111
5. Enjoy it!
1212

1313

14+
This image sets up the Raspberry Pi to provide wifi using the essid `kolibri` without any password.
1415

1516
After following the above steps the Raspberry Pi will provide a wifi network named under the essid `kolibri` without any password.
1617

17-
After connecting a device to this wifi network provided by the Raspberry, you can open the url http://10.10.10.10 in a browser will allow you enjoy all the features of a working Kolibri server.
18+
After connecting a device to this wifi network provided by the Raspberry, you can open the url http://10.10.10.10 in a browser will allow you enjoy all the features of a working Kolibri server.
1819

1920
By default the server does not have Internet access. To add content channels to Kolibri you can either connect an usb disk with content or plug and ethernet cable with Internet access.
2021

2122
In case you want to login into the server, the user is `pi` and the password is `kolibrifly`
2223

24+
VERY IMPORTANT: After installing the image, a ssh server is installed with a known password. CHANGE IT in case you want to connect it to Internet or be used by people who could mess it up.
2325
**VERY IMPORTANT NOTICE**: After installing the image, a ssh server is installed with a known password. **CHANGE IT** in case you want to connect it to Internet or be used by people who could mess it up.
2426

2527

@@ -41,6 +43,6 @@ Using the `raspi-config` script we'll
4143

4244
- Add options to make the wifi encrypted
4345

44-
46+
4547

4648
## Rebuilding the Kolibri Raspberry Pi image

build-docker.sh

Lines changed: 95 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,20 @@
1-
#!/bin/bash -eu
2-
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
1+
#!/usr/bin/env bash
2+
# Note: Avoid usage of arrays as MacOS users have an older version of bash (v3.x) which does not supports arrays
3+
set -eu
4+
5+
DIR="$(CDPATH='' cd -- "$(dirname -- "$0")" && pwd)"
36

47
BUILD_OPTS="$*"
58

6-
DOCKER="docker"
9+
# Allow user to override docker command
10+
DOCKER=${DOCKER:-docker}
711

8-
if ! ${DOCKER} ps >/dev/null 2>&1; then
9-
DOCKER="sudo docker"
12+
# Ensure that default docker command is not set up in rootless mode
13+
if \
14+
! ${DOCKER} ps >/dev/null 2>&1 || \
15+
${DOCKER} info 2>/dev/null | grep -q rootless \
16+
; then
17+
DOCKER="sudo ${DOCKER}"
1018
fi
1119
if ! ${DOCKER} ps >/dev/null; then
1220
echo "error connecting to docker:"
@@ -32,7 +40,7 @@ done
3240

3341
# Ensure that the configuration file is an absolute path
3442
if test -x /usr/bin/realpath; then
35-
CONFIG_FILE=$(realpath -s "$CONFIG_FILE")
43+
CONFIG_FILE=$(realpath -s "$CONFIG_FILE" || realpath "$CONFIG_FILE")
3644
fi
3745

3846
# Ensure that the confguration file is present
@@ -41,12 +49,13 @@ if test -z "${CONFIG_FILE}"; then
4149
exit 1
4250
else
4351
# shellcheck disable=SC1090
44-
source "${CONFIG_FILE}"
52+
source ${CONFIG_FILE}
4553
fi
4654

4755
CONTAINER_NAME=${CONTAINER_NAME:-pigen_work}
4856
CONTINUE=${CONTINUE:-0}
4957
PRESERVE_CONTAINER=${PRESERVE_CONTAINER:-0}
58+
PIGEN_DOCKER_OPTS=${PIGEN_DOCKER_OPTS:-""}
5059

5160
if [ -z "${IMG_NAME}" ]; then
5261
echo "IMG_NAME not set in 'config'" 1>&2
@@ -73,31 +82,89 @@ fi
7382
# Modify original build-options to allow config file to be mounted in the docker container
7483
BUILD_OPTS="$(echo "${BUILD_OPTS:-}" | sed -E 's@\-c\s?([^ ]+)@-c /config@')"
7584

76-
${DOCKER} build -t pi-gen "${DIR}"
85+
# Check the arch of the machine we're running on. If it's 64-bit, use a 32-bit base image instead
86+
case "$(uname -m)" in
87+
x86_64|aarch64)
88+
BASE_IMAGE=i386/debian:bullseye
89+
;;
90+
*)
91+
BASE_IMAGE=debian:bullseye
92+
;;
93+
esac
94+
${DOCKER} build --build-arg BASE_IMAGE=${BASE_IMAGE} -t pi-gen "${DIR}"
95+
7796
if [ "${CONTAINER_EXISTS}" != "" ]; then
78-
trap 'echo "got CTRL+C... please wait 5s" && ${DOCKER} stop -t 5 ${CONTAINER_NAME}_cont' SIGINT SIGTERM
79-
time ${DOCKER} run --rm --privileged \
80-
--volume "${CONFIG_FILE}":/config:ro \
81-
-e "GIT_HASH=${GIT_HASH}" \
82-
--volumes-from="${CONTAINER_NAME}" --name "${CONTAINER_NAME}_cont" \
83-
pi-gen \
84-
bash -e -o pipefail -c "dpkg-reconfigure qemu-user-static || true &&
85-
cd /pi-gen; ./build.sh ${BUILD_OPTS} &&
86-
rsync -av work/*/build.log deploy/" &
87-
wait "$!"
97+
DOCKER_CMDLINE_NAME="${CONTAINER_NAME}_cont"
98+
DOCKER_CMDLINE_PRE="--rm"
99+
DOCKER_CMDLINE_POST="--volumes-from=${CONTAINER_NAME}"
88100
else
89-
trap 'echo "got CTRL+C... please wait 5s" && ${DOCKER} stop -t 5 ${CONTAINER_NAME}' SIGINT SIGTERM
90-
time ${DOCKER} run --name "${CONTAINER_NAME}" --privileged \
91-
--volume "${CONFIG_FILE}":/config:ro \
92-
-e "GIT_HASH=${GIT_HASH}" \
93-
pi-gen \
94-
bash -e -o pipefail -c "dpkg-reconfigure qemu-user-static || true &&
95-
cd /pi-gen; ./build.sh ${BUILD_OPTS} &&
96-
rsync -av work/*/build.log deploy/" &
97-
wait "$!"
101+
DOCKER_CMDLINE_NAME="${CONTAINER_NAME}"
102+
DOCKER_CMDLINE_PRE=""
103+
DOCKER_CMDLINE_POST=""
104+
fi
105+
106+
# Check if binfmt_misc is required
107+
binfmt_misc_required=1
108+
case $(uname -m) in
109+
aarch64)
110+
binfmt_misc_required=0
111+
;;
112+
arm*)
113+
binfmt_misc_required=0
114+
;;
115+
esac
116+
117+
# Check if qemu-arm-static and /proc/sys/fs/binfmt_misc are present
118+
if [[ "${binfmt_misc_required}" == "1" ]]; then
119+
if ! qemu_arm=$(which qemu-arm-static) ; then
120+
echo "qemu-arm-static not found (please install qemu-user-static)"
121+
exit 1
122+
fi
123+
if [ ! -f /proc/sys/fs/binfmt_misc/register ]; then
124+
echo "binfmt_misc required but not mounted, trying to mount it..."
125+
if ! mount binfmt_misc -t binfmt_misc /proc/sys/fs/binfmt_misc ; then
126+
echo "mounting binfmt_misc failed"
127+
exit 1
128+
fi
129+
echo "binfmt_misc mounted"
130+
fi
131+
if ! grep -q "^interpreter ${qemu_arm}" /proc/sys/fs/binfmt_misc/qemu-arm* ; then
132+
# Register qemu-arm for binfmt_misc
133+
reg="echo ':qemu-arm-rpi:M::"\
134+
"\x7fELF\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x28\x00:"\
135+
"\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff:"\
136+
"${qemu_arm}:F' > /proc/sys/fs/binfmt_misc/register"
137+
echo "Registering qemu-arm for binfmt_misc..."
138+
sudo bash -c "${reg}" 2>/dev/null || true
139+
fi
98140
fi
141+
142+
trap 'echo "got CTRL+C... please wait 5s" && ${DOCKER} stop -t 5 ${DOCKER_CMDLINE_NAME}' SIGINT SIGTERM
143+
time ${DOCKER} run \
144+
$DOCKER_CMDLINE_PRE \
145+
--name "${DOCKER_CMDLINE_NAME}" \
146+
--privileged \
147+
${PIGEN_DOCKER_OPTS} \
148+
--volume "${CONFIG_FILE}":/config:ro \
149+
-e "GIT_HASH=${GIT_HASH}" \
150+
$DOCKER_CMDLINE_POST \
151+
pi-gen \
152+
bash -e -o pipefail -c "
153+
dpkg-reconfigure qemu-user-static || true &&
154+
# binfmt_misc is sometimes not mounted with debian bullseye image
155+
(mount binfmt_misc -t binfmt_misc /proc/sys/fs/binfmt_misc || true) &&
156+
cd /pi-gen; ./build.sh ${BUILD_OPTS} &&
157+
rsync -av work/*/build.log deploy/
158+
" &
159+
wait "$!"
160+
161+
# Ensure that deploy/ is always owned by calling user
99162
echo "copying results from deploy/"
100-
${DOCKER} cp "${CONTAINER_NAME}":/pi-gen/deploy .
163+
${DOCKER} cp "${CONTAINER_NAME}":/pi-gen/deploy - | tar -xf -
164+
165+
echo "copying log from container ${CONTAINER_NAME} to deploy/"
166+
${DOCKER} logs --timestamps "${CONTAINER_NAME}" &>deploy/build-docker.log
167+
101168
ls -lah deploy
102169

103170
# cleanup

0 commit comments

Comments
 (0)