Skip to content

Commit f19a74a

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 f19a74a

File tree

11 files changed

+533
-6
lines changed

11 files changed

+533
-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: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
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+
mpy_platform:
20+
description: MicroPython platform 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@v4
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.mpy_platform }}-${{ steps.sanitize_platform.outputs.cleaned_platform }}
71+
flavor: latest=false
72+
73+
- name: Docker build and push
74+
uses: docker/build-push-action@v6
75+
id: docker_platform
76+
with:
77+
context: .
78+
push: ${{ inputs.push }}
79+
tags: ${{ steps.meta.outputs.tags }}
80+
labels: ${{ steps.meta.outputs.labels }}
81+
platforms: ${{ inputs.platform }}
82+
build-args: |
83+
BUILD_PLATFORM=${{ inputs.mpy_platform }}
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
name: Build container manifest
2+
on:
3+
workflow_call:
4+
inputs:
5+
mpy_platform:
6+
description: MicroPython platform to target
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+
mpy_platform: ${{ inputs.mpy_platform }}
25+
platform: linux/amd64
26+
runs-on: ubuntu-24.04
27+
push: true
28+
secrets: inherit
29+
30+
docker-arm64:
31+
if: inputs.mpy_platform != 'litex'
32+
uses: ./.github/workflows/docker_build.yml
33+
with:
34+
mpy_platform: ${{ inputs.mpy_platform }}
35+
platform: linux/arm64
36+
runs-on: ubuntu-24.04-arm
37+
push: true
38+
secrets: inherit
39+
40+
docker-manifest:
41+
needs:
42+
- docker-amd64
43+
- docker-arm64
44+
runs-on: ubuntu-24.04
45+
steps:
46+
- uses: actions/checkout@v4
47+
48+
- name: Docker Login GHCR
49+
uses: docker/login-action@v3
50+
with:
51+
registry: ${{ env.REGISTRY }}
52+
username: ${{ github.actor }}
53+
password: ${{ secrets.GITHUB_TOKEN }}
54+
55+
- name: Docker meta
56+
id: meta_docker
57+
uses: docker/metadata-action@v5
58+
with:
59+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
60+
tags: |
61+
main-${{ inputs.mpy_platform }}
62+
flavor: latest=false
63+
64+
- name: Create Docker manifest
65+
id: manifest_docker
66+
uses: int128/docker-manifest-create-action@v2
67+
with:
68+
tags: |
69+
${{ steps.meta_docker.outputs.tags }}
70+
push: true
71+
sources: |
72+
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}@${{ needs.docker-amd64.outputs.digest }}
73+
${{ inputs.mpy_platform != 'litex' && env.REGISTRY }}/${{ inputs.mpy_platform != 'litex' && env.IMAGE_NAME }}@${{ inputs.mpy_platform != 'litex' && needs.docker-arm64.outputs.digest }}

.github/workflows/on_pr.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
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+
docker-amd64:
13+
strategy:
14+
fail-fast: false
15+
matrix:
16+
mpy_platform:
17+
- esp32
18+
- nrf
19+
uses: ./.github/workflows/docker_build.yml
20+
with:
21+
mpy_platform: ${{ matrix.mpy_platform }}
22+
platform: linux/amd64
23+
runs-on: ubuntu-24.04
24+
push: false
25+
secrets: inherit

.github/workflows/on_push.yml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
name: Build Release
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 5 * * 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+
docker-platforms:
20+
strategy:
21+
fail-fast: false
22+
matrix:
23+
mpy_platform:
24+
- esp32
25+
- nrf
26+
uses: ./.github/workflows/docker_manifest.yml
27+
with:
28+
mpy_platform: ${{ matrix.mpy_platform }}
29+
secrets: inherit

