Skip to content

Commit 280f19e

Browse files
committed
chore: initial project setup with GitHub Actions and Docker support
- Added dependabot configuration for GitHub Actions and Docker. - Created workflows for building Docker images and manifests. - Implemented entrypoint script for building MicroPython ports. - Updated README with usage instructions and examples. - Added license information and ensured compliance with MIT License. Signed-off-by: Chiho Sin <[email protected]>
1 parent ccb4640 commit 280f19e

File tree

11 files changed

+647
-6
lines changed

11 files changed

+647
-6
lines changed

.github/dependabot.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
version: 2
2+
updates:
3+
- package-ecosystem: github-actions
4+
directory: /
5+
schedule:
6+
interval: daily
7+
- package-ecosystem: docker
8+
directory: /
9+
schedule:
10+
interval: daily

.github/workflows/docker_build.yml

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
name: Build container
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
platform:
7+
description: Docker platform to target
8+
required: true
9+
type: string
10+
runs-on:
11+
description: Runner to use
12+
required: true
13+
type: string
14+
push:
15+
description: Push images to registry
16+
required: false
17+
type: boolean
18+
default: false
19+
port:
20+
description: MicroPython port to target
21+
required: true
22+
type: string
23+
outputs:
24+
digest:
25+
description: Digest of built image
26+
value: ${{ jobs.docker-build.outputs.digest }}
27+
28+
env:
29+
REGISTRY: ghcr.io
30+
IMAGE_NAME: ${{ github.repository }}
31+
32+
permissions:
33+
contents: read
34+
packages: write
35+
id-token: write
36+
attestations: write
37+
38+
jobs:
39+
docker-build:
40+
name: Build ${{ inputs.platform }}
41+
outputs:
42+
digest: ${{ steps.docker_platform.outputs.digest }}
43+
runs-on: ${{ inputs.runs-on }}
44+
steps:
45+
- uses: actions/checkout@v5
46+
47+
- uses: docker/setup-qemu-action@v3
48+
49+
- uses: docker/setup-buildx-action@v3
50+
51+
- name: Docker login
52+
if: ${{ inputs.push }}
53+
uses: docker/login-action@v3
54+
with:
55+
registry: ${{ env.REGISTRY }}
56+
username: ${{ github.actor }}
57+
password: ${{ secrets.GITHUB_TOKEN }}
58+
59+
- name: Sanitize platform string
60+
id: sanitize_platform
61+
# Replace slashes with underscores
62+
run: echo "cleaned_platform=${{ inputs.platform }}" | sed 's/\//_/g' >> $GITHUB_OUTPUT
63+
64+
- name: Docker tag
65+
id: meta
66+
uses: docker/metadata-action@v5
67+
with:
68+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
69+
tags: |
70+
GHA-main-${{ inputs.port }}-${{ steps.sanitize_platform.outputs.cleaned_platform }}
71+
flavor: latest=false
72+
73+
- name: Set up Docker Buildx
74+
uses: docker/setup-buildx-action@v3
75+
76+
- name: Docker build and push
77+
uses: docker/build-push-action@v6
78+
id: docker_platform
79+
with:
80+
context: .
81+
cache-from: type=registry,ref=${{ steps.meta.outputs.tags }}-buildcache
82+
cache-to: type=registry,ref=${{ steps.meta.outputs.tags }}-buildcache,mode=max
83+
push: ${{ inputs.push }}
84+
tags: ${{ steps.meta.outputs.tags }}
85+
labels: ${{ steps.meta.outputs.labels }}
86+
platforms: ${{ inputs.platform }}
87+
target: ${{ inputs.port }}
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
name: Build container manifest
2+
on:
3+
workflow_call:
4+
inputs:
5+
port:
6+
description: MicroPython port to build
7+
required: true
8+
type: string
9+
10+
env:
11+
REGISTRY: ghcr.io
12+
IMAGE_NAME: ${{ github.repository }}
13+
14+
permissions:
15+
contents: read
16+
packages: write
17+
id-token: write
18+
attestations: write
19+
20+
jobs:
21+
docker-amd64:
22+
uses: ./.github/workflows/docker_build.yml
23+
with:
24+
port: ${{ inputs.port }}
25+
platform: linux/amd64
26+
runs-on: ubuntu-24.04
27+
push: true
28+
secrets: inherit
29+
30+
docker-arm64:
31+
uses: ./.github/workflows/docker_build.yml
32+
with:
33+
port: ${{ inputs.port }}
34+
platform: linux/arm64
35+
runs-on: ubuntu-24.04-arm
36+
push: true
37+
secrets: inherit
38+
39+
docker-manifest:
40+
needs:
41+
- docker-amd64
42+
- docker-arm64
43+
runs-on: ubuntu-24.04
44+
steps:
45+
- uses: actions/checkout@v5
46+
47+
- name: Docker Login GHCR
48+
uses: docker/login-action@v3
49+
with:
50+
registry: ${{ env.REGISTRY }}
51+
username: ${{ github.actor }}
52+
password: ${{ secrets.GITHUB_TOKEN }}
53+
54+
- name: Docker meta
55+
id: meta_docker
56+
uses: docker/metadata-action@v5
57+
with:
58+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
59+
tags: |
60+
main-${{ inputs.port }}
61+
flavor: latest=false
62+
63+
- name: Create Docker manifest
64+
id: manifest_docker
65+
uses: int128/docker-manifest-create-action@v2
66+
with:
67+
tags: |
68+
${{ steps.meta_docker.outputs.tags }}
69+
push: true
70+
sources: |
71+
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}@${{ needs.docker-amd64.outputs.digest }}
72+
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}@${{ needs.docker-arm64.outputs.digest }}

