Skip to content

Commit 3e1cce3

Browse files
committed
refactor(docker): modernize setup
- Upgrade base image from ubuntu:22.04 to ubuntu:noble-20260113 - Pin APT snapshot for reproducible builds - Add multi-platform support (amd64/arm64) via buildx - Add entry-point.sh to create a matching host user inside the container instead of bind-mounting /etc/passwd and /etc/group - Use platform-specific package lists (e.g. cross-compilation toolchains for arm64 hosts) - Rename docker.mk to docker/docker.mk and update Makefile include
1 parent 178afe5 commit 3e1cce3

6 files changed

Lines changed: 158 additions & 78 deletions

File tree

Dockerfile

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

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ MESSAGE = printf '$(TERM_BOLD)>>> $(if $*,$*: ,)%b$(TERM_RESET)\n' $$'$(call str
6969
$(file >$(USER_DEFCONFIG),)
7070

7171
-include $(LOCAL_MK)
72-
include $(PROJECT_DIR)/docker.mk
72+
include $(PROJECT_DIR)/docker/docker.mk
7373

7474
ifdef EXTRA_OPTS
7575
$(warning EXTRA_OPTS will be removed in the future, please migrate to $$(call add-defconfig,...))

docker/Dockerfile

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
FROM ubuntu:noble-20260113
2+
SHELL ["/bin/bash", "-c"]
3+
4+
# Architecture to build for
5+
ARG TARGETPLATFORM
6+
7+
ARG DEBIAN_FRONTEND=noninteractive
8+
9+
# This first RUN is separated from the second one because it
10+
# shouldn't change often, and we want to cache it as much as
11+
# possible. The second may change more often, and we don't
12+
# want to invalidate the cache of the first one when that
13+
# happens.
14+
RUN <<EOF
15+
apt-get update -y
16+
apt-get install ca-certificates -y
17+
18+
echo 'APT::Snapshot "20260215T000000Z";' > /etc/apt/apt.conf.d/50snapshot
19+
20+
if [ "$TARGETPLATFORM" = "linux/amd64" ]; then
21+
dpkg --add-architecture i386
22+
fi
23+
24+
apt-get update -y
25+
apt-get upgrade -y
26+
EOF
27+
28+
RUN <<EOF
29+
PACKAGES=(
30+
"bc"
31+
"build-essential"
32+
"cpio"
33+
"curl"
34+
"default-jre"
35+
"file"
36+
"gettext" # buildstats.sh
37+
"git"
38+
"gosu" # entry-point.sh
39+
"graphviz"
40+
"libncurses6"
41+
"libncurses-dev"
42+
"libssl-dev" # cmake build
43+
"locales"
44+
"lzip"
45+
"mercurial"
46+
"python3"
47+
"rsync"
48+
"subversion"
49+
"wget"
50+
"unzip"
51+
)
52+
53+
if [ "$TARGETPLATFORM" = "linux/amd64" ]; then
54+
PACKAGES+=(
55+
"gcc-multilib" # cross-compilation of 32-bit x86 builds on 64-bit host
56+
"g++-multilib" # cross-compilation of 32-bit x86 builds on 64-bit host
57+
"libc6:i386"
58+
"libncurses6:i386"
59+
"libstdc++6:i386"
60+
)
61+
else
62+
PACKAGES+=(
63+
"gcc-arm-linux-gnueabihf" # 32-bit arm builds
64+
"g++-arm-linux-gnueabihf" # 32-bit arm builds
65+
"gcc-mingw-w64-x86-64-win32" # wine
66+
"libc6-dev-armhf-cross" # 32-bit arm builds
67+
)
68+
fi
69+
70+
apt-get install -y --no-install-recommends -o APT::Immediate-Configure=0 "${PACKAGES[@]}"
71+
apt-get clean
72+
rm -rf /var/lib/apt/lists/*
73+
74+
# Set locale
75+
sed -i -e 's/# en_US.UTF-8 UTF-8/en_US.UTF-8 UTF-8/' /etc/locale.gen
76+
locale-gen
77+
78+
# Use bash instead of dash as default shell
79+
echo 'dash dash/sh boolean false' | debconf-set-selections
80+
dpkg-reconfigure dash
81+
82+
# Create this so the ccache directory gets mounted here
83+
mkdir -p /home/batocera
84+
EOF
85+
86+
ENV LANG=en_US.UTF-8 \
87+
LANGUAGE=en_US:en \
88+
LC_ALL=en_US.UTF-8 \
89+
TZ=Europe/Paris
90+
91+
WORKDIR /build
92+
93+
COPY --chmod=0755 entry-point.sh /opt/entry-point.sh
94+
ENTRYPOINT ["/opt/entry-point.sh"]
95+
CMD ["/bin/bash"]

docker.mk renamed to docker/docker.mk

Lines changed: 36 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
DOCKER ?= docker
2-
DOCKER_OPTS ?=
3-
DOCKER_REPO ?= batoceralinux
4-
DOCKER_IMAGE_NAME ?= batocera.linux-build
1+
DOCKER ?= docker
2+
DOCKER_OPTS ?=
3+
DOCKER_REPO ?= batoceralinux
4+
DOCKER_IMAGE_NAME ?= batocera.linux-build
5+
DOCKER_PLATFORM ?= linux/amd64,linux/arm64
56

67
ifdef IMAGE_NAME
78
$(warning IMAGE_NAME will be removed in the future, please migrate to DOCKER_IMAGE_NAME)
@@ -24,15 +25,13 @@ GID := $(shell id -g)
2425

2526
define RUN_DOCKER
2627
$(DOCKER) run -t --init --rm \
27-
-e HOME \
2828
-v $(PROJECT_DIR):/build \
2929
-v $(DL_DIR):/build/buildroot/dl \
3030
-v $(OUTPUT_DIR)/$*:/$* \
31-
-v $(CCACHE_DIR):$(HOME)/.buildroot-ccache \
31+
-v $(CCACHE_DIR):/home/batocera/.buildroot-ccache \
3232
-w /$* \
33-
-v /etc/passwd:/etc/passwd:ro \
34-
-v /etc/group:/etc/group:ro \
35-
-u $(UID):$(GID) \
33+
-e HOST_UID=$(UID) \
34+
-e HOST_GID=$(GID) \
3635
$(DOCKER_OPTS) \
3736
$(DOCKER_IMAGE)
3837
endef
@@ -48,11 +47,30 @@ endif
4847
DOCKER_IMAGE_STAMP = $(PROJECT_DIR)/.ba-docker-image-available
4948
DOCKER_IMAGE_AVAILABLE := $(if $(DIRECT_BUILD),,$(DOCKER_IMAGE_STAMP))
5049

50+
define DOCKER_CHECK_BUILDER
51+
if ! $(DOCKER) buildx inspect batocera-builder >/dev/null 2>&1 ; then \
52+
$(call MESSAGE,Creating docker builder 'batocera-builder'); \
53+
$(DOCKER) buildx create --name batocera-builder; \
54+
fi
55+
endef
56+
57+
define DOCKER_ECHO_ACTION_MESSAGE
58+
$(call MESSAGE,$(DOCKER_ACTION_MESSAGE) docker image $(DOCKER_IMAGE))
59+
endef
60+
5161
$(DOCKER_IMAGE_STAMP): | _check_docker
52-
@$(call MESSAGE,$(DOCKER_ACTION_MESSAGE) docker image $(DOCKER_IMAGE))
53-
$(if $(filter build,$(DOCKER_ACTION)),\
54-
$(DOCKER) build -t $(DOCKER_IMAGE) .,\
55-
$(DOCKER) pull $(DOCKER_IMAGE))
62+
@if [ '$(DOCKER_ACTION)' = 'build' ]; then \
63+
$(DOCKER_CHECK_BUILDER); \
64+
$(DOCKER_ECHO_ACTION_MESSAGE); \
65+
$(DOCKER) buildx build --builder batocera-builder \
66+
--platform $(DOCKER_PLATFORM) \
67+
-t $(DOCKER_IMAGE) $(PROJECT_DIR)/docker; \
68+
$(DOCKER) buildx build --builder batocera-builder \
69+
--load -t $(DOCKER_IMAGE) $(PROJECT_DIR)/docker; \
70+
else \
71+
$(DOCKER_ECHO_ACTION_MESSAGE); \
72+
$(DOCKER) pull $(DOCKER_IMAGE); \
73+
fi
5674
@touch $@
5775

5876
.PHONY: pull-docker-image
@@ -79,5 +97,9 @@ rebuild-docker-image: clean-for-docker-image
7997

8098
.PHONY: publish-docker-image
8199
publish-docker-image: | _check_docker
100+
@$(DOCKER_CHECK_BUILDER)
82101
@$(call MESSAGE,Publishing docker image $(DOCKER_IMAGE))
83-
@$(DOCKER) push $(DOCKER_IMAGE):latest
102+
@$(DOCKER) buildx build --builder batocera-builder \
103+
--push --platform $(DOCKER_PLATFORM) \
104+
-t $(DOCKER_IMAGE) \
105+
$(PROJECT_DIR)/docker

docker/entry-point.sh

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/bin/bash
2+
set -e
3+
4+
if [ ! -z "$HOST_UID" ] && [ ! -z "$HOST_GID" ]; then
5+
# Create "batocera" user and group with the same UID and GID as the host user
6+
groupadd -o -g "$HOST_GID" batocera 2>/dev/null
7+
useradd -o -u "$HOST_UID" -g "$HOST_GID" -d /home/batocera -c '' -M -s /bin/bash batocera 2>/dev/null
8+
9+
# This should already be made, but create it just in case
10+
mkdir -p /home/batocera
11+
12+
# Set the ownership of the home directory to the "batocera" user and group
13+
# NOTE: this is not done recursively because the build process mounts the
14+
# ccache directory in /home/batocera/.ccache and we don't want to change
15+
# the ownership of all of those files (since they should already have the
16+
# correct ownership)
17+
chown batocera:batocera /home/batocera
18+
19+
export HOME=/home/batocera
20+
21+
# Set $@ to run the docker command as the "batocera" user and group
22+
set -- gosu "$HOST_UID":"$HOST_GID" "$@"
23+
fi
24+
25+
exec "$@"

package/batocera/boot/batocera-syslinux-efi/batocera-syslinux-efi.mk

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
BATOCERA_SYSLINUX_EFI_VERSION = 6.04.pre2.r11.gbf6db5b4-2
88
BATOCERA_SYSLINUX_EFI_SOURCE =
99
BATOCERA_SYSLINUX_EFI_SITE = binaries
10+
BATOCERA_SYSLINUX_EFI_DEPENDENCIES = host-dosfstools host-mtools
1011

1112
define BATOCERA_SYSLINUX_EFI_EXTRACT_CMDS
1213
cp -R $(BR2_EXTERNAL_BATOCERA_PATH)/package/batocera/boot/batocera-syslinux-efi/binaries/* $(@D)

0 commit comments

Comments
 (0)