From d6d33e5f3e3b3de19b2c36c0e575bd3b94058a65 Mon Sep 17 00:00:00 2001 From: Dave Vigil Date: Mon, 14 Jul 2025 23:54:16 -0500 Subject: [PATCH] Added dockerfilE/container --- .github/workflows/docker-build.yml | 80 ++++++++++++++++++ .github/workflows/lint_and_compile.yml | 2 +- DOCKER_README.md | 99 ++++++++++++++++++++++ Dockerfile | 109 +++++++++++++++++++++++++ build.sh | 71 ++++++++++++++++ 5 files changed, 360 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/docker-build.yml create mode 100644 DOCKER_README.md create mode 100644 Dockerfile create mode 100755 build.sh diff --git a/.github/workflows/docker-build.yml b/.github/workflows/docker-build.yml new file mode 100644 index 0000000..e45ed64 --- /dev/null +++ b/.github/workflows/docker-build.yml @@ -0,0 +1,80 @@ +name: Build QMK Firmware with Docker +on: [push, pull_request] + +jobs: + build: + runs-on: ubuntu-latest + strategy: + matrix: + keyboard: [draculad, iris, scottogame, sweep, swoop] + include: + - keyboard: draculad + qmk_path: draculad + - keyboard: iris + qmk_path: keebio/iris/rev8 + - keyboard: scottogame + qmk_path: handwired/scottokeebs/scottogame + - keyboard: sweep + qmk_path: ferris/sweep + - keyboard: swoop + qmk_path: bluebell/swoop + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + with: + submodules: recursive + + - name: Build Docker image + run: docker build -t qmk-builder . + + - name: Build firmware + run: | + docker run --rm \ + -v "${{ github.workspace }}:/workspace" \ + -w /workspace \ + -e USER=dgvigil \ + qmk-builder \ + bash -c " + cd /qmk_firmware + qmk compile -kb ${{ matrix.qmk_path }} -km dgvigil + " + + - name: Upload firmware artifacts + uses: actions/upload-artifact@v4 + with: + name: firmware-${{ matrix.keyboard }} + path: qmk_firmware/*.hex + retention-days: 30 + + - name: Upload UF2 files + uses: actions/upload-artifact@v4 + with: + name: firmware-${{ matrix.keyboard }}-uf2 + path: qmk_firmware/*.uf2 + retention-days: 30 + + release: + needs: build + runs-on: ubuntu-latest + if: github.event_name == 'push' && github.ref == 'refs/heads/main' + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Download all artifacts + uses: actions/download-artifact@v4 + with: + path: artifacts + + - name: Create release + uses: marvinpinto/action-automatic-releases@latest + with: + repo_token: "${{ secrets.GITHUB_TOKEN }}" + automatic_release_tag: "${{ github.sha }}" + title: "QMK Firmware Build - ${{ github.sha }}" + prerelease: false + files: | + artifacts/**/*.hex + artifacts/**/*.uf2 \ No newline at end of file diff --git a/.github/workflows/lint_and_compile.yml b/.github/workflows/lint_and_compile.yml index 3df5ff8..a9b24ae 100644 --- a/.github/workflows/lint_and_compile.yml +++ b/.github/workflows/lint_and_compile.yml @@ -4,7 +4,7 @@ jobs: lint-and-compile: runs-on: local container: - image: qmkfm/qmk_cli + image: registry.home.dgvigil.dev/qmk-builder:latest steps: - name: Check out repository code uses: actions/checkout@v4 diff --git a/DOCKER_README.md b/DOCKER_README.md new file mode 100644 index 0000000..d2078b8 --- /dev/null +++ b/DOCKER_README.md @@ -0,0 +1,99 @@ +# QMK Firmware Docker Build Environment + +This repository includes a custom Docker setup for building QMK firmware in CI/CD environments. + +## Files + +- `Dockerfile` - Custom Docker image for QMK firmware builds +- `.dockerignore` - Excludes unnecessary files from Docker build context +- `build.sh` - Convenience script for building firmware locally +- `.github/workflows/docker-build.yml` - GitHub Actions workflow using the custom Docker image + +## Features + +- Based on Ubuntu 22.04 for stability +- Includes ARM and AVR toolchains +- Pre-installed QMK CLI and dependencies +- Automatic symlink setup for your keymaps +- Optimized for your specific keyboard configurations + +## Local Usage + +### Building the Docker Image + +```bash +docker build -t qmk-builder . +``` + +### Building Firmware + +#### Using the build script: +```bash +# Build all keyboards +./build.sh + +# Build specific keyboard +./build.sh iris + +# Build with custom user +./build.sh iris myuser +``` + +#### Using Docker directly: +```bash +# Build all keyboards +docker run --rm \ + -v "$(pwd):/workspace" \ + -w /workspace \ + -e USER=dgvigil \ + qmk-builder \ + bash -c "cd /qmk_firmware && qmk compile -kb keebio/iris/rev8 -km dgvigil" +``` + +## CI/CD Usage + +The `.github/workflows/docker-build.yml` workflow demonstrates how to use this Docker setup in GitHub Actions: + +1. Builds the Docker image +2. Builds each keyboard in parallel +3. Uploads firmware artifacts +4. Creates releases on main branch pushes + +## Supported Keyboards + +- `draculad` → `draculad` +- `iris` → `keebio/iris/rev8` +- `scottogame` → `handwired/scottokeebs/scottogame` +- `sweep` → `ferris/sweep` +- `swoop` → `bluebell/swoop` + +## Environment Variables + +- `USER` - The QMK user name (defaults to `dgvigil`) +- `QMK_HOME` - Path to QMK firmware (set to `/qmk_firmware`) + +## Differences from qmkfm/qmk_cli + +This custom Dockerfile provides: + +1. **Faster builds** - Pre-installed toolchains and dependencies +2. **Better integration** - Automatic symlink setup for your keymaps +3. **Consistent environment** - Same setup across local and CI builds +4. **Optimized for your workflow** - Tailored to your specific keyboard configurations + +## Troubleshooting + +### Build fails with toolchain errors +Make sure the Docker image is built with the latest QMK firmware: +```bash +docker build --no-cache -t qmk-builder . +``` + +### Symlinks not working +The entrypoint script automatically sets up symlinks, but you can verify they exist: +```bash +docker run --rm -v "$(pwd):/workspace" qmk-builder ls -la /qmk_firmware/keyboards/keebio/iris/keymaps/ +``` + +### Missing firmware files +Check that the build completed successfully and look for `.hex` and `.uf2` files in the QMK firmware directory. \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..d68f057 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,109 @@ +# QMK Firmware Build Environment +# Based on Ubuntu 22.04 for stability and compatibility + +FROM ubuntu:22.04 + +# Set environment variables +ENV DEBIAN_FRONTEND=noninteractive +ENV QMK_HOME=/qmk_firmware +ENV PATH="/root/.local/bin:$PATH" + +# Install system dependencies +RUN apt-get update && apt-get install -y \ + build-essential \ + clang-format \ + dfu-programmer \ + dfu-util \ + git \ + libnewlib-arm-none-eabi \ + nodejs \ + python3 \ + python3-pip \ + python3-setuptools \ + python3-wheel \ + wget \ + unzip \ + && rm -rf /var/lib/apt/lists/* + +# Install ARM toolchain +RUN wget -qO- https://developer.arm.com/-/media/Files/downloads/gnu-rm/10.3-2021.10/gcc-arm-none-eabi-10.3-2021.10-x86_64-linux.tar.bz2 | tar xj -C /opt \ + && ln -s /opt/gcc-arm-none-eabi-10.3-2021.10/bin/* /usr/local/bin/ + +# Install AVR toolchain +RUN wget -qO- https://downloads.arduino.cc/arduino-1.8.19-linux64.tar.xz | tar xJ -C /opt \ + && ln -s /opt/arduino-1.8.19/hardware/tools/avr/bin/* /usr/local/bin/ + +# Set up QMK environment +WORKDIR /workspace +RUN git clone --depth 1 https://github.com/qmk/qmk_firmware.git $QMK_HOME + +# Install QMK CLI and Python dependencies +RUN pip3 install --user qmk +RUN pip3 install --user -r $QMK_HOME/requirements.txt + +# Set up QMK +RUN qmk setup --yes + +# Create build directory +RUN mkdir -p /workspace/build + +# Set working directory +WORKDIR /workspace + +# Copy entrypoint script +COPY </dev/null || true +rm -rf $QMK_HOME/keyboards/keebio/iris/keymaps/\$USER 2>/dev/null || true +rm -rf $QMK_HOME/keyboards/handwired/scottokeebs/scottogame/keymaps/\$USER 2>/dev/null || true +rm -rf $QMK_HOME/keyboards/bluebell/swoop/keymaps/\$USER 2>/dev/null || true +rm -rf $QMK_HOME/keyboards/ferris/keymaps/\$USER 2>/dev/null || true +rm -rf $QMK_HOME/users/\$USER 2>/dev/null || true + +# Create symlinks for keymaps +if [ -d "draculad" ]; then + ln -s /workspace/draculad/ $QMK_HOME/keyboards/draculad/keymaps/\$USER +fi + +if [ -d "iris" ]; then + ln -s /workspace/iris/ $QMK_HOME/keyboards/keebio/iris/keymaps/\$USER +fi + +if [ -d "sweep" ]; then + ln -s /workspace/sweep/ $QMK_HOME/keyboards/ferris/keymaps/\$USER +fi + +if [ -d "scottogame" ]; then + ln -s /workspace/scottogame/ $QMK_HOME/keyboards/handwired/scottokeebs/scottogame/keymaps/\$USER +fi + +if [ -d "swoop" ]; then + ln -s /workspace/swoop/ $QMK_HOME/keyboards/bluebell/swoop/keymaps/\$USER +fi + +if [ -d "user" ]; then + ln -s /workspace/user/ $QMK_HOME/users/\$USER +fi + +# Execute the command passed to the container +exec "\$@" +EOF + +RUN chmod +x /usr/local/bin/entrypoint.sh + +# Set entrypoint +ENTRYPOINT ["/usr/local/bin/entrypoint.sh"] + +# Default command +CMD ["bash"] \ No newline at end of file diff --git a/build.sh b/build.sh new file mode 100755 index 0000000..fbddf3a --- /dev/null +++ b/build.sh @@ -0,0 +1,71 @@ +#!/bin/bash +set -e + +# Build script for QMK firmware using Docker +# Usage: ./build.sh [keyboard] [user] + +KEYBOARD=${1:-all} +USER=${2:-dgvigil} + +echo "Building QMK firmware for user: $USER" + +# Build the Docker image if it doesn't exist +if [[ "$(docker images -q qmk-builder 2> /dev/null)" == "" ]]; then + echo "Building Docker image..." + docker build -t qmk-builder . +fi + +# Function to build a specific keyboard +build_keyboard() { + local kb=$1 + local user=$2 + + echo "Building $kb for user $user..." + + # Map keyboard names to QMK paths + case $kb in + "draculad") + qmk_path="draculad" + ;; + "iris") + qmk_path="keebio/iris/rev8" + ;; + "scottogame") + qmk_path="handwired/scottokeebs/scottogame" + ;; + "sweep") + qmk_path="ferris/sweep" + ;; + "swoop") + qmk_path="bluebell/swoop" + ;; + *) + echo "Unknown keyboard: $kb" + exit 1 + ;; + esac + + # Run the build in Docker + docker run --rm \ + -v "$(pwd):/workspace" \ + -w /workspace \ + -e USER=$user \ + qmk-builder \ + bash -c " + cd $QMK_HOME + qmk compile -kb $qmk_path -km $user + " +} + +# Build all keyboards or specific one +if [ "$KEYBOARD" = "all" ]; then + echo "Building all keyboards..." + for kb in draculad iris scottogame sweep swoop; do + build_keyboard $kb $USER + done +else + build_keyboard $KEYBOARD $USER +fi + +echo "Build complete!" +echo "Firmware files should be in the qmk_firmware directory" \ No newline at end of file