This guide shows how to:
- Build and publish a multi-architecture Docker image that contains the STM32F4 toolchain.
- Register a GitHub Actions self-hosted runner on a host.
- Run your pipeline with labels that target the image.
📝Notes:
- Host system noted: MacOS 16.10.
- Base image noted: Ubuntu 24.04 inside Docker.
⚠️Cautions:
- Some runner commands come directly from GitHub UI:
<repo_url>/settings/actions/runners→ “New self-hosted runner”. Use the values GitHub generates for your repository, OS, and architecture. - Tokens and URLs below are placeholders.
Step 1: Docker image: build and push
🚨 IMPORTANT — BEFORE YOU START!!!
The Docker image ugurkebir/stm32f4-build:14.3-rel1 is public on Docker Hub. Anyone can pull and use it.
If you will use this image from Docker Hub, skip Step 1 and go directly to Step 2.
You can pull the image with the following command:
docker pull ugurkebir/stm32f4-build:14.3-rel1
⚠️Caution:
- Use the public image if you don't need to build.
If you’re still on Step 1, you’ve chosen to build your own image. Let’s write the Dockerfile...
Dockerfile summary:
- Base:
ubuntu:24.04(noble). - Installs Arm GNU Toolchain 14.3.Rel1.
- Provides
arm-none-eabi-gcc,arm-none-eabi-objcopy,openocd,make. - Default command prints tool versions and drops to
bash.
Dockerfile
# syntax=docker/dockerfile:1.7
# Ubuntu 24.04 (noble) based, ARM GNU Toolchain 14.3.Rel1
FROM ubuntu:24.04
ARG DEBIAN_FRONTEND=noninteractive
ARG USER=builder
ARG UID=1000
ARG GID=1000
# ---- Version Information ----
ARG ARM_GCC_VERSION=14.3.rel1
ARG ARM_GCC_BUILD=arm-14.174
# Arm GNU Toolchain 14.3.Rel1 package name and default URL
ARG ARM_GCC_PKG=arm-gnu-toolchain-14.3.rel1-aarch64-arm-none-eabi.tar.xz
ARG ARM_GCC_URL=https://developer.arm.com/-/media/Files/downloads/gnu/${ARM_GCC_VERSION}/binrel/${ARM_GCC_PKG}
# ---- System packages ----
RUN --mount=type=cache,target=/var/cache/apt \
--mount=type=cache,target=/var/lib/apt \
rm -f /var/lib/apt/lists/lock /var/cache/apt/archives/lock || true && \
apt-get update && apt-get install -y --no-install-recommends \
ca-certificates \
build-essential \
make \
git \
wget \
curl \
xz-utils \
python3 \
python3-pip \
ccache \
openocd \
gdb-multiarch \
clang-format \
cppcheck \
sudo \
&& rm -rf /var/lib/apt/lists/*
# ---- ARM Toolchain installation (14.3.Rel1 / arm-none-eabi 14.3.1 20250623) ----
RUN --mount=type=cache,target=/tmp/dl \
mkdir -p /opt/arm-gnu-toolchain && \
cd /tmp/dl && \
wget -c "${ARM_GCC_URL}" -O "${ARM_GCC_PKG}" && \
tar -xf "${ARM_GCC_PKG}" -C /opt/arm-gnu-toolchain --strip-components=1
# ---- User ----
RUN set -eux; \
if ! getent group "${GID}" >/dev/null; then \
groupadd -g "${GID}" "${USER}"; \
fi; \
useradd -m -u "${UID}" -g "${GID}" -s /bin/bash "${USER}"; \
usermod -aG sudo "${USER}"; \
mkdir -p /home/${USER}/workspace; \
chown -R "${UID}:${GID}" /home/${USER}
# Embed password as a hash
ARG PASS_HASH
RUN echo "${USER}:${PASS_HASH}" | chpasswd -e
# ---- Environment ----
ENV PATH="/opt/arm-gnu-toolchain/bin:${PATH}"
ENV CCACHE_DIR=/home/${USER}/.ccache
ENV CC="ccache arm-none-eabi-gcc"
ENV CXX="ccache arm-none-eabi-g++"
ENV AR=arm-none-eabi-ar
ENV AS=arm-none-eabi-as
ENV OBJCOPY=arm-none-eabi-objcopy
ENV OBJDUMP=arm-none-eabi-objdump
ENV GDB=gdb-multiarch
# Reproducible build vars
ENV CFLAGS="-O2 -ffunction-sections -fdata-sections -fno-common -fno-builtin"
ENV LDFLAGS="-Wl,--gc-sections"
# Metadata
LABEL org.opencontainers.image.title="STM32F4 Makefile Build Image" \
org.opencontainers.image.description="Ubuntu 24.04 + Arm GNU Toolchain ${ARM_GCC_VERSION} (${ARM_GCC_BUILD}) arm-none-eabi-gcc 14.3.1 (20250623)" \
org.opencontainers.image.source="Bitbucket Pipelines" \
toolchain.version="${ARM_GCC_VERSION}" \
toolchain.build="${ARM_GCC_BUILD}" \
toolchain.flavor="arm-none-eabi"
# prompt
RUN printf "PS1='\\[\\e[32m\\]\\u\\[\\e[00m\\]:\\[\\e[33m\\]\\w\\[\\e[00m\\]\\\\n$ '\n" >> /etc/bash.bashrc
WORKDIR /home/${USER}/workspace
USER ${USER}
# Initial version outputs
CMD arm-none-eabi-gcc --version && \
arm-none-eabi-objcopy --version && \
openocd --version && \
make --version && \
bash
The provided build script uses Buildx to produce linux/arm64 and linux/amd64 images and pushes to Docker Hub. Save the script as build.sh and execute it unchanged on the host.
#!/bin/bash
docker buildx create --use
docker build \
--build-arg USER=builder \
--build-arg UID="$(id -u)" \
--build-arg GID=1000 \
--build-arg PASS_HASH="$(openssl passwd -6 '<password>')" \
--platform linux/arm64,linux/amd64 \
-t ugurkebir/stm32f4-build:14.3-rel1 \
--push .
How to run it
Save the Dockerfile in your workspace root.
Execute
build.sh. The script:- Creates a Buildx builder.
- Builds for
linux/arm64andlinux/amd64. - Pushes
ugurkebir/stm32f4-build:14.3-rel1to your registry.
Quick test of the image(Optional)
docker run --rm -it ugurkebir/stm32f4-build:14.3-rel1
# Inside the container you will see tool versions printed, then a bash prompt.
Step 2: GitHub Actions self-hosted runner on macOS ARM64
You use a self-hosted runner on the host to execute jobs. The script below matches your file as-is. The commands for ./config.sh options and the runner download URL come from GitHub’s New self-hosted runner wizard on your repo’s Settings → Actions → Runners page.
#!/bin/bash
# This script sets up a GitHub Actions self-hosted runner on macOS ARM64
mkdir actions-runner && cd actions-runner
# Download the latest runner package
curl -o actions-runner-osx-arm64-2.329.0.tar.gz -L https://github.com/actions/runner/releases/download/v2.329.0/actions-runner-osx-arm64-2.329.0.tar.gz
# Optional: Validate the hash
echo "<validation_key> actions-runner-osx-arm64-2.329.0.tar.gz" | shasum -a 256 -c
# Extract the installer
tar xzf ./actions-runner-osx-arm64-2.329.0.tar.gz
# Create the runner and start the configuration experience
./config.sh --url <github_url> --token <token> \
--name "M4-Runner-ARM64" \
--labels "linux,arm64"
# Install the service
./svc.sh install
# Start the service
./svc.sh start
# Last step, run it!
./run.sh
Important
- The
--labels "linux,arm64"are user-defined labels that your workflows will target. They do not change the host OS. - Replace
<github_url>,<token>, and<validation_key>with the exact values generated by GitHub for your repository and runner. - Execute
config.sh.
Step 3: Using the runner with the Docker image in a workflow
Target your runner labels and then run builds inside the pushed image. Example workflow:
name: stm32f4-ci
on:
push:
branches: [ main ]
pull_request:
jobs:
build:
# Match the labels you configured in ./config.sh
runs-on: [self-hosted, linux, arm64]
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Docker login
run: |
echo "${{ secrets.DOCKERHUB_TOKEN }}" | docker login -u "${{ secrets.DOCKERHUB_USER }}" --password-stdin
- name: Pull toolchain image
run: docker pull ugurkebir/stm32f4-build:14.3-rel1
- name: Build firmware
run: |
docker run --rm \
-v "$PWD":/home/builder/workspace \
-w /home/builder/workspace \
ugurkebir/stm32f4-build:14.3-rel1 \
bash -lc '
arm-none-eabi-gcc --version
make -j$(sysctl -n hw.ncpu || nproc)
'
# Optional: package artifacts
- name: Upload firmware
uses: actions/upload-artifact@v4
with:
name: firmware
path: |
build/**/*.elf
build/**/*.bin
build/**/*.hex
Notes
runs-on: [self-hosted, linux, arm64]must match the labels you set in./config.sh.- The workflow logs in to Docker if your repo is private or you rate-limit. Configure
DOCKERHUB_USERandDOCKERHUB_TOKENas repository secrets. - The container mounts the repository into
/home/builder/workspace. Adjust build commands to your makefile or build system.
Step 4: Local manual run on the host
To mirror CI locally:
git clone <repo>
cd <repo>
docker pull ugurkebir/stm32f4-build:14.3-rel1
docker run --rm -it \
-v "$PWD":/home/builder/workspace \
-w /home/builder/workspace \
ugurkebir/stm32f4-build:14.3-rel1
# run your build commands at the prompt
Step 5: Security and maintenance
- Do not commit tokens. Use GitHub Secrets.
- Rotate the runner registration token when reconfiguring.
- Update the runner binary and image tags on a schedule.
- The password hash build arg (
PASS_HASH) is used to set the user’s password inside the image. Supply a strong value.
Step 6: Troubleshooting
- If you get an error configuring the runner, make sure you use single quotes (") and double dashes (--).
- Runner shows “idle” but jobs do not start: labels mismatch. Align
runs-onwith--labelsfrom./config.sh. - Docker privileges on macOS: ensure the user running the service has access to Docker Desktop and that it is running.
- Cross-arch mismatch: the image is multi-arch. If a specific tool is arch-locked, pin
--platformappropriately in your workflow’sdocker runusing--platformonly when needed.
Step 7: Provenance of runner commands
The runner download URL, checksum line, and ./config.sh ... flags originate from GitHub’s New self-hosted runner wizard under your repository’s Settings → Actions → Runners. You reused those commands unmodified for this setup.