.github/workflows/on_pr.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
name: Build PR
2+
on:
3+
pull_request:
4+
5+
permissions:
6+
contents: read
7+
packages: write
8+
id-token: write
9+
attestations: write
10+
11+
jobs:
12+
build:
13+
name: Build Test
14+
strategy:
15+
fail-fast: false
16+
matrix:
17+
port:
18+
- esp32
19+
- nrf
20+
uses: ./.github/workflows/docker_build.yml
21+
with:
22+
port: ${{ matrix.port }}
23+
platform: linux/amd64
24+
runs-on: ubuntu-24.04
25+
push: false
26+
secrets: inherit

.github/workflows/on_push.yml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
name: Build CI
2+
on:
3+
push:
4+
# build and push anytime commits are pushed/merged
5+
branches:
6+
- main
7+
schedule:
8+
# build and push weekly
9+
- cron: 0 0 * * 5
10+
workflow_dispatch: # allow manual triggering
11+
12+
permissions:
13+
contents: read
14+
packages: write
15+
id-token: write
16+
attestations: write
17+
18+
jobs:
19+
build:
20+
name: Build Docker
21+
strategy:
22+
fail-fast: false
23+
matrix:
24+
port:
25+
- esp32
26+
- nrf
27+
uses: ./.github/workflows/docker_manifest.yml
28+
with:
29+
port: ${{ matrix.port }}
30+
secrets: inherit
31+
32+
clean:
33+
name: Cleanup GitHub Packages
34+
needs: build
35+
runs-on: ubuntu-latest
36+
steps:
37+
- name: Cleanup GitHub packages container
38+
uses: dataaxiom/ghcr-cleanup-action@v1
39+
with:
40+
delete-ghost-images: true
41+
delete-untagged: true
42+
token: ${{ secrets.GITHUB_TOKEN }}

Containerfile

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
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" ]

Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Containerfile

LICENSE

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
MIT License
1+
The MIT License (MIT)
22

33
Copyright (c) 2025 FoBE Studio
44

@@ -9,13 +9,13 @@ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
99
copies of the Software, and to permit persons to whom the Software is
1010
furnished to do so, subject to the following conditions:
1111

12-
The above copyright notice and this permission notice shall be included in all
13-
copies or substantial portions of the Software.
12+
The above copyright notice and this permission notice shall be included in
13+
all copies or substantial portions of the Software.
1414

1515
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1616
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1717
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
1818
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
1919
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21-
SOFTWARE.
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+
THE SOFTWARE.

0 commit comments

Comments
 (0)