1+ FROM python:3.13-slim-bookworm AS base
2+
3+ ENV PIP_ROOT_USER_ACTION=ignore
4+
5+ WORKDIR /workspace
6+
7+ # Apt dependencies
8+ RUN --mount=type=cache,target=/var/cache/apt \
9+ --mount=type=cache,target=/var/lib/apt \
10+ apt-get update && apt-get install -y \
11+ jq jdupes build-essential \
12+ libgpiod-dev libyaml-cpp-dev libbluetooth-dev libusb-1.0-0-dev libi2c-dev libuv1-dev \
13+ libx11-dev libinput-dev libxkbcommon-x11-dev \
14+ openssl libssl-dev libulfius-dev liborcania-dev \
15+ git git-lfs gettext cmake mtools floppyd dosfstools ninja-build \
16+ parted zip wget curl ca-certificates \
17+ && rm -rf /var/lib/apt/lists/*
18+
19+ RUN --mount=type=cache,target=/root/.cache/pip \
20+ pip3 install --upgrade pip setuptools wheel build huffman poetry
21+
22+ FROM base AS repo
23+
24+ ARG WORKSPACE_REPO="https://github.com/fobe-projects/micropython.git"
25+ ARG WORKSPACE_REPO_UPSTREAM="https://github.com/micropython/micropython.git"
26+ ARG WORKSPACE_REPO_REMOTE="origin"
27+ ARG WORKSPACE_REPO_REF="main"
28+
29+ RUN git config --global --add safe.directory /workspace \
30+ && git clone "${WORKSPACE_REPO}" /workspace \
31+ && git remote add upstream "${WORKSPACE_REPO_UPSTREAM}" \
32+ && git fetch upstream --tags --prune --force \
33+ && git fetch origin --tags --prune --force \
34+ && git reset --hard "${WORKSPACE_REPO_REMOTE}/${WORKSPACE_REPO_REF}" \
35+ && git repack -d
36+
37+ ARG WORKSPACE_BUILD_REMOTE="origin"
38+ ARG WORKSPACE_BUILD_REF="main"
39+ RUN echo "Hard reset repository to: ${WORKSPACE_REPO_REMOTE}/${WORKSPACE_REPO_REF}" \
40+ && git fetch upstream --tags --prune --force \
41+ && git fetch origin --tags --prune --force \
42+ && git fetch "${WORKSPACE_BUILD_REMOTE}" "${WORKSPACE_BUILD_REF}" \
43+ && git reset --hard FETCH_HEAD \
44+ && git repack -d \
45+ && echo "Repository firmware version: $(git describe --tags --dirty --always --match 'v[1-9].*')"
46+
47+ FROM repo AS nrf
48+
49+ ENV MPY_PORT=nrf
50+
51+ ARG ARM_TOOLCHAIN_EABI_VERSION="14.2.rel1"
52+ RUN --mount=type=cache,target=/tmp/arm-toolchain-cache,id=arm-toolchain-eabi-${ARM_TOOLCHAIN_EABI_VERSION} \
53+ ARCH=$(dpkg --print-architecture) && \
54+ if [ "$ARCH" = "arm64" ]; then \
55+ TOOLCHAIN_URL="https://developer.arm.com/-/media/Files/downloads/gnu/$ARM_TOOLCHAIN_EABI_VERSION/binrel/arm-gnu-toolchain-$ARM_TOOLCHAIN_EABI_VERSION-aarch64-arm-none-eabi.tar.xz" ; \
56+ TOOLCHAIN_ARCHIVE="/tmp/arm-toolchain-cache/arm-gnu-toolchain-$ARM_TOOLCHAIN_EABI_VERSION-aarch64-arm-none-eabi.tar.xz" ; \
57+ elif [ "$ARCH" = "amd64" ]; then \
58+ TOOLCHAIN_URL="https://developer.arm.com/-/media/Files/downloads/gnu/$ARM_TOOLCHAIN_EABI_VERSION/binrel/arm-gnu-toolchain-$ARM_TOOLCHAIN_EABI_VERSION-x86_64-arm-none-eabi.tar.xz" ; \
59+ TOOLCHAIN_ARCHIVE="/tmp/arm-toolchain-cache/arm-gnu-toolchain-$ARM_TOOLCHAIN_EABI_VERSION-x86_64-arm-none-eabi.tar.xz" ; \
60+ else \
61+ echo "Unsupported architecture: $ARCH" ; \
62+ exit 1; \
63+ fi && \
64+ mkdir -p /usr/local/arm-none-eabi && \
65+ if [ ! -f "$TOOLCHAIN_ARCHIVE" ]; then \
66+ curl -fsSL "$TOOLCHAIN_URL" -o "$TOOLCHAIN_ARCHIVE" ; \
67+ fi && \
68+ tar -xJf "$TOOLCHAIN_ARCHIVE" -C /usr/local/arm-none-eabi --strip-components=1 && \
69+ for f in /usr/local/arm-none-eabi/bin/arm-none-eabi-*; do \
70+ ln -sf "$f" /usr/local/bin/$(basename "$f" ); \
71+ done
72+
73+ RUN --mount=type=cache,target=/tmp/nrfutil-cache,id=nrfutil-tools \
74+ ARCH=$(dpkg --print-architecture) && \
75+ if [ "$ARCH" = "arm64" ]; then \
76+ TOOLCHAIN_URL="https://files.nordicsemi.com/artifactory/swtools/external/nrfutil/executables/aarch64-unknown-linux-gnu/nrfutil" ; \
77+ TOOLCHAIN_ARCHIVE="/tmp/nrfutil-cache/nrfutil-arm64" ; \
78+ elif [ "$ARCH" = "amd64" ]; then \
79+ TOOLCHAIN_URL="https://files.nordicsemi.com/artifactory/swtools/external/nrfutil/executables/x86_64-unknown-linux-gnu/nrfutil" ; \
80+ TOOLCHAIN_ARCHIVE="/tmp/nrfutil-cache/nrfutil-amd64" ; \
81+ else \
82+ echo "Unsupported architecture: $ARCH" ; \
83+ exit 1; \
84+ fi && \
85+ mkdir -p /usr/local/nrfutil && \
86+ if [ ! -f "$TOOLCHAIN_ARCHIVE" ]; then \
87+ curl -fsSL "$TOOLCHAIN_URL" -o "$TOOLCHAIN_ARCHIVE" ; \
88+ fi && \
89+ cp "$TOOLCHAIN_ARCHIVE" /usr/local/nrfutil/nrfutil && \
90+ chmod +x /usr/local/nrfutil/nrfutil && \
91+ /usr/local/nrfutil/nrfutil install nrf5sdk-tools; \
92+ ln -sf /usr/local/nrfutil/nrfutil /usr/local/bin/nrfutil
93+
94+ RUN make -C ports/"${MPY_PORT}" submodules && git repack -d
95+
96+ RUN ports/nrf/drivers/bluetooth/download_ble_stack.sh
97+
98+ COPY --chmod=0755 entrypoint.sh /entrypoint.sh
99+ ENTRYPOINT [ "/entrypoint.sh" ]
100+
101+ FROM repo AS esp32
102+
103+ ENV MPY_PORT=esp32
104+ ENV IDF_PATH=/opt/esp-idf
105+ ENV IDF_TOOLS_PATH=/opt/esp-idf-tools
106+ ENV ESP_ROM_ELF_DIR=/opt/esp-idf-tools
107+
108+ ARG IDF_VERSION=v5.4.2
109+ RUN git clone -b "${IDF_VERSION}" --recursive --depth 1 --shallow-submodules https://github.com/espressif/esp-idf.git "${IDF_PATH}"
110+
111+ RUN --mount=type=cache,target=/root/.cache/pip \
112+ --mount=type=cache,target=/opt/esp-idf-tools/dist \
113+ "${IDF_PATH}" /install.sh "esp32,esp32c2,esp32c3,esp32c6,esp32s2,esp32s3" > /dev/null 2>&1 \
114+ && bash -c "source ${IDF_PATH}/export.sh && pip3 install --upgrade minify-html jsmin sh requests-cache"
115+
116+ RUN bash -c "source ${IDF_PATH}/export.sh && make -C ports/esp32 submodules && git repack -d"
117+
118+ COPY --chmod=0755 entrypoint.sh /entrypoint.sh
119+ ENTRYPOINT [ "/entrypoint.sh" ]
0 commit comments