diff --git a/.github/workflows/docker-build.yml b/.github/workflows/docker-build.yml new file mode 100644 index 0000000..c544f2b --- /dev/null +++ b/.github/workflows/docker-build.yml @@ -0,0 +1,107 @@ +--- +name: Docker Image + +on: + push: + tags: [ '*.*.*' ] + +env: + REGISTRY_IMAGE: ghcr.io/rgrizzell/circuitpython + +jobs: + build: + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + platform: + - linux/amd64 + - linux/arm64 + steps: + - name: Prepare + run: | + platform=${{ matrix.platform }} + echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV + + - name: Checkout + uses: actions/checkout@v4 + + - name: Docker meta + id: meta + uses: docker/metadata-action@v5 + with: + images: ${{ env.REGISTRY_IMAGE }} + + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Login to GitHub Container Registry + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.repository_owner }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Build and push by digest + id: build + uses: docker/build-push-action@v5 + with: + context: . + platforms: ${{ matrix.platform }} + labels: ${{ steps.meta.outputs.labels }} + outputs: type=image,name=${{ env.REGISTRY_IMAGE }},push-by-digest=true,name-canonical=true,push=true + + - name: Export digest + run: | + mkdir -p /tmp/digests + digest="${{ steps.build.outputs.digest }}" + touch "/tmp/digests/${digest#sha256:}" + + - name: Upload digest + uses: actions/upload-artifact@v4 + with: + name: digests-${{ env.PLATFORM_PAIR }} + path: /tmp/digests/* + if-no-files-found: error + retention-days: 1 + + merge: + runs-on: ubuntu-latest + needs: + - build + steps: + - name: Download digests + uses: actions/download-artifact@v4 + with: + path: /tmp/digests + pattern: digests-* + merge-multiple: true + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Docker meta + id: meta + uses: docker/metadata-action@v5 + with: + images: ${{ env.REGISTRY_IMAGE }} + + - name: Login to GitHub Container Registry + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.repository_owner }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Create manifest list and push + working-directory: /tmp/digests + run: | + docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \ + $(printf '${{ env.REGISTRY_IMAGE }}@sha256:%s ' *) + + - name: Inspect image + run: | + docker buildx imagetools inspect ${{ env.REGISTRY_IMAGE }}:${{ steps.meta.outputs.version }} \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index bdbf00b..003b6cd 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,16 +1,23 @@ -FROM debian:10-slim -ARG VERSION=6.2.0 +FROM debian:12-slim as build +ARG VERSION=9.0.5 -RUN apt update -RUN DEBIAN_FRONTEND=noninteractive apt install -y build-essential pkg-config libffi-dev wget git gettext python3 -RUN git clone https://github.com/adafruit/circuitpython.git +# Install system requirements +RUN apt update \ + && apt install -y build-essential cmake git git-lfs gettext libffi-dev pkg-config python3 python3-pip python3-venv uncrustify +# Clone the CircuitPython project +RUN git clone -b $VERSION https://github.com/adafruit/circuitpython.git +# Setup build dependencies WORKDIR /circuitpython -RUN git checkout $VERSION -RUN git submodule sync --quiet --recursive -RUN git submodule update --init -RUN make -C mpy-cross -RUN cd ports/unix && make axtls && make micropython && make install -RUN apt-get purge --auto-remove -y build-essential pkg-config libffi-dev wget git gettext python3 -RUN rm -rf /circuitpython -WORKDIR / +RUN python3 -m venv .venv +ENV PATH="/circuitpython/.venv/bin:$PATH" +RUN python3 -m pip install --upgrade -r requirements-dev.txt \ + && python tools/ci_fetch_deps.py tests +# Build the binaires +RUN make -C mpy-cross \ + && make -C ports/unix + +# Create final runtime container +FROM debian:12-slim +COPY --from=build /circuitpython/mpy-cross/build/mpy-cross /usr/local/bin/mpy-cross +COPY --from=build /circuitpython/ports/unix/build-standard/micropython /usr/local/bin/micropython CMD ["/usr/local/bin/micropython"] \ No newline at end of file