Containerfile

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
FROM python:3.13-bookworm AS base
2+
3+
ENV PIP_ROOT_USER_ACTION=ignore
4+
5+
# Apt dependencies
6+
RUN apt-get update && apt-get install -y \
7+
jq jdupes build-essential \
8+
libgpiod-dev libyaml-cpp-dev libbluetooth-dev libusb-1.0-0-dev libi2c-dev libuv1-dev \
9+
libx11-dev libinput-dev libxkbcommon-x11-dev \
10+
openssl libssl-dev libulfius-dev liborcania-dev \
11+
git git-lfs gettext cmake mtools floppyd dosfstools ninja-build \
12+
parted zip \
13+
&& rm -rf /var/lib/apt/lists/*
14+
15+
FROM base AS repo
16+
ARG BUILD_REPO="https://github.com/fobe-projects/micropython.git"
17+
ARG BUILD_REF="main"
18+
19+
WORKDIR /workspace
20+
21+
RUN git config --global --add safe.directory /workspace \
22+
&& git config --global protocol.file.allow always \
23+
&& git clone --depth 1 --filter=tree:0 "${BUILD_REPO}" /workspace \
24+
&& cd /workspace && git checkout "${BUILD_REF}" \
25+
&& git repack -d
26+
27+
RUN pip3 install --upgrade pip setuptools wheel build huffman poetry
28+
29+
FROM repo AS port
30+
31+
ARG ARM_TOOLCHAIN_EABI_VERSION="14.2.rel1"
32+
ARG ARM_TOOLCHAIN_ELF_VERSION="13.3.rel1"
33+
ARG BUILD_PLATFORM
34+
35+
RUN if [ "${BUILD_PLATFORM}" != "esp32" ] && [ "${BUILD_PLATFORM}" != "zephyr" ] && [ "${BUILD_PLATFORM}" != "none" ]; then \
36+
ARCH=$(dpkg --print-architecture) && \
37+
if [ "$ARCH" = "arm64" ]; then \
38+
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"; \
39+
elif [ "$ARCH" = "amd64" ]; then \
40+
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"; \
41+
else \
42+
echo "Unsupported architecture: $ARCH"; \
43+
exit 1; \
44+
fi && \
45+
mkdir -p /usr/local/arm-none-eabi && \
46+
curl -fsSL "$TOOLCHAIN_URL" | tar -xJ -C /usr/local/arm-none-eabi --strip-components=1 && \
47+
for f in /usr/local/arm-none-eabi/bin/arm-none-eabi-*; do \
48+
ln -sf "$f" /usr/local/bin/$(basename "$f"); \
49+
done \
50+
fi
51+
52+
# Nordic
53+
RUN if [ "${BUILD_PLATFORM}" = "nrf" ]; then \
54+
ARCH=$(dpkg --print-architecture) && \
55+
if [ "$ARCH" = "arm64" ]; then \
56+
TOOLCHAIN_URL="https://files.nordicsemi.com/artifactory/swtools/external/nrfutil/executables/aarch64-unknown-linux-gnu/nrfutil"; \
57+
elif [ "$ARCH" = "amd64" ]; then \
58+
TOOLCHAIN_URL="https://files.nordicsemi.com/artifactory/swtools/external/nrfutil/executables/x86_64-unknown-linux-gnu/nrfutil"; \
59+
else \
60+
echo "Unsupported architecture: $ARCH"; \
61+
exit 1; \
62+
fi && curl -fsSL "$TOOLCHAIN_URL" -o nrfutil;\
63+
chmod +x nrfutil; \
64+
./nrfutil install nrf5sdk-tools; \
65+
mv nrfutil /usr/local/bin; \
66+
nrfutil -V; \
67+
make -C ports/nrf submodules; \
68+
cd /workspace/ports/nrf && ./drivers/bluetooth/download_ble_stack.sh; \
69+
cd /workspace; \
70+
fi
71+
72+
# Espressif IDF
73+
ENV IDF_PATH=/opt/esp-idf
74+
ENV IDF_TOOLS_PATH=/opt/esp-idf-tools
75+
ENV ESP_ROM_ELF_DIR=/opt/esp-idf-tools
76+
RUN if [ "${BUILD_PLATFORM}" = "esp32" ]; then \
77+
git clone -b v5.4.2 --recursive https://github.com/espressif/esp-idf.git ${IDF_PATH}; \
78+
$IDF_PATH/install.sh; \
79+
bash -c "source ${IDF_PATH}/export.sh && pip3 install --upgrade minify-html jsmin sh requests-cache && make -C ports/esp32 submodules"; \
80+
rm -rf $IDF_TOOLS_PATH/dist; \
81+
fi
82+
83+
COPY --chmod=0755 entrypoint.sh /entrypoint.sh
84+
